From 962ccfbfe7ea1427c9c4ad64eb80c4b0abce88e7 Mon Sep 17 00:00:00 2001 From: IDMhan Date: Tue, 26 Dec 2023 11:10:48 +0900 Subject: [PATCH] [HOTFIX] UIManager Refactor --- BlueWater/Assets/01.Scenes/02.Tycoon.unity | 16 +++- .../Assets/02.Scripts/Tycoon/TycoonPlayer.cs | 96 ++++++++++--------- .../Assets/02.Scripts/Tycoon/TycoonUi.cs | 22 +++++ .../Assets/02.Scripts/Tycoon/TycoonUi.cs.meta | 11 +++ BlueWater/Assets/02.Scripts/Ui/UiManager.cs | 19 +--- 5 files changed, 104 insertions(+), 60 deletions(-) create mode 100644 BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs create mode 100644 BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs.meta diff --git a/BlueWater/Assets/01.Scenes/02.Tycoon.unity b/BlueWater/Assets/01.Scenes/02.Tycoon.unity index 4a4430db1..1e1cfaadb 100644 --- a/BlueWater/Assets/01.Scenes/02.Tycoon.unity +++ b/BlueWater/Assets/01.Scenes/02.Tycoon.unity @@ -12310,6 +12310,7 @@ GameObject: - component: {fileID: 957212529} - component: {fileID: 957212528} - component: {fileID: 957212527} + - component: {fileID: 957212531} m_Layer: 5 m_Name: Canvas m_TagString: Untagged @@ -12400,6 +12401,19 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!114 &957212531 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 957212526} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 06c19c0e062e84c169aca3af92060883, type: 3} + m_Name: + m_EditorClassIdentifier: + _persistent: 0 --- !u!1 &957702341 GameObject: m_ObjectHideFlags: 0 @@ -14151,7 +14165,7 @@ GameObject: - component: {fileID: 1072594281} - component: {fileID: 1072594284} m_Layer: 5 - m_Name: UIPopup + m_Name: BuildListPopup m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/BlueWater/Assets/02.Scripts/Tycoon/TycoonPlayer.cs b/BlueWater/Assets/02.Scripts/Tycoon/TycoonPlayer.cs index 75f6bf8d7..91b800039 100644 --- a/BlueWater/Assets/02.Scripts/Tycoon/TycoonPlayer.cs +++ b/BlueWater/Assets/02.Scripts/Tycoon/TycoonPlayer.cs @@ -69,7 +69,16 @@ namespace BlueWaterProject private void OnBuildMode(InputValue value) { + var buildListPopup = UiManager.Inst.TycoonUi.BuildListPopup; + if (buildListPopup.gameObject.activeSelf) + { + buildListPopup.Hide(); + } + else + { + buildListPopup.Show(); + } } private void OnCancel(InputValue value) @@ -140,62 +149,61 @@ namespace BlueWaterProject public void StartInteraction(Transform target) { - interactionTarget = target; - interactionTarget.GetComponent()?.ChangeStateToInteraction(); - - var targetPosition = interactionTarget.position; - var playerPosition = transform.position; - - var directionToTarget = (targetPosition - playerPosition).normalized; - - // 캐릭터가 NPC의 왼쪽 또는 오른쪽에 있는지 확인 - var crossProduct = Vector3.Cross(directionToTarget, transform.forward).y; - - Vector3 desiredPosition; - float desiredScaleX; // 캐릭터의 방 - - if (crossProduct > 0) // 캐릭터가 NPC의 왼쪽에 있는 경우 - { - desiredPosition = targetPosition + interactionTarget.right * 2f; - desiredScaleX = 1f; // 오른쪽을 바라봄 - } - else // 캐릭터가 NPC의 오른쪽에 있는 경우 - { - desiredPosition = targetPosition + interactionTarget.right * -2f; - desiredScaleX = -1f; // 왼쪽을 바라봄 - } - - // 장애물 감지 - if (Physics.Raycast(playerPosition, (desiredPosition - playerPosition).normalized, Vector3.Distance(playerPosition, desiredPosition), LayerMask.GetMask("Obstacle"))) - { - // 장애물이 감지되면, 반대쪽으로 이동 - desiredPosition = crossProduct > 0 ? targetPosition + interactionTarget.right * -2f : targetPosition + interactionTarget.right * 2f; - desiredScaleX = -desiredScaleX; // 방향을 반전 - } - - // 캐릭터를 원하는 위치와 방향으로 부드럽게 이동 및 회전 - StartCoroutine(MoveCharacterToPosition(desiredPosition, desiredScaleX)); - UiManager.Inst.InShipInteraction.gameObject.SetActive(true); + // interactionTarget = target; + // interactionTarget.GetComponent()?.ChangeStateToInteraction(); + // + // var targetPosition = interactionTarget.position; + // var playerPosition = transform.position; + // + // var directionToTarget = (targetPosition - playerPosition).normalized; + // + // // 캐릭터가 NPC의 왼쪽 또는 오른쪽에 있는지 확인 + // var crossProduct = Vector3.Cross(directionToTarget, transform.forward).y; + // + // Vector3 desiredPosition; + // float desiredScaleX; // 캐릭터의 방 + // + // if (crossProduct > 0) // 캐릭터가 NPC의 왼쪽에 있는 경우 + // { + // desiredPosition = targetPosition + interactionTarget.right * 2f; + // desiredScaleX = 1f; // 오른쪽을 바라봄 + // } + // else // 캐릭터가 NPC의 오른쪽에 있는 경우 + // { + // desiredPosition = targetPosition + interactionTarget.right * -2f; + // desiredScaleX = -1f; // 왼쪽을 바라봄 + // } + // + // // 장애물 감지 + // if (Physics.Raycast(playerPosition, (desiredPosition - playerPosition).normalized, Vector3.Distance(playerPosition, desiredPosition), LayerMask.GetMask("Obstacle"))) + // { + // // 장애물이 감지되면, 반대쪽으로 이동 + // desiredPosition = crossProduct > 0 ? targetPosition + interactionTarget.right * -2f : targetPosition + interactionTarget.right * 2f; + // desiredScaleX = -desiredScaleX; // 방향을 반전 + // } + // + // // 캐릭터를 원하는 위치와 방향으로 부드럽게 이동 및 회전 + // StartCoroutine(MoveCharacterToPosition(desiredPosition, desiredScaleX)); + // UiManager.Inst.InShipInteraction.gameObject.SetActive(true); } public void StartConversation() { - if (interactionTarget != null) - { - interactionTarget.GetComponent().OnConversationStart(interactionTarget); - UiManager.Inst.InShipInteraction.gameObject.SetActive(false); - } + // if (interactionTarget != null) + // { + // interactionTarget.GetComponent().OnConversationStart(interactionTarget); + // UiManager.Inst.InShipInteraction.gameObject.SetActive(false); + // } } public void EndInteraction() { - interactionTarget.GetComponent()?.RestoreState(); + //interactionTarget.GetComponent()?.RestoreState(); } public void EndConversation() { - UiManager.Inst.InShipInteraction.gameObject.SetActive(true); - + //UiManager.Inst.InShipInteraction.gameObject.SetActive(true); } } } diff --git a/BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs b/BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs new file mode 100644 index 000000000..4535b610f --- /dev/null +++ b/BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using BlueWaterProject; +using Doozy.Runtime.UIManager.Containers; +using UnityEngine; + +public class TycoonUi : MonoBehaviour +{ + public UIPopup BuildListPopup { get; set; } + + private void Init() + { + UiManager.Inst.TycoonUi = this; + BuildListPopup = transform.Find("BuildListPopup").GetComponent(); + } + + private void Awake() + { + Init(); + } +} diff --git a/BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs.meta b/BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs.meta new file mode 100644 index 000000000..c09860c3b --- /dev/null +++ b/BlueWater/Assets/02.Scripts/Tycoon/TycoonUi.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 54648b16fa3ac47d9bc7543e261ac76e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/BlueWater/Assets/02.Scripts/Ui/UiManager.cs b/BlueWater/Assets/02.Scripts/Ui/UiManager.cs index ddef8635d..2f0179e65 100644 --- a/BlueWater/Assets/02.Scripts/Ui/UiManager.cs +++ b/BlueWater/Assets/02.Scripts/Ui/UiManager.cs @@ -1,3 +1,4 @@ +using Doozy.Runtime.UIManager.Containers; using Sirenix.OdinInspector; using UnityEngine; @@ -9,24 +10,12 @@ namespace BlueWaterProject { [Title("Mouse")] private Texture2D cursorTexture; - - [Title("InteractionUI")] - private Transform defaultInteraction; - public Transform InShipInteraction { get; set; } public OceanUi OceanUi { get; set; } - - private void Init() - { - defaultInteraction = transform.Find("DefaultInteraction"); - InShipInteraction = transform.Find("InShipPlayerInteractionUI"); - } - - protected override void OnAwake() - { - Init(); - } + [Title("Tycoon")] + public TycoonUi TycoonUi { get; set; } + private void Start() {