From fc2a7d98faaa55712edcdf2bcb48f03d03e1eebd Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Tue, 14 Dec 2021 16:59:20 +0100 Subject: [PATCH] Add gamepad camera control for editor viewports --- Source/Editor/Viewport/EditorViewport.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index 78f7417ef..695e5d5c9 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -1218,6 +1218,14 @@ namespace FlaxEditor.Viewport // Get input movement Vector3 moveDelta = Vector3.Zero; + Vector2 mouseDelta = Vector2.Zero; + if (FlaxEngine.Input.GamepadsCount > 0) + { + // Gamepads handling + moveDelta += new Vector3(GetGamepadAxis(GamepadAxis.LeftStickX), 0, GetGamepadAxis(GamepadAxis.LeftStickY)); + mouseDelta += new Vector2(GetGamepadAxis(GamepadAxis.RightStickX), -GetGamepadAxis(GamepadAxis.RightStickY)); + _input.IsRotating |= !mouseDelta.IsZero; + } if (win.GetKey(KeyboardKeys.ArrowRight)) { moveDelta += Vector3.Right; @@ -1239,7 +1247,6 @@ namespace FlaxEditor.Viewport // Update moveDelta *= dt * (60.0f * 4.0f); - Vector2 mouseDelta = Vector2.Zero; UpdateView(dt, ref moveDelta, ref mouseDelta, out _); } } @@ -1496,5 +1503,12 @@ namespace FlaxEditor.Viewport } } } + + private float GetGamepadAxis(GamepadAxis axis) + { + var value = FlaxEngine.Input.GetGamepadAxis(InputGamepadIndex.All, axis); + var deadZone = 0.2f; + return value >= deadZone || value <= -deadZone ? value : 0.0f; + } } }