2026-06-19 UI, UI로직

This commit is contained in:
skrwns304@gmail.com
2026-06-19 14:27:40 +09:00
parent b751a9ed66
commit b1e85a5b89
549 changed files with 18058 additions and 20 deletions

View File

@@ -0,0 +1,173 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootprintHintManager : MonoBehaviour
{
[Header("VR Player Reference")]
[Tooltip("XR Origin의 Main Camera Transform을 넣는 것을 추천합니다.")]
[SerializeField] private Transform playerTarget;
[Header("Footprint Prefabs")]
[SerializeField] private GameObject leftFootPrefab;
[SerializeField] private GameObject rightFootPrefab;
[Header("Footprint Settings")]
[SerializeField] private int footprintCount = 6;
[SerializeField] private float spacing = 0.45f;
[SerializeField] private float sideOffset = 0.13f;
[SerializeField] private float showTime = 2f;
[SerializeField] private bool startWithLeftFoot = true;
[Header("Ground Settings")]
[SerializeField] private bool useGroundRaycast = true;
[SerializeField] private LayerMask groundMask = ~0;
[SerializeField] private float raycastHeight = 2f;
[SerializeField] private float raycastDistance = 5f;
[SerializeField] private float groundOffset = 0.03f;
[SerializeField] private float fallbackGroundY = 0f;
private readonly List<GameObject> spawnedFootprints = new List<GameObject>();
private Coroutine footprintRoutine;
public void ShowFootprints(MazeDirection direction)
{
if (footprintRoutine != null)
StopCoroutine(footprintRoutine);
footprintRoutine = StartCoroutine(ShowFootprintRoutine(direction));
}
private IEnumerator ShowFootprintRoutine(MazeDirection direction)
{
ClearFootprints();
if (playerTarget == null)
{
Debug.LogWarning("FootprintHintManager: Player Target is missing.");
footprintRoutine = null;
yield break;
}
if (leftFootPrefab == null || rightFootPrefab == null)
{
Debug.LogWarning("FootprintHintManager: Left Foot Prefab or Right Foot Prefab is missing.");
footprintRoutine = null;
yield break;
}
Vector3 moveDirection = GetWorldDirection(direction);
if (moveDirection == Vector3.zero)
{
footprintRoutine = null;
yield break;
}
Vector3 sideDirection = Vector3.Cross(Vector3.up, moveDirection).normalized;
for (int i = 0; i < footprintCount; i++)
{
bool isLeftFoot = startWithLeftFoot ? i % 2 == 0 : i % 2 != 0;
GameObject prefabToUse = isLeftFoot ? leftFootPrefab : rightFootPrefab;
float forwardDistance = spacing * (i + 1);
float leftRightOffset = isLeftFoot ? -sideOffset : sideOffset;
Vector3 spawnPosition =
playerTarget.position +
moveDirection * forwardDistance +
sideDirection * leftRightOffset;
Quaternion spawnRotation = Quaternion.LookRotation(moveDirection, Vector3.up);
PlaceOnGround(ref spawnPosition, ref spawnRotation, moveDirection);
GameObject footprint = Instantiate(
prefabToUse,
spawnPosition,
spawnRotation
);
spawnedFootprints.Add(footprint);
}
yield return new WaitForSeconds(showTime);
ClearFootprints();
footprintRoutine = null;
}
private Vector3 GetWorldDirection(MazeDirection direction)
{
Vector3 forward = playerTarget.forward;
Vector3 right = playerTarget.right;
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
switch (direction)
{
case MazeDirection.Forward:
return forward;
case MazeDirection.Backward:
return -forward;
case MazeDirection.Left:
return -right;
case MazeDirection.Right:
return right;
case MazeDirection.None:
default:
return Vector3.zero;
}
}
private void PlaceOnGround(
ref Vector3 position,
ref Quaternion rotation,
Vector3 moveDirection
)
{
if (!useGroundRaycast)
{
position.y = fallbackGroundY + groundOffset;
return;
}
Vector3 rayStart = position + Vector3.up * raycastHeight;
if (Physics.Raycast(rayStart, Vector3.down, out RaycastHit hit, raycastDistance, groundMask))
{
position = hit.point + hit.normal * groundOffset;
Vector3 projectedForward =
Vector3.ProjectOnPlane(moveDirection, hit.normal).normalized;
if (projectedForward.sqrMagnitude > 0.001f)
rotation = Quaternion.LookRotation(projectedForward, hit.normal);
}
else
{
position.y = fallbackGroundY + groundOffset;
}
}
public void ClearFootprints()
{
foreach (GameObject footprint in spawnedFootprints)
{
if (footprint != null)
Destroy(footprint);
}
spawnedFootprints.Clear();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ea80bc964f8932649a840b3fd8cbf34f

View File

@@ -0,0 +1,8 @@
public enum MazeDirection
{
None,
Forward,
Backward,
Left,
Right
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4dbf81c4c8135684d934e97d4158abae

View 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();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b9aa32259300fd84f88c69548784c009

View File

@@ -0,0 +1,42 @@
using TMPro;
using UnityEngine;
public class MazeUIManager : MonoBehaviour
{
[Header("Result UI")]
[SerializeField] private GameObject rewardPanel;
[SerializeField] private TextMeshProUGUI rewardText;
private void Awake()
{
HideReward();
}
public void ShowSuccess()
{
ShowResult("SUCCESS!", Color.green);
}
public void ShowFail()
{
ShowResult("FAIL!", Color.red);
}
private void ShowResult(string message, Color color)
{
if (rewardPanel != null)
rewardPanel.SetActive(true);
if (rewardText != null)
{
rewardText.text = message;
rewardText.color = color;
}
}
public void HideReward()
{
if (rewardPanel != null)
rewardPanel.SetActive(false);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a006d8153489a634697983539bc6d7f5