2026-06-19 UI, UI로직
This commit is contained in:
167
Assets/My project/maze Scripts/Ui/MazeGameManager.cs
Normal file
167
Assets/My project/maze Scripts/Ui/MazeGameManager.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MazeGameManager : MonoBehaviour
|
||||
{
|
||||
[Header("VR Player Reference")]
|
||||
[Tooltip("XR Origin 또는 Main Camera Transform을 넣으세요.")]
|
||||
[SerializeField] private Transform playerTarget;
|
||||
|
||||
[Header("Managers")]
|
||||
[SerializeField] private MazeUIManager mazeUI;
|
||||
[SerializeField] private FootprintHintManager footprintHint;
|
||||
|
||||
[Header("Goal")]
|
||||
[SerializeField] private Transform goal;
|
||||
[SerializeField] private float goalDistance = 1.5f;
|
||||
|
||||
[Header("Checkpoints")]
|
||||
[SerializeField] private Transform[] checkpoints;
|
||||
[SerializeField] private float checkpointDistance = 1.5f;
|
||||
|
||||
[Header("Checkpoint Directions")]
|
||||
[Tooltip("각 체크포인트에 도착했을 때 보여줄 발자국 방향입니다.")]
|
||||
[SerializeField] private MazeDirection[] checkpointDirections;
|
||||
|
||||
[Header("VR Distance Option")]
|
||||
[Tooltip("VR에서는 머리 높이가 달라지므로 보통 Y축 높이는 무시하는 것이 좋습니다.")]
|
||||
[SerializeField] private bool ignoreHeight = true;
|
||||
|
||||
private bool[] reached;
|
||||
private bool isCompleted;
|
||||
private bool isFailed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitializeCheckpoints();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ResetMaze();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isCompleted || isFailed)
|
||||
return;
|
||||
|
||||
if (playerTarget == null)
|
||||
return;
|
||||
|
||||
CheckCheckpoints();
|
||||
CheckGoal();
|
||||
}
|
||||
|
||||
private void InitializeCheckpoints()
|
||||
{
|
||||
int count = checkpoints != null ? checkpoints.Length : 0;
|
||||
reached = new bool[count];
|
||||
}
|
||||
|
||||
private void CheckCheckpoints()
|
||||
{
|
||||
if (checkpoints == null || checkpoints.Length == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < checkpoints.Length; i++)
|
||||
{
|
||||
if (reached[i])
|
||||
continue;
|
||||
|
||||
if (checkpoints[i] == null)
|
||||
continue;
|
||||
|
||||
float distance = GetDistance(playerTarget.position, checkpoints[i].position);
|
||||
|
||||
if (distance <= checkpointDistance)
|
||||
{
|
||||
reached[i] = true;
|
||||
|
||||
MazeDirection direction = GetCheckpointDirection(i);
|
||||
|
||||
if (footprintHint != null)
|
||||
footprintHint.ShowFootprints(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckGoal()
|
||||
{
|
||||
if (goal == null)
|
||||
return;
|
||||
|
||||
float distance = GetDistance(playerTarget.position, goal.position);
|
||||
|
||||
if (distance <= goalDistance)
|
||||
Complete();
|
||||
}
|
||||
|
||||
private float GetDistance(Vector3 a, Vector3 b)
|
||||
{
|
||||
if (ignoreHeight)
|
||||
{
|
||||
a.y = 0f;
|
||||
b.y = 0f;
|
||||
}
|
||||
|
||||
return Vector3.Distance(a, b);
|
||||
}
|
||||
|
||||
private MazeDirection GetCheckpointDirection(int index)
|
||||
{
|
||||
if (checkpointDirections != null &&
|
||||
index >= 0 &&
|
||||
index < checkpointDirections.Length)
|
||||
{
|
||||
return checkpointDirections[index];
|
||||
}
|
||||
|
||||
return MazeDirection.None;
|
||||
}
|
||||
|
||||
private void Complete()
|
||||
{
|
||||
if (isCompleted || isFailed)
|
||||
return;
|
||||
|
||||
isCompleted = true;
|
||||
|
||||
if (footprintHint != null)
|
||||
footprintHint.ClearFootprints();
|
||||
|
||||
if (mazeUI != null)
|
||||
mazeUI.ShowSuccess();
|
||||
}
|
||||
|
||||
public void Fail()
|
||||
{
|
||||
if (isCompleted || isFailed)
|
||||
return;
|
||||
|
||||
isFailed = true;
|
||||
|
||||
if (footprintHint != null)
|
||||
footprintHint.ClearFootprints();
|
||||
|
||||
if (mazeUI != null)
|
||||
mazeUI.ShowFail();
|
||||
}
|
||||
|
||||
public void ResetMaze()
|
||||
{
|
||||
isCompleted = false;
|
||||
isFailed = false;
|
||||
|
||||
if (reached == null || reached.Length != (checkpoints != null ? checkpoints.Length : 0))
|
||||
InitializeCheckpoints();
|
||||
|
||||
for (int i = 0; i < reached.Length; i++)
|
||||
reached[i] = false;
|
||||
|
||||
if (footprintHint != null)
|
||||
footprintHint.ClearFootprints();
|
||||
|
||||
if (mazeUI != null)
|
||||
mazeUI.HideReward();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user