This commit is contained in:
2026-06-24 20:36:47 +09:00
30 changed files with 2544 additions and 291 deletions

View File

@@ -9,11 +9,13 @@ public class HookWalkToTable : MonoBehaviour
public Transform tableFrontPoint;
public Transform chairFrontPoint;
[Header("Sit Point")]
[Header("Sit / Stand Point")]
public Transform sitPoint;
public Transform standPoint;
[Header("Move Setting")]
public float arriveBuffer = 0.15f;
public float navMeshSampleDistance = 1.5f;
[Header("Animator")]
public Animator animator;
@@ -21,8 +23,16 @@ public class HookWalkToTable : MonoBehaviour
public string sitTriggerName = "sitTrigger";
public string standTriggerName = "standTrigger";
[Header("Force Stand Animation")]
public bool forcePlayStandState = true;
public string standStateName = "Sit To Stand 0";
[Header("Stand Up Setting")]
public float standUpDuration = 1.5f;
public bool disableAgentAfterStandUp = true;
[Header("After Match")]
public bool blockWalkingAfterStandUp = true;
[Header("Collision")]
public bool disableCollidersWhenSitting = true;
@@ -37,16 +47,21 @@ public class HookWalkToTable : MonoBehaviour
private int step = 0;
private bool isMoving = false;
private bool hasArrived = false;
private bool isSitting = false;
private bool isStandingUp = false;
private bool hasStoodUpAfterMatch = false;
private Vector3 currentDestination;
void Start()
private void Start()
{
agent = GetComponent<NavMeshAgent>();
if (animator == null)
{
animator = GetComponentInChildren<Animator>();
}
if (agent != null)
{
agent.isStopped = true;
@@ -57,32 +72,37 @@ void Start()
if (animator != null)
{
animator.applyRootMotion = false;
animator.SetBool(walkBoolName, false);
animator.ResetTrigger(sitTriggerName);
animator.ResetTrigger(standTriggerName);
}
else
{
Debug.LogWarning("Hook Animator is missing.");
}
if (hookColliders == null || hookColliders.Length == 0)
{
hookColliders = GetComponentsInChildren<Collider>();
}
Debug.Log("HookWalkToTable ready.");
}
void Update()
private void Update()
{
// 테스트용: T 누르면 테이블로 이동 후 앉기
if (Keyboard.current != null && Keyboard.current[testStartKey].wasPressedThisFrame)
{
StartWalking();
}
// 테스트용: Y 누르면 일어나기
if (Keyboard.current != null && Keyboard.current[testStandUpKey].wasPressedThisFrame)
{
StandUp();
}
if (!isMoving || agent == null)
if (!isMoving || agent == null || !agent.enabled)
{
return;
}
@@ -102,6 +122,12 @@ void Update()
public void StartWalking()
{
if (blockWalkingAfterStandUp && hasStoodUpAfterMatch)
{
Debug.Log("Hook already stood up after match. StartWalking ignored.");
return;
}
if (agent == null)
{
Debug.LogWarning("NavMeshAgent is missing.");
@@ -116,23 +142,28 @@ public void StartWalking()
if (isMoving || isSitting || isStandingUp)
{
Debug.Log("Hook cannot start walking now.");
return;
}
step = 0;
hasArrived = false;
isMoving = true;
EnableHookColliders();
if (animator != null)
{
animator.applyRootMotion = false;
animator.ResetTrigger(sitTriggerName);
animator.ResetTrigger(standTriggerName);
animator.SetBool(walkBoolName, true);
}
agent.enabled = true;
if (!agent.enabled)
{
agent.enabled = true;
}
agent.isStopped = false;
MoveTo(tableFrontPoint);
@@ -140,11 +171,18 @@ public void StartWalking()
Debug.Log("Hook starts walking to table front point.");
}
void MoveTo(Transform target)
private void MoveTo(Transform target)
{
if (target == null)
{
Debug.LogWarning("Move target is null.");
StopWalking();
return;
}
NavMeshHit hit;
if (NavMesh.SamplePosition(target.position, out hit, 1.5f, NavMesh.AllAreas))
if (NavMesh.SamplePosition(target.position, out hit, navMeshSampleDistance, NavMesh.AllAreas))
{
currentDestination = hit.position;
agent.SetDestination(currentDestination);
@@ -158,7 +196,7 @@ void MoveTo(Transform target)
}
}
void GoNextStep()
private void GoNextStep()
{
step++;
@@ -173,44 +211,41 @@ void GoNextStep()
}
}
void ArriveAndSit()
private void ArriveAndSit()
{
isMoving = false;
hasArrived = true;
isSitting = true;
isStandingUp = false;
// 1. 이동 중지
if (agent != null)
if (agent != null && agent.enabled)
{
agent.isStopped = true;
agent.ResetPath();
agent.enabled = false;
}
// 2. 앉아 있는 동안 후크 콜라이더 끄기
if (disableCollidersWhenSitting)
{
DisableHookColliders();
}
// 3. 실제 앉을 위치로 강제 이동
if (sitPoint != null)
{
transform.position = sitPoint.position;
transform.rotation = sitPoint.rotation;
transform.SetPositionAndRotation(sitPoint.position, sitPoint.rotation);
}
else if (chairFrontPoint != null)
{
transform.rotation = chairFrontPoint.rotation;
}
// 4. 앉는 애니메이션 실행
if (animator != null)
{
animator.applyRootMotion = false;
animator.SetBool(walkBoolName, false);
animator.ResetTrigger(standTriggerName);
animator.ResetTrigger(sitTriggerName);
Debug.Log("Sit trigger call: " + sitTriggerName);
animator.SetTrigger(sitTriggerName);
}
@@ -219,31 +254,61 @@ void ArriveAndSit()
public void StandUp()
{
if (!isSitting || isStandingUp)
if (isStandingUp)
{
Debug.Log("Hook is already standing up.");
return;
}
if (!isSitting)
{
Debug.LogWarning("Hook is not sitting. StandUp ignored.");
return;
}
StartCoroutine(StandUpRoutine());
}
IEnumerator StandUpRoutine()
private IEnumerator StandUpRoutine()
{
isStandingUp = true;
isSitting = false;
isMoving = false;
if (agent != null && agent.enabled)
{
agent.isStopped = true;
agent.ResetPath();
agent.enabled = false;
}
if (animator != null)
{
animator.applyRootMotion = false;
animator.SetBool(walkBoolName, false);
animator.ResetTrigger(sitTriggerName);
animator.ResetTrigger(standTriggerName);
Debug.Log("Stand trigger call: " + standTriggerName);
animator.SetTrigger(standTriggerName);
if (forcePlayStandState && !string.IsNullOrEmpty(standStateName))
{
animator.CrossFadeInFixedTime(standStateName, 0.08f, 0);
Debug.Log("Force play stand state: " + standStateName);
}
}
Debug.Log("Hook started stand up animation.");
yield return new WaitForSeconds(standUpDuration);
if (standPoint != null)
{
transform.SetPositionAndRotation(standPoint.position, standPoint.rotation);
}
if (enableCollidersAfterStandUp)
{
EnableHookColliders();
@@ -251,18 +316,51 @@ IEnumerator StandUpRoutine()
if (agent != null)
{
agent.enabled = true;
agent.isStopped = true;
agent.ResetPath();
if (disableAgentAfterStandUp)
{
agent.enabled = false;
}
else
{
if (!agent.enabled)
{
agent.enabled = true;
}
agent.isStopped = true;
agent.ResetPath();
}
}
hasArrived = false;
hasStoodUpAfterMatch = true;
isStandingUp = false;
Debug.Log("Hook stood up.");
}
void DisableHookColliders()
public void ResetHookAfterMatchBlock()
{
hasStoodUpAfterMatch = false;
Debug.Log("Hook StartWalking block reset.");
}
private void StopWalking()
{
isMoving = false;
if (agent != null && agent.enabled)
{
agent.isStopped = true;
agent.ResetPath();
}
if (animator != null)
{
animator.SetBool(walkBoolName, false);
}
}
private void DisableHookColliders()
{
if (hookColliders == null || hookColliders.Length == 0)
{
@@ -278,7 +376,7 @@ void DisableHookColliders()
}
}
void EnableHookColliders()
private void EnableHookColliders()
{
if (hookColliders == null || hookColliders.Length == 0)
{
@@ -293,20 +391,4 @@ void EnableHookColliders()
}
}
}
void StopWalking()
{
isMoving = false;
if (agent != null && agent.enabled)
{
agent.isStopped = true;
agent.ResetPath();
}
if (animator != null)
{
animator.SetBool(walkBoolName, false);
}
}
}

View File

@@ -94,16 +94,39 @@ public void SetZoneActive(DialogRegion zone, bool active)
public void SetClearDialogParameter()
{
string sceneName1 = "블랙잭";
string sceneCode1 = "blackjack";
string sceneName2 = "캣룸";
string sceneCode2 = "CatsRoom";
//DialogVariables.Set("SpaceSceneName1", RandomSceneRouteManager.Instance.GetNextSceneName1());
//DialogVariables.Set("SpaceSceneCode1", RandomSceneRouteManager.Instance.GetNextSceneCode1());
//DialogVariables.Set("SpaceSceneName2", RandomSceneRouteManager.Instance.GetNextSceneName2());
//DialogVariables.Set("SpaceSceneCode2", RandomSceneRouteManager.Instance.GetNextSceneCode2());
if (RandomSceneRouteManager.Instance != null)
{
RandomSceneRouteManager.Instance.PrepareNextSceneChoices();
//테스트용
DialogVariables.Set("SpaceSceneName1", "블랙잭");
DialogVariables.Set("SpaceSceneCode1", "blackjack");
DialogVariables.Set("SpaceSceneName2", "미로방");
DialogVariables.Set("SpaceSceneCode2", "MazeRoom");
sceneName1 = RandomSceneRouteManager.Instance.GetNextSceneName1();
sceneCode1 = RandomSceneRouteManager.Instance.GetNextSceneCode1();
sceneName2 = RandomSceneRouteManager.Instance.GetNextSceneName2();
sceneCode2 = RandomSceneRouteManager.Instance.GetNextSceneCode2();
}
else
{
Debug.LogWarning("RandomSceneRouteManager가 없어서 테스트용 선택지를 사용합니다.");
}
DialogVariables.Set("SpaceSceneName1", sceneName1);
DialogVariables.Set("SpaceSceneCode1", sceneCode1);
DialogVariables.Set("SpaceSceneName2", sceneName2);
DialogVariables.Set("SpaceSceneCode2", sceneCode2);
if (_clearGate != null)
{
_clearGate.SetDoorChoices(sceneCode1, sceneCode2);
}
else
{
Debug.LogWarning("GameClear에 RoomClearGateController가 연결되지 않았습니다.");
}
Debug.Log($"선택지 세팅 완료: {sceneName1}/{sceneCode1}, {sceneName2}/{sceneCode2}");
}
}

View File

@@ -1,55 +0,0 @@
using UnityEngine;
public class GateOpenZone : MonoBehaviour
{
[Header("게이트 오픈 관리자")]
[SerializeField] private RoomClearGateController roomClearGateController;
[Header("Player Check")]
[SerializeField] private string playerTag = "Player";
private bool used = false;
private void OnTriggerEnter(Collider other)
{
if (used)
{
return;
}
if (!IsPlayer(other))
{
return;
}
if (roomClearGateController == null)
{
Debug.LogWarning("RoomClearGateController가 연결되지 않았습니다.");
return;
}
if (!roomClearGateController.IsRoomCleared)
{
Debug.Log("아직 방 클리어 전입니다. 게이트를 열지 않습니다.");
return;
}
used = true;
roomClearGateController.OpenClearGate();
}
private bool IsPlayer(Collider other)
{
if (other.CompareTag(playerTag))
{
return true;
}
if (other.transform.root.CompareTag(playerTag))
{
return true;
}
return false;
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 6986d649e7cfba74881058e544e2f727

View File

@@ -15,6 +15,11 @@ public class RandomSceneRouteManager : MonoBehaviour
private readonly HashSet<string> visitedScenes = new HashSet<string>();
private bool finalSceneUsed = false;
private string nextSceneCode1 = "";
private string nextSceneCode2 = "";
private string nextSceneName1 = "";
private string nextSceneName2 = "";
private void Awake()
{
if (Instance == null)
@@ -28,10 +33,9 @@ private void Awake()
}
}
public string GetNextSceneName()
public void PrepareNextSceneChoices()
{
string currentSceneName = SceneManager.GetActiveScene().name;
Debug.Log("현재 씬 이름: " + currentSceneName);
if (IsRoomScene(currentSceneName))
@@ -63,28 +67,131 @@ public string GetNextSceneName()
candidates.Add(cleanSceneName);
}
if (candidates.Count > 0)
Shuffle(candidates);
nextSceneCode1 = "";
nextSceneCode2 = "";
nextSceneName1 = "";
nextSceneName2 = "";
if (candidates.Count >= 1)
{
int randomIndex = Random.Range(0, candidates.Count);
string selectedSceneName = candidates[randomIndex];
visitedScenes.Add(selectedSceneName);
Debug.Log("랜덤으로 선택된 다음 씬: " + selectedSceneName);
return selectedSceneName;
nextSceneCode1 = candidates[0];
nextSceneName1 = GetDisplayName(nextSceneCode1);
}
if (!finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
if (candidates.Count >= 2)
{
nextSceneCode2 = candidates[1];
nextSceneName2 = GetDisplayName(nextSceneCode2);
}
else if (candidates.Count == 1 && !finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
{
nextSceneCode2 = finalSceneName.Trim();
nextSceneName2 = GetDisplayName(nextSceneCode2);
}
if (candidates.Count == 0)
{
if (!finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
{
nextSceneCode1 = finalSceneName.Trim();
nextSceneName1 = GetDisplayName(nextSceneCode1);
}
else
{
Debug.LogWarning("이동 가능한 다음 씬이 없습니다.");
}
}
Debug.Log("선택지 1: " + nextSceneName1 + " / " + nextSceneCode1);
Debug.Log("선택지 2: " + nextSceneName2 + " / " + nextSceneCode2);
}
public string GetNextSceneName1()
{
return nextSceneName1;
}
public string GetNextSceneCode1()
{
return nextSceneCode1;
}
public string GetNextSceneName2()
{
return nextSceneName2;
}
public string GetNextSceneCode2()
{
return nextSceneCode2;
}
public string GetNextSceneName()
{
PrepareNextSceneChoices();
if (!string.IsNullOrEmpty(nextSceneCode1))
{
return nextSceneCode1;
}
return string.Empty;
}
public void MarkSceneVisited(string sceneName)
{
if (string.IsNullOrWhiteSpace(sceneName))
{
return;
}
string cleanSceneName = sceneName.Trim();
if (cleanSceneName == finalSceneName)
{
finalSceneUsed = true;
string cleanFinalSceneName = finalSceneName.Trim();
Debug.Log("모든 방 방문 완료. 마지막 씬으로 이동: " + cleanFinalSceneName);
return cleanFinalSceneName;
}
Debug.LogWarning("이동 가능한 다음 씬이 없습니다.");
return string.Empty;
if (IsRoomScene(cleanSceneName))
{
visitedScenes.Add(cleanSceneName);
}
Debug.Log("방문 처리된 씬: " + cleanSceneName);
}
private void Shuffle(List<string> list)
{
for (int i = 0; i < list.Count; i++)
{
int randomIndex = Random.Range(i, list.Count);
string temp = list[i];
list[i] = list[randomIndex];
list[randomIndex] = temp;
}
}
private string GetDisplayName(string sceneName)
{
switch (sceneName)
{
case "blackjack":
return "블랙잭";
case "CatsRoom":
return "캣룸";
case "MazeRoom":
return "미로방";
case "Cave_Test_2":
return "동굴방";
default:
return sceneName;
}
}
private bool IsRoomScene(string sceneName)
@@ -129,6 +236,12 @@ public void ResetRoute()
{
visitedScenes.Clear();
finalSceneUsed = false;
nextSceneCode1 = "";
nextSceneCode2 = "";
nextSceneName1 = "";
nextSceneName2 = "";
Debug.Log("랜덤 방 방문 기록 초기화");
}
}

View File

@@ -2,28 +2,86 @@
public class RoomClearGateController : MonoBehaviour
{
[Header("<EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ")]
[Header("룸 클리어 후 열릴 게이트")]
[SerializeField] private RoomExitGate exitGate;
[Header("Option")]
[SerializeField] private bool requireRoomClearedBeforeOpen = true;
private bool isRoomCleared = false;
private bool gateOpened = false;
public bool IsRoomCleared => isRoomCleared;
private string selectedSceneCode = "";
// 랜덤 선택지 1, 2에 들어갈 씬 코드
private string choiceSceneCode1 = "";
private string choiceSceneCode2 = "";
public bool IsRoomCleared => isRoomCleared;
public string SelectedSceneCode => selectedSceneCode;
public bool HasSelectedScene => !string.IsNullOrEmpty(selectedSceneCode);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>¸<EFBFBD> <20><> ȣ<><C8A3>
// <20><> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20>ٷ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʰ<EFBFBD>, "<22><> Ŭ<><C5AC><EFBFBD><EFBFBD> <20>Ϸ<EFBFBD>" <20><><EFBFBD>¸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void MarkRoomCleared()
{
isRoomCleared = true;
Debug.Log("<EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD> <20>Ϸ<EFBFBD>. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EEB0A1> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.");
Debug.Log("방 클리어 완료. 이제 선택지에서 다음 방을 고를 수 있습니다.");
}
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EEB0AC> <20><> ȣ<><C8A3>
// GameClear에서 랜덤으로 뽑은 선택지 코드를 여기에 저장
public void SetDoorChoices(string code1, string code2)
{
choiceSceneCode1 = code1;
choiceSceneCode2 = code2;
Debug.Log("문 선택지 1 코드: " + choiceSceneCode1);
Debug.Log("문 선택지 2 코드: " + choiceSceneCode2);
}
// 대화 선택지 1번에서 호출
public void OpenDoorChoice1()
{
OpenDoor(choiceSceneCode1);
}
// 대화 선택지 2번에서 호출
public void OpenDoorChoice2()
{
OpenDoor(choiceSceneCode2);
}
// 실제 문 열기
public void OpenDoor(string code)
{
if (string.IsNullOrEmpty(code))
{
Debug.LogWarning("선택된 씬 코드가 비어있습니다.");
return;
}
selectedSceneCode = code;
Debug.Log("선택된 다음 씬 코드: " + selectedSceneCode);
if (exitGate != null)
{
exitGate.SetNextSceneName(selectedSceneCode);
}
OpenClearGate();
}
// 문 열기 실행
public void OpenClearGate()
{
if (!isRoomCleared)
if (requireRoomClearedBeforeOpen && !isRoomCleared)
{
Debug.Log("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD>̶<EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.");
Debug.Log("아직 방 클리어 전이라 게이트를 열 수 없습니다.");
return;
}
if (!HasSelectedScene)
{
Debug.Log("아직 다음 방을 선택하지 않아서 게이트를 열지 않습니다.");
return;
}
@@ -37,11 +95,11 @@ public void OpenClearGate()
if (exitGate != null)
{
exitGate.OpenGate();
Debug.Log("<EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD>");
Debug.Log("클리어 게이트 열림. 선택된 다음 씬: " + selectedSceneCode);
}
else
{
Debug.LogWarning("Exit Gate<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>.");
Debug.LogWarning("Exit Gate가 연결되지 않았습니다.");
}
}
@@ -49,11 +107,8 @@ public void ResetClearState()
{
isRoomCleared = false;
gateOpened = false;
selectedSceneCode = "";
choiceSceneCode1 = "";
choiceSceneCode2 = "";
}
public void OpenDoor(string code)
{
Debug.Log($"다음씬코드 : {code}");
}
}

View File

@@ -34,10 +34,13 @@ public class RoomExitGate : MonoBehaviour
[SerializeField] private string playerTag = "Player";
[Header("Scene Move")]
[SerializeField] private bool useRandomScene = true;
[SerializeField] private bool useRandomScene = false;
[SerializeField] private string fallbackSceneName;
[SerializeField] private float sceneMoveDelay = 0.2f;
[Header("Selected Scene")]
[SerializeField] private string selectedSceneName;
[Header("Start Setting")]
[SerializeField] private bool hideGateOnStart = true;
[SerializeField] private bool hidePortalOnStart = true;
@@ -114,6 +117,12 @@ private void PrepareStartState()
}
}
public void SetNextSceneName(string sceneName)
{
selectedSceneName = sceneName;
Debug.Log("게이트 다음 씬 설정: " + selectedSceneName);
}
public void OpenGate()
{
if (isOpened || isOpening)
@@ -277,6 +286,11 @@ private IEnumerator EnterGateRoutine()
private string GetNextSceneName()
{
if (!string.IsNullOrEmpty(selectedSceneName))
{
return selectedSceneName;
}
if (useRandomScene && RandomSceneRouteManager.Instance != null)
{
return RandomSceneRouteManager.Instance.GetNextSceneName();
@@ -322,5 +336,7 @@ public void CloseGateImmediately()
{
gateVisualRoot.SetActive(false);
}
selectedSceneName = "";
}
}