瀏覽代碼

Added tutorial for keyboard input

Jorn Theunissen 6 年之前
父節點
當前提交
dd03c76518

+ 1 - 1
Tutorials/Tutorials/Assets/GameSettings.xkgamesettings

@@ -2,7 +2,7 @@
 Id: 66354f1a-ad5a-4504-b892-293a74e9a496
 SerializedVersion: {Xenko: 3.1.0.1}
 Tags: []
-DefaultScene: 52a557d6-1f2c-4983-a0bb-2c12d562d3bf:Scenes/Basics/Cloning entities
+DefaultScene: ee2eb459-7847-42b5-bd69-fc43a6625fd5:Scenes/Basics/Keyboard input
 GraphicsCompositor: 6fbf9e7f-5a64-4144-9f7e-42ab89526670:GraphicsCompositor
 Defaults:
     - !Xenko.Audio.AudioEngineSettings,Xenko.Audio

+ 132 - 0
Tutorials/Tutorials/Assets/Scenes/Basics/Keyboard input.xkscene

@@ -0,0 +1,132 @@
+!SceneAsset
+Id: ee2eb459-7847-42b5-bd69-fc43a6625fd5
+SerializedVersion: {Xenko: 3.1.0.1}
+Tags: []
+ChildrenIds: []
+Offset: {X: 0.0, Y: 0.0, Z: 0.0}
+Hierarchy:
+    RootParts:
+        - ref!! 07e70be2-580e-445f-b994-0dcb7152ba77
+        - ref!! b017eab6-ede1-448d-9970-2adf407a53dd
+        - ref!! a315df29-99f1-4cc9-8e0e-f48136b37cbb
+        - ref!! 4bdaab19-3cf6-4c79-8d61-30b123f20e21
+        - ref!! 8cb12a7f-4d29-4a76-96f9-891bc5327ea6
+        - ref!! c29e99d3-a22d-40cd-a186-47f86e45368f
+        - ref!! 07347eb4-249b-41b0-a0d1-53648d6fb7a1
+    Parts:
+        -   Entity:
+                Id: 07347eb4-249b-41b0-a0d1-53648d6fb7a1
+                Name: Green Theapot
+                Components:
+                    f8eee6f467c9263f9fdd120f5463f988: !TransformComponent
+                        Id: c6782912-86e4-4b95-a131-37275b5a8b31
+                        Position: {X: -2.05260038, Y: 0.0, Z: 0.0}
+                        Rotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    3633cb40f574236299aec88b18c090d2: !ModelComponent
+                        Id: 2e5d266c-1146-4341-bcab-20d44affddf5
+                        Model: 9a3a7dbc-7b08-478a-aab2-19afe1d6ce1c:Models/Teapot
+                        Materials:
+                            a7caa81c4d9afdde1e7b7968d7c4ea8a~0: ca5e832c-0dc0-42e8-bd85-fcb24bfd34f1:Materials/Green
+        -   Entity:
+                Id: 07e70be2-580e-445f-b994-0dcb7152ba77
+                Name: Camera
+                Components:
+                    d5dd94550dc377d8b1703c74aae2cee5: !TransformComponent
+                        Id: 854327f9-07d4-4bb6-9853-efed97edeaa4
+                        Position: {X: -0.168541268, Y: 1.97455645, Z: -6.0}
+                        Rotation: {X: -7.915897E-09, Y: -0.9848077, Z: -0.173648179, W: 7.343504E-08}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    f1cc2f84c67fbd3cc50a22dd0ef605a5: !CameraComponent
+                        Id: a8e66c37-8278-455b-a7ba-ff270544ed6c
+                        Name: null
+                        Projection: Perspective
+                        Slot: c9cb3666-f711-498c-9878-292e79ed7993
+        -   Entity:
+                Id: 4bdaab19-3cf6-4c79-8d61-30b123f20e21
+                Name: Keyboard input
+                Components:
+                    a754b53539c67302833c65636d012820: !TransformComponent
+                        Id: 0d6903be-037d-43fc-81e2-f9bb7b660e8e
+                        Position: {X: 0.0, Y: 0.0, Z: 0.0}
+                        Rotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    5d52f4fa8ee6759f92213b58db9ca856: !Tutorials.Basics.KeyboardInput,Tutorials
+                        Id: efab93a3-3b5d-4e16-b2a5-2e514ade8056
+                        blueTheapot: ref!! 8cb12a7f-4d29-4a76-96f9-891bc5327ea6
+                        yellowTheapot: ref!! c29e99d3-a22d-40cd-a186-47f86e45368f
+                        greenTheapot: ref!! 07347eb4-249b-41b0-a0d1-53648d6fb7a1
+        -   Entity:
+                Id: 8cb12a7f-4d29-4a76-96f9-891bc5327ea6
+                Name: Blue Theapot
+                Components:
+                    f8eee6f467c9263f9fdd120f5463f988: !TransformComponent
+                        Id: 2e3cc2e8-f4ee-430f-b1b1-007e8656a529
+                        Position: {X: 1.94739974, Y: 0.0, Z: 0.0}
+                        Rotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    3633cb40f574236299aec88b18c090d2: !ModelComponent
+                        Id: dbe89cae-45b0-426a-b641-aa8fc2e437aa
+                        Model: 9a3a7dbc-7b08-478a-aab2-19afe1d6ce1c:Models/Teapot
+                        Materials: {}
+        -   Entity:
+                Id: a315df29-99f1-4cc9-8e0e-f48136b37cbb
+                Name: Skybox light
+                Components:
+                    88b62d474d21080cf1a760192a108619: !TransformComponent
+                        Id: 3bf8baca-76ad-4043-bc1f-5047decf72d7
+                        Position: {X: 100.0, Y: 0.0, Z: 0.0}
+                        Rotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    b6410438b41b6be62428102415f68a4e: !LightComponent
+                        Id: b47febf6-3da3-4d45-af3f-c9491ebc235d
+                        Type: !LightSkybox
+                            Skybox: ae4fd991-6290-4c24-b73b-25d81a1a4837:Materials/Skybox
+                    073131bbebf95a3cbbe2d431328d38b1: !BackgroundComponent
+                        Id: 31232b87-a306-4c37-bfc9-9730577cc63c
+                        Texture: b7f73672-f9bf-44ae-8a04-0017010b4ca1:Materials/Skybox texture
+        -   Entity:
+                Id: b017eab6-ede1-448d-9970-2adf407a53dd
+                Name: Directional light
+                Components:
+                    cf26351dfd6822268d36b77072bcc655: !TransformComponent
+                        Id: f457f360-c2e9-4cb1-8063-cf1dd72e18a0
+                        Position: {X: 100.0, Y: 0.0, Z: 0.0}
+                        Rotation: {X: 1.131334E-08, Y: 0.9659258, Z: 0.258819044, W: -4.222196E-08}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    e3f271d9c2060484c44e8dfef59ed0e3: !LightComponent
+                        Id: 15594294-6eab-4996-b6d9-78eb3792e86d
+                        Type: !LightDirectional
+                            Color: !ColorRgbProvider
+                                Value: {R: 1.0, G: 1.0, B: 1.0}
+                            Shadow:
+                                Enabled: true
+                                Filter: !LightShadowMapFilterTypePcf
+                                    FilterSize: Filter5x5
+                                Size: Large
+                                DepthRange: {}
+                                PartitionMode: !LightDirectionalShadowMap.PartitionLogarithmic {}
+                                ComputeTransmittance: false
+                                BiasParameters: {}
+                        Intensity: 20.0
+        -   Entity:
+                Id: c29e99d3-a22d-40cd-a186-47f86e45368f
+                Name: Yellow Theapot
+                Components:
+                    f8eee6f467c9263f9fdd120f5463f988: !TransformComponent
+                        Id: a9a26b2f-87ba-4560-807c-821feee82430
+                        Position: {X: -0.0526002645, Y: 0.0, Z: 0.0}
+                        Rotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
+                        Scale: {X: 1.0, Y: 1.0, Z: 1.0}
+                        Children: {}
+                    3633cb40f574236299aec88b18c090d2: !ModelComponent
+                        Id: f25e1d13-9f04-42d6-aa8d-37470904654b
+                        Model: 9a3a7dbc-7b08-478a-aab2-19afe1d6ce1c:Models/Teapot
+                        Materials:
+                            d520ca585d4faf100775350f15a43bf3~0: 619de649-4998-4996-bd74-085eaffdbbeb:Materials/Yellow

+ 41 - 0
Tutorials/Tutorials/Basics/KeyboardInput.cs

@@ -0,0 +1,41 @@
+using Xenko.Core.Mathematics;
+using Xenko.Engine;
+using Xenko.Input;
+
+namespace Tutorials.Basics {
+    /// <summary>
+    /// This script demonstrates how to check for keyboard input.
+    /// </summary>
+    public class KeyboardInput : SyncScript {
+        public Entity blueTheapot;
+        public Entity yellowTheapot;
+        public Entity greenTheapot;
+
+        public override void Start() {}
+
+        public override void Update() {
+            //First lets check if we have a keyboard.
+            if (Input.HasKeyboard) {
+
+                //Key down is used for when a key is being held down.
+                DebugText.Print("Hold the 1 key down to rotate the blue theapot", new Int2(50, 160));
+                if (Input.IsKeyDown(Keys.D1)) {
+                    var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;
+                    blueTheapot.Transform.RotationEulerXYZ += new Vector3(0, 0.3f * deltaTime, 0);
+                }
+
+                //Use 'IskeyPressed' for a single key press event. 
+                DebugText.Print("Press F to rotate the yellow theapot (and to pay respects)", new Int2(50, 200));
+                if (Input.IsKeyPressed(Keys.F)) {
+                    yellowTheapot.Transform.RotationEulerXYZ += new Vector3(0, 35, 0);
+                }
+
+                //'IsKeyReleased' is used for when you want to know when a key is released after being either held down or pressed. 
+                DebugText.Print("Press and release the Space bar to rotate the green theapot", new Int2(50, 240));
+                if (Input.IsKeyReleased(Keys.Space)) {
+                    greenTheapot.Transform.RotationEulerXYZ += new Vector3(0, 55, 0);
+                }
+            }
+        }
+    }
+}

+ 3 - 3
en/tutorials/csharpbasics/index.md

@@ -11,6 +11,6 @@ IN REVIEW: You can try out each individual script in by creating a new project a
 * [Delta time](deltaTime.md) 
 * [Cloning an entity](cloningEntities.md) 
 * [Removing an entity](removeEntities.md) 
-* [GetKey](getKey.md) 
-* [GetMouse](getMouse.md) 
-* [GetButton](getButton.md) 
+* [Keyboard input](keyboardInput.md) 
+* [Mouse input](mouseInput.md) 
+* [Virtual buttons](virtualButtons.md)

+ 10 - 0
en/tutorials/csharpbasics/keyboardInput.md

@@ -0,0 +1,10 @@
+# Keyboard input
+You can find this sample in the tutorial project: **Scenes** -> **Basics** -> **Keyboard input** 
+
+## Explanation
+This C# basics tutorial covers how to handle keyboard input. We can check for the existisce of a keyboard and then we can use various methods to check if a key is pressed, held down or released.
+
+![Delta time](media/keyboard-input.png)
+
+## Code
+[!code-csharp[Entity](..\..\..\Tutorials\Tutorials\Basics\KeyboardInput.cs)]

+ 3 - 0
en/tutorials/csharpbasics/media/keyboard-input.png

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:af5b25259ad7d1a88afce3597e0359e85a009c20f19e4c93d25c569ecfd98413
+size 127448

+ 10 - 0
en/tutorials/csharpbasics/mouseInput.md

@@ -0,0 +1,10 @@
+# KeybMouseoard input
+You can find this sample in the tutorial project: **Scenes** -> **Basics** -> **Mouse input** 
+
+## Explanation
+This C# basics tutorial covers how to handle mouse input. We can check for the existance of a mouse and then we can use various methods to check if a mouse buttons are clicked, held down or released. We can also for the mouse wheel being scrolled and clicked.
+
+![Delta time](media/mouse-input.png)
+
+## Code
+[!code-csharp[Entity](..\..\..\Tutorials\Tutorials\Basics\MouseInput.cs)]

+ 10 - 0
en/tutorials/csharpbasics/virtualButtons.md

@@ -0,0 +1,10 @@
+# Virtual buttons
+You can find this sample in the tutorial project: **Scenes** -> **Basics** -> **Virtual buttons** 
+
+## Explanation
+This C# basics tutorial covers how to virtual buttons. Lets say that you a player to jump when a key is pressed. The spacebar is a common option, but what if a gamer wants to have a different key bind to this 'Jump' action. The answer here is the 'Virtual button'. Virtual buttons allow to bind 1 or more keyboard keys, mousebuttons and joystick button to be mapped to a single 'Virtual button'. We can check for the name of that virtual button and if any of the mapped inputs is true, than the virtual button can is triggered.
+
+![Delta time](media/virtual-button.png)
+
+## Code
+[!code-csharp[Entity](..\..\..\Tutorials\Tutorials\Basics\VirtualButtons.cs)]

+ 7 - 7
en/tutorials/toc.md

@@ -8,15 +8,15 @@
 ### [Editor properties](csharpbasics/editorproperties.md) 
 ### [Getting a component](csharpbasics/getcomponent.md) 
 ### [Cloning an entity](csharpbasics/cloningEntities.md) 
-### [Removing an entity](csharpbasics/destroyingentities.md) soon...
-### [GetKey](csharpbasics/getKey.md) soon...
-### [GetMouse](csharpbasics/getMouse.md) soon...
-### [GetButton](csharpbasics/getButton.md) soon...
+### [Removing an entity](csharpbasics/destroyingentities.md) 
+### [Keyboard input](csharpbasics/keyboardInput.md) 
+### [Mouse input](csharpbasics/mouseInput.md) 
+### [Virtual buttons](csharpbasics/virtualButtons.md)
 
 ## [C# intermediate](csharpintermediate/index.md)
-### [Raycasting](csharpintermediate/raycasting.md) soon...
-### [Switching a scene](csharpintermediate/switchingscenes.md)soon...
-### [Loading a child scene](csharpintermediate/loadingchildscene.md)soon...
+### [Raycasting](csharpintermediate/raycasting.md) 
+### [Switching a scene](csharpintermediate/switchingscenes.md)
+### [Loading a child scene](csharpintermediate/loadingchildscene.md)
 
 ## [C# advanced](csharpadvanced/index.md)
 ### [Shader](csharpadvanced/shader.md)