From 0c2483f249f14179263b24cb22cab866be3fdc69 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Mon, 30 Jun 2025 14:56:32 -0700 Subject: [PATCH] Draggable UI improvements --- Assets/Scenes/GamePlayer.unity | 77 ++++++++++++++++++++++----- Assets/Scripts/GamePlayerPauseMenu.cs | 8 +-- Assets/Scripts/IgnoreRaycast.cs | 2 +- 3 files changed, 70 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/GamePlayer.unity b/Assets/Scenes/GamePlayer.unity index 0953e45..de7a48c 100644 --- a/Assets/Scenes/GamePlayer.unity +++ b/Assets/Scenes/GamePlayer.unity @@ -267,6 +267,7 @@ GameObject: - component: {fileID: 83812372} - component: {fileID: 83812371} - component: {fileID: 83812373} + - component: {fileID: 83812374} m_Layer: 5 m_Name: FPSCounter m_TagString: Untagged @@ -288,9 +289,9 @@ RectTransform: m_Children: [] m_Father: {fileID: 1811565639} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -432.5, y: 375} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 210, y: -35} m_SizeDelta: {x: 400, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &83812371 @@ -406,6 +407,18 @@ MonoBehaviour: m_EditorClassIdentifier: uiName: FPSText canDrag: 0 +--- !u!114 &83812374 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 83812369} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9213dca44899f70ffb449db66c6d1764, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &157642289 GameObject: m_ObjectHideFlags: 0 @@ -758,6 +771,7 @@ MonoBehaviour: scoreText: {fileID: 432923591} highScoreText: {fileID: 1606868532} boostText: {fileID: 497996347} + editingUI: 0 --- !u!1 &432923589 GameObject: m_ObjectHideFlags: 0 @@ -770,6 +784,7 @@ GameObject: - component: {fileID: 432923592} - component: {fileID: 432923591} - component: {fileID: 432923593} + - component: {fileID: 432923594} m_Layer: 5 m_Name: ScoreText m_TagString: Untagged @@ -791,9 +806,9 @@ RectTransform: m_Children: [] m_Father: {fileID: 1811565639} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 290} + m_AnchorMin: {x: 0.5, y: 1} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: -70} m_SizeDelta: {x: 1280, y: 90} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &432923591 @@ -909,6 +924,18 @@ MonoBehaviour: m_EditorClassIdentifier: uiName: ScoreText canDrag: 0 +--- !u!114 &432923594 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 432923589} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9213dca44899f70ffb449db66c6d1764, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &450099079 GameObject: m_ObjectHideFlags: 0 @@ -1265,6 +1292,7 @@ GameObject: - component: {fileID: 497996348} - component: {fileID: 497996347} - component: {fileID: 497996349} + - component: {fileID: 497996350} m_Layer: 5 m_Name: BoostText m_TagString: Untagged @@ -1286,9 +1314,9 @@ RectTransform: m_Children: [] m_Father: {fileID: 1811565639} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 170.00003} + m_AnchorMin: {x: 0.5, y: 1} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: -189.99997} m_SizeDelta: {x: 1280, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &497996347 @@ -1404,6 +1432,18 @@ MonoBehaviour: m_EditorClassIdentifier: uiName: BoostText canDrag: 0 +--- !u!114 &497996350 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 497996345} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9213dca44899f70ffb449db66c6d1764, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &519420028 GameObject: m_ObjectHideFlags: 0 @@ -2926,6 +2966,7 @@ GameObject: - component: {fileID: 1606868533} - component: {fileID: 1606868532} - component: {fileID: 1606868534} + - component: {fileID: 1606868535} m_Layer: 5 m_Name: HighScoreText m_TagString: Untagged @@ -2947,9 +2988,9 @@ RectTransform: m_Children: [] m_Father: {fileID: 1811565639} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 219.99997} + m_AnchorMin: {x: 0.5, y: 1} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: -140.00003} m_SizeDelta: {x: 1280, y: 45} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1606868532 @@ -3065,6 +3106,18 @@ MonoBehaviour: m_EditorClassIdentifier: uiName: HighScoreText canDrag: 0 +--- !u!114 &1606868535 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1606868530} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9213dca44899f70ffb449db66c6d1764, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1625416038 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GamePlayerPauseMenu.cs b/Assets/Scripts/GamePlayerPauseMenu.cs index c6786a9..c114717 100644 --- a/Assets/Scripts/GamePlayerPauseMenu.cs +++ b/Assets/Scripts/GamePlayerPauseMenu.cs @@ -45,10 +45,10 @@ public class GamePlayerPauseMenu : MonoBehaviour }); resetUiButton.onClick.AddListener(() => { - fpsText.transform.localPosition = new Vector2(-432.5f, 375f); - scoreText.transform.localPosition = new Vector2(0f, 290f); - highScoreText.transform.localPosition = new Vector2(0f, 220f); - boostText.transform.localPosition = new Vector2(0f, 170f); + ((RectTransform)fpsText.transform).anchoredPosition = new Vector2(210f, -35f); + ((RectTransform)scoreText.transform).anchoredPosition = new Vector2(0f, -70f); + ((RectTransform)highScoreText.transform).anchoredPosition = new Vector2(0f, -140f); + ((RectTransform)boostText.transform).anchoredPosition = new Vector2(0f, -190f); PlayerPrefs.DeleteKey("DraggedUIFPSText"); PlayerPrefs.DeleteKey("DraggedUIScoreText"); PlayerPrefs.DeleteKey("DraggedUIHighScoreText"); diff --git a/Assets/Scripts/IgnoreRaycast.cs b/Assets/Scripts/IgnoreRaycast.cs index eb7de47..fbd6216 100644 --- a/Assets/Scripts/IgnoreRaycast.cs +++ b/Assets/Scripts/IgnoreRaycast.cs @@ -2,5 +2,5 @@ using UnityEngine; public class IgnoreRaycast : MonoBehaviour, ICanvasRaycastFilter { - public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera) => false; + public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera) => GetComponent() != null && GetComponent().canDrag; } \ No newline at end of file