From cc276f33df8cef6ac7570c3f62287e73e7f24945 Mon Sep 17 00:00:00 2001 From: superboo07 <39241538+superboo07@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:39:18 -0500 Subject: [PATCH 1/2] Initial implementation of cursor that doesn't hide --- Core_GamepadSupport/Navigation/CanvasCharmer.cs | 2 ++ Core_GamepadSupport/Navigation/CursorDrawer.cs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Core_GamepadSupport/Navigation/CanvasCharmer.cs b/Core_GamepadSupport/Navigation/CanvasCharmer.cs index b2db3f8..9d6130e 100644 --- a/Core_GamepadSupport/Navigation/CanvasCharmer.cs +++ b/Core_GamepadSupport/Navigation/CanvasCharmer.cs @@ -67,6 +67,8 @@ private void OnGUI() if (GamepadSupportPlugin.CanvasDebug.Value) DrawCanvasList(currentSelectedGameObject); + + CursorDrawer.DrawMousePointer(Input.mousePosition); } private void Update() diff --git a/Core_GamepadSupport/Navigation/CursorDrawer.cs b/Core_GamepadSupport/Navigation/CursorDrawer.cs index baab260..a521d62 100644 --- a/Core_GamepadSupport/Navigation/CursorDrawer.cs +++ b/Core_GamepadSupport/Navigation/CursorDrawer.cs @@ -7,10 +7,12 @@ namespace KK_GamepadSupport.Navigation public class CursorDrawer { private Texture2D _pointer; + private Texture2D _mousePointer; public void LoadTexture() { _pointer = ResourceUtils.GetEmbeddedResource("pointer.png", typeof(CursorDrawer).Assembly).LoadTexture(); + _mousePointer = ResourceUtils.GetEmbeddedResource("pointer.png", typeof(CursorDrawer).Assembly).LoadTexture(); const int idealResolutionH = 1800; @@ -19,6 +21,9 @@ public void LoadTexture() var scaleFactor = (float)Screen.height / idealResolutionH; TextureScale.Bilinear(_pointer, (int)(_pointer.width * scaleFactor), (int)(_pointer.height * scaleFactor)); _pointer.Apply(false); + + TextureScale.Bilinear(_mousePointer, (int)(_mousePointer.width * scaleFactor), (int)(_mousePointer.height * scaleFactor)); + _mousePointer.Apply(false); } } @@ -61,6 +66,11 @@ public void Draw(Vector2 pixelPosition, bool poke) GUI.Label(new Rect(Mathf.Max(0, pixelPosition.x - _pointer.width) + offset, pixelPosition.y - _pointer.height / 3f, _pointer.width, _pointer.height), _pointer); } + public void DrawMousePointer(Vector3 mousePosition) + { + GUI.Label(new Rect(mousePosition.x - _mousePointer.width / 2, Screen.height - mousePosition.y - _mousePointer.height / 2, _mousePointer.width, _mousePointer.height), _mousePointer); + } + private static Rect RectTransformToScreenSpace(RectTransform transform) { var size = Vector2.Scale(transform.rect.size, transform.lossyScale); From ac6938c0c8488d30c76629f8ace4947eb65a155a Mon Sep 17 00:00:00 2001 From: superboo07 <39241538+superboo07@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:53:19 -0500 Subject: [PATCH 2/2] Make cursor rendering better --- Core_GamepadSupport/Gamepad/CursorEmulator.cs | 5 +++++ Core_GamepadSupport/Navigation/CanvasCharmer.cs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Core_GamepadSupport/Gamepad/CursorEmulator.cs b/Core_GamepadSupport/Gamepad/CursorEmulator.cs index f9f4867..7753116 100644 --- a/Core_GamepadSupport/Gamepad/CursorEmulator.cs +++ b/Core_GamepadSupport/Gamepad/CursorEmulator.cs @@ -70,6 +70,7 @@ public static void OnUpdate() if (EmulatingCursor()) { + Cursor.visible = false; var rightStick = GamepadWhisperer.GetRightStick(); if (rightStick.magnitude > 0) { @@ -92,6 +93,10 @@ public static void OnUpdate() if (scrollAmount != 0) Native.mouse_event(Native.MOUSEEVENTF_WHEEL, 0, 0, scrollAmount, 0); } + else + { + Cursor.visible = true; + } _previousR = rPressed; _previousL = lPressed; diff --git a/Core_GamepadSupport/Navigation/CanvasCharmer.cs b/Core_GamepadSupport/Navigation/CanvasCharmer.cs index 9d6130e..744b53e 100644 --- a/Core_GamepadSupport/Navigation/CanvasCharmer.cs +++ b/Core_GamepadSupport/Navigation/CanvasCharmer.cs @@ -68,7 +68,8 @@ private void OnGUI() if (GamepadSupportPlugin.CanvasDebug.Value) DrawCanvasList(currentSelectedGameObject); - CursorDrawer.DrawMousePointer(Input.mousePosition); + if (!Cursor.visible) + CursorDrawer.DrawMousePointer(Input.mousePosition); } private void Update()