From 658cd58e30a0610ba86f84e98a5c9ba80167f31c Mon Sep 17 00:00:00 2001 From: cooney Date: Mon, 26 Jan 2026 20:37:55 +0900 Subject: [PATCH] =?UTF-8?q?UI=EB=A7=A4=EB=8B=88=EC=A0=80=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Prefabs/UI/Popup/UI_Button.prefab | 82 ++++++++- Assets/Scenes/SampleScene.unity | 174 +++++++++++++++++- .../Scripts/Controllers/PlayerController.cs | 4 +- Assets/Scripts/Managers/UIManager.cs | 53 +++++- Assets/Scripts/UI/Popup/UI_Button.cs | 7 + Assets/Scripts/UI/Popup/UI_Popup.cs | 8 +- Assets/Scripts/UI/Scene/UI_Scene.cs | 9 +- 7 files changed, 311 insertions(+), 26 deletions(-) diff --git a/Assets/Resources/Prefabs/UI/Popup/UI_Button.prefab b/Assets/Resources/Prefabs/UI/Popup/UI_Button.prefab index f57dc1d..8b9b6a2 100644 --- a/Assets/Resources/Prefabs/UI/Popup/UI_Button.prefab +++ b/Assets/Resources/Prefabs/UI/Popup/UI_Button.prefab @@ -172,8 +172,8 @@ RectTransform: 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: 0} - m_SizeDelta: {x: 100, y: 100} + m_AnchoredPosition: {x: 6.5198, y: 2.445} + m_SizeDelta: {x: 1165.9971, y: 417.843} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &4364403290364872906 CanvasRenderer: @@ -196,7 +196,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Color: {r: 0.17928976, g: 0.3342303, b: 0.745283, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 @@ -358,6 +358,81 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 +--- !u!1 &4264258648771630736 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8518210677045445944} + - component: {fileID: 7009258958550476364} + - component: {fileID: 1967232194002159381} + m_Layer: 5 + m_Name: Blocker + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &8518210677045445944 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4264258648771630736} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 769090406308646766} + 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: 0} + m_SizeDelta: {x: 1973, y: 682} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &7009258958550476364 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4264258648771630736} + m_CullTransparentMesh: 1 +--- !u!114 &1967232194002159381 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4264258648771630736} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 0} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!1 &4452573537343001885 GameObject: m_ObjectHideFlags: 0 @@ -558,6 +633,7 @@ RectTransform: m_LocalScale: {x: 0, y: 0, z: 0} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 8518210677045445944} - {fileID: 272034280093159647} - {fileID: 2663493036096751071} - {fileID: 6652151643977742740} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 7f78e50..51ff3bb 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -216,6 +216,131 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1001 &513036105 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_Pivot.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_Pivot.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchorMax.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchorMax.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchorMin.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchorMin.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_SizeDelta.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_SizeDelta.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchoredPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchoredPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 769090406308646766, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6011887641808883285, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_SizeDelta.x + value: 1598.0125 + objectReference: {fileID: 0} + - target: {fileID: 6011887641808883285, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_SizeDelta.y + value: 509.067 + objectReference: {fileID: 0} + - target: {fileID: 6011887641808883285, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchoredPosition.x + value: -29.1026 + objectReference: {fileID: 0} + - target: {fileID: 6011887641808883285, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_AnchoredPosition.y + value: 4.9136 + objectReference: {fileID: 0} + - target: {fileID: 7343359177762002509, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_Color.b + value: 0.21545738 + objectReference: {fileID: 0} + - target: {fileID: 7343359177762002509, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_Color.g + value: 0.18039215 + objectReference: {fileID: 0} + - target: {fileID: 7343359177762002509, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_Color.r + value: 0.74509805 + objectReference: {fileID: 0} + - target: {fileID: 7475544957123485698, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} + propertyPath: m_Name + value: UI_Button + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: c37cc897a85d2a94890cf5ba8fd63495, type: 3} --- !u!1 &587582342 GameObject: m_ObjectHideFlags: 0 @@ -322,12 +447,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 587582342} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.05714, y: 1.2596, z: 5.5541463} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.49456, y: 1.2596, z: 4.046586} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 0} + m_Father: {fileID: 2005468121} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!54 &587582348 Rigidbody: @@ -645,12 +770,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1226977306} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.05714, y: 1.2596, z: 7.698694} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.49456, y: 1.2596, z: 6.1911345} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 0} + m_Father: {fileID: 2005468121} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1359563799 GameObject: @@ -839,6 +964,39 @@ PrefabInstance: insertIndex: -1 addedObject: {fileID: 682105188} m_SourcePrefab: {fileID: 100100000, guid: e90488251cab05045aa6e1baa6774cc1, type: 3} +--- !u!1 &2005468120 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2005468121} + m_Layer: 0 + m_Name: Env + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2005468121 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2005468120} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 1.5517, y: -0, z: 1.50756} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 587582347} + - {fileID: 1226977311} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &6313602676529983552 PrefabInstance: m_ObjectHideFlags: 0 @@ -912,6 +1070,6 @@ SceneRoots: - {fileID: 6313602676529983552} - {fileID: 1814897681} - {fileID: 1359563803} - - {fileID: 587582347} - - {fileID: 1226977311} - {fileID: 635655862} + - {fileID: 2005468121} + - {fileID: 513036105} diff --git a/Assets/Scripts/Controllers/PlayerController.cs b/Assets/Scripts/Controllers/PlayerController.cs index 1bd3cf5..6b81784 100644 --- a/Assets/Scripts/Controllers/PlayerController.cs +++ b/Assets/Scripts/Controllers/PlayerController.cs @@ -21,9 +21,7 @@ public class PlayerController : MonoBehaviour // Managers.Resource.Instantiate("UI/UI_Button"); // TEMP - UI_Button ui = Managers.UI.ShowPopupUI(); - - Managers.UI.ClosePopupUI(ui); + Managers.UI.ShowPopupUI(); } public enum PlayerState diff --git a/Assets/Scripts/Managers/UIManager.cs b/Assets/Scripts/Managers/UIManager.cs index 2151c05..93a097f 100644 --- a/Assets/Scripts/Managers/UIManager.cs +++ b/Assets/Scripts/Managers/UIManager.cs @@ -3,10 +3,59 @@ using UnityEngine; public class UIManager { - int _order = 0; + int _order = 10; Stack _popupStack = new Stack(); + UI_Scene _sceneUI = null; + public GameObject Root + { + get + { + GameObject root = GameObject.Find("@UI_Root"); + + if (root == null) + { + root = new GameObject("@UI_Root"); + } + return root; + } + + } + + public void SetCanvas(GameObject go, bool sort = true) + { + Canvas canvas = Util.GetOrAddComponent(go); + canvas.renderMode = RenderMode.ScreenSpaceOverlay; + canvas.overrideSorting = true; + + if (sort) + { + canvas.sortingOrder = _order; + _order++; + } + else + { + canvas.sortingOrder = 0; + } + } + + public T ShowSceneUI(string name = null) where T : UI_Scene + { + if (string.IsNullOrEmpty(name)) + { + name = typeof(T).Name; + } + + GameObject go = Managers.Resource.Instantiate($"UI/Scene/{name}"); + T sceneUI = Util.GetOrAddComponent(go); + _sceneUI = sceneUI; + + go.transform.SetParent(Root.transform); + + return sceneUI; + } + public T ShowPopupUI(string name = null) where T : UI_Popup { if (string.IsNullOrEmpty(name)) @@ -18,6 +67,8 @@ public class UIManager T popup = Util.GetOrAddComponent(go); _popupStack.Push(popup); + go.transform.SetParent(Root.transform); + return popup; } diff --git a/Assets/Scripts/UI/Popup/UI_Button.cs b/Assets/Scripts/UI/Popup/UI_Button.cs index 968a13b..352c4a0 100644 --- a/Assets/Scripts/UI/Popup/UI_Button.cs +++ b/Assets/Scripts/UI/Popup/UI_Button.cs @@ -30,6 +30,13 @@ public class UI_Button : UI_Popup private void Start() { + Init(); + } + + public override void Init() + { + base.Init(); + // Reflection Bind