게이트 이동 시스템 추가 및 기존 이동 매니저 정리

This commit is contained in:
dldydtn9755-crypto
2026-06-22 11:28:53 +09:00
parent f443c4a4de
commit 6fc20431e8
57 changed files with 767 additions and 435 deletions

View File

@@ -0,0 +1,55 @@
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

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

View File

@@ -0,0 +1,134 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RandomSceneRouteManager : MonoBehaviour
{
public static RandomSceneRouteManager Instance;
[Header("랜덤으로 이동할 방 Scene 이름들")]
[SerializeField] private string[] roomSceneNames;
[Header("모든 방 방문 후 이동할 마지막 Scene 이름")]
[SerializeField] private string finalSceneName;
private readonly HashSet<string> visitedScenes = new HashSet<string>();
private bool finalSceneUsed = false;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public string GetNextSceneName()
{
string currentSceneName = SceneManager.GetActiveScene().name;
Debug.Log("현재 씬 이름: " + currentSceneName);
if (IsRoomScene(currentSceneName))
{
visitedScenes.Add(currentSceneName);
}
List<string> candidates = new List<string>();
foreach (string sceneName in roomSceneNames)
{
if (string.IsNullOrWhiteSpace(sceneName))
{
continue;
}
string cleanSceneName = sceneName.Trim();
if (cleanSceneName == currentSceneName)
{
continue;
}
if (visitedScenes.Contains(cleanSceneName))
{
continue;
}
candidates.Add(cleanSceneName);
}
if (candidates.Count > 0)
{
int randomIndex = Random.Range(0, candidates.Count);
string selectedSceneName = candidates[randomIndex];
visitedScenes.Add(selectedSceneName);
Debug.Log("랜덤으로 선택된 다음 씬: " + selectedSceneName);
return selectedSceneName;
}
if (!finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
{
finalSceneUsed = true;
string cleanFinalSceneName = finalSceneName.Trim();
Debug.Log("모든 방 방문 완료. 마지막 씬으로 이동: " + cleanFinalSceneName);
return cleanFinalSceneName;
}
Debug.LogWarning("이동 가능한 다음 씬이 없습니다.");
return string.Empty;
}
private bool IsRoomScene(string sceneName)
{
foreach (string roomSceneName in roomSceneNames)
{
if (string.IsNullOrWhiteSpace(roomSceneName))
{
continue;
}
if (roomSceneName.Trim() == sceneName)
{
return true;
}
}
return false;
}
public void RequestRandomSceneChange()
{
if (SceneLoadManager.Instance == null)
{
Debug.LogError("SceneLoadManager가 없습니다.");
return;
}
string nextSceneName = GetNextSceneName();
if (string.IsNullOrEmpty(nextSceneName))
{
Debug.LogWarning("이동할 다음 씬 이름이 비어있습니다.");
return;
}
Debug.Log("랜덤 씬 이동 요청: " + nextSceneName);
SceneLoadManager.Instance.RequestSceneChange(nextSceneName);
}
public void ResetRoute()
{
visitedScenes.Clear();
finalSceneUsed = false;
Debug.Log("랜덤 방 방문 기록 초기화");
}
}

View File

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

View File

@@ -0,0 +1,53 @@
using UnityEngine;
public class RoomClearGateController : MonoBehaviour
{
[Header("방 클리어 후 열릴 게이트")]
[SerializeField] private RoomExitGate exitGate;
private bool isRoomCleared = false;
private bool gateOpened = false;
public bool IsRoomCleared => isRoomCleared;
// 블랙잭 최종 승리 후 호출
// 이 함수는 게이트를 바로 열지 않고, "방 클리어 완료" 상태만 저장함
public void MarkRoomCleared()
{
isRoomCleared = true;
Debug.Log("방 클리어 완료. 이제 오픈존에 들어가면 게이트가 열립니다.");
}
// 오픈존에 들어갔을 때 호출
public void OpenClearGate()
{
if (!isRoomCleared)
{
Debug.Log("아직 방 클리어 전이라 게이트를 열 수 없습니다.");
return;
}
if (gateOpened)
{
return;
}
gateOpened = true;
if (exitGate != null)
{
exitGate.OpenGate();
Debug.Log("방 클리어 게이트 오픈");
}
else
{
Debug.LogWarning("Exit Gate가 연결되지 않았습니다.");
}
}
public void ResetClearState()
{
isRoomCleared = false;
gateOpened = false;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 125cade625c9b644b842b1a4f20527e4

View File

@@ -0,0 +1,326 @@
using System.Collections;
using UnityEngine;
public class RoomExitGate : MonoBehaviour
{
[Header("Gate Root")]
[SerializeField] private GameObject gateVisualRoot;
[Header("Door")]
[SerializeField] private Transform leftDoor;
[SerializeField] private Transform rightDoor;
[Header("Door Open Angle")]
[SerializeField] private float leftOpenAngleY = 110f;
[SerializeField] private float rightOpenAngleY = -110f;
[Header("Portal")]
[SerializeField] private GameObject portalEffectRoot;
[SerializeField] private ParticleSystem[] portalParticles;
[Header("Open Effect")]
[SerializeField] private ParticleSystem openParticle;
[SerializeField] private AudioSource openSound;
[Header("Trigger")]
[SerializeField] private Collider gateTrigger;
[Header("Timing")]
[SerializeField] private float openDelay = 1.2f;
[SerializeField] private float openDuration = 1.2f;
[SerializeField] private float portalShowDelay = 0.3f;
[Header("Player Check")]
[SerializeField] private string playerTag = "Player";
[Header("Scene Move")]
[SerializeField] private bool useRandomScene = true;
[SerializeField] private string fallbackSceneName;
[SerializeField] private float sceneMoveDelay = 0.2f;
[Header("Start Setting")]
[SerializeField] private bool hideGateOnStart = true;
[SerializeField] private bool hidePortalOnStart = true;
private Quaternion leftClosedRotation;
private Quaternion rightClosedRotation;
private Quaternion leftOpenRotation;
private Quaternion rightOpenRotation;
private bool isOpened = false;
private bool isOpening = false;
private bool isEntering = false;
private void Awake()
{
CacheDoorRotations();
AutoFindPortalParticles();
PrepareTrigger();
PrepareStartState();
}
private void CacheDoorRotations()
{
if (leftDoor != null)
{
leftClosedRotation = leftDoor.localRotation;
leftOpenRotation = leftClosedRotation * Quaternion.Euler(0f, leftOpenAngleY, 0f);
}
if (rightDoor != null)
{
rightClosedRotation = rightDoor.localRotation;
rightOpenRotation = rightClosedRotation * Quaternion.Euler(0f, rightOpenAngleY, 0f);
}
}
private void AutoFindPortalParticles()
{
if ((portalParticles == null || portalParticles.Length == 0) && portalEffectRoot != null)
{
portalParticles = portalEffectRoot.GetComponentsInChildren<ParticleSystem>(true);
}
}
private void PrepareTrigger()
{
if (gateTrigger != null)
{
gateTrigger.enabled = false;
gateTrigger.isTrigger = true;
}
Rigidbody rb = GetComponent<Rigidbody>();
if (rb == null)
{
rb = gameObject.AddComponent<Rigidbody>();
}
rb.isKinematic = true;
rb.useGravity = false;
}
private void PrepareStartState()
{
if (hideGateOnStart && gateVisualRoot != null)
{
gateVisualRoot.SetActive(false);
}
if (hidePortalOnStart && portalEffectRoot != null)
{
portalEffectRoot.SetActive(false);
}
}
public void OpenGate()
{
if (isOpened || isOpening)
{
return;
}
StartCoroutine(OpenGateRoutine());
}
private IEnumerator OpenGateRoutine()
{
isOpening = true;
if (openParticle != null)
{
openParticle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
openParticle.Play();
}
if (openSound != null)
{
openSound.Play();
}
yield return new WaitForSeconds(openDelay);
if (gateVisualRoot != null)
{
gateVisualRoot.SetActive(true);
}
float timer = 0f;
bool portalShown = false;
while (timer < openDuration)
{
timer += Time.deltaTime;
float t = Mathf.Clamp01(timer / openDuration);
t = Mathf.SmoothStep(0f, 1f, t);
if (leftDoor != null)
{
leftDoor.localRotation = Quaternion.Slerp(leftClosedRotation, leftOpenRotation, t);
}
if (rightDoor != null)
{
rightDoor.localRotation = Quaternion.Slerp(rightClosedRotation, rightOpenRotation, t);
}
if (!portalShown && timer >= portalShowDelay)
{
ShowPortal();
portalShown = true;
}
yield return null;
}
if (leftDoor != null)
{
leftDoor.localRotation = leftOpenRotation;
}
if (rightDoor != null)
{
rightDoor.localRotation = rightOpenRotation;
}
ShowPortal();
if (gateTrigger != null)
{
gateTrigger.enabled = true;
}
isOpened = true;
isOpening = false;
Debug.Log("게이트 열림 완료");
}
private void ShowPortal()
{
if (portalEffectRoot != null && !portalEffectRoot.activeSelf)
{
portalEffectRoot.SetActive(true);
}
if (portalParticles == null)
{
return;
}
foreach (ParticleSystem particle in portalParticles)
{
if (particle != null && !particle.isPlaying)
{
particle.Play();
}
}
}
private void OnTriggerEnter(Collider other)
{
if (!isOpened || isEntering)
{
return;
}
if (!IsPlayer(other))
{
return;
}
StartCoroutine(EnterGateRoutine());
}
private bool IsPlayer(Collider other)
{
if (other.CompareTag(playerTag))
{
return true;
}
if (other.transform.root.CompareTag(playerTag))
{
return true;
}
return false;
}
private IEnumerator EnterGateRoutine()
{
isEntering = true;
yield return new WaitForSeconds(sceneMoveDelay);
string nextSceneName = GetNextSceneName();
if (string.IsNullOrEmpty(nextSceneName))
{
Debug.LogWarning("다음 씬 이름이 비어있습니다.");
isEntering = false;
yield break;
}
if (SceneLoadManager.Instance == null)
{
Debug.LogError("SceneLoadManager가 없습니다.");
isEntering = false;
yield break;
}
Debug.Log("게이트 진입, 이동할 씬: " + nextSceneName);
SceneLoadManager.Instance.RequestSceneChange(nextSceneName);
}
private string GetNextSceneName()
{
if (useRandomScene && RandomSceneRouteManager.Instance != null)
{
return RandomSceneRouteManager.Instance.GetNextSceneName();
}
return fallbackSceneName;
}
public void CloseGateImmediately()
{
StopAllCoroutines();
isOpened = false;
isOpening = false;
isEntering = false;
if (leftDoor != null)
{
leftDoor.localRotation = leftClosedRotation;
}
if (rightDoor != null)
{
rightDoor.localRotation = rightClosedRotation;
}
if (portalEffectRoot != null)
{
portalEffectRoot.SetActive(false);
}
if (gateTrigger != null)
{
gateTrigger.enabled = false;
}
if (openParticle != null)
{
openParticle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
}
if (hideGateOnStart && gateVisualRoot != null)
{
gateVisualRoot.SetActive(false);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 317d18e41b8485446ac641a9e1cd4ce2

View File

@@ -0,0 +1,169 @@
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoadManager : MonoBehaviour
{
public static SceneLoadManager Instance;
[SerializeField] private GameObject _loadingRoot;
[SerializeField] private Camera _loadingCam;
[SerializeField] private Transform _loadingCamTargetTransform;
private bool _isChangingScene = false;
public bool IsChangingScene => _isChangingScene;
private void Awake()
{
if (Instance == null)
{
Instance = this; // 만들어진 자신을 인스턴스로 설정
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject); // 이미 인스턴스가 있으면 자신을 파괴
}
}
private void Start()
{
SceneManager.sceneLoaded += OnSceneLoaded;
OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
}
private void OnDestroy()
{
if (Instance == this)
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
}
private void Update()
{
if (_loadingRoot != null && _loadingCamTargetTransform != null)
{
_loadingRoot.transform.position = _loadingCamTargetTransform.position;
}
}
// 씬이 로드되었을때 호출
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
MonoBehaviour[] allObjs = UnityEngine.Object.FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
foreach (var obj in allObjs)
{
if (obj is ISceneInitializable initializable)
{
// 씬에서 ISceneInitializable 인터페이스를 가진 오브젝트의 초기화 로직을 실행
initializable.OnSceneLoaded();
}
}
}
public void SetSceneLoadingProgressValue(float value)
{
// 여기에 로딩바 UI 연결 예정
}
public void RequestSceneChange(string sceneName)
{
if (_isChangingScene)
{
Debug.Log("이미 씬 전환 중입니다.");
return;
}
if (string.IsNullOrEmpty(sceneName))
{
Debug.LogWarning("이동할 씬 이름이 비어있습니다.");
return;
}
_ = SceneChange(sceneName);
}
private async Awaitable SceneChange(string sceneName)
{
try
{
_isChangingScene = true;
// 로딩바 수치 0으로 설정
SetSceneLoadingProgressValue(0f);
if (_loadingRoot != null)
{
_loadingRoot.SetActive(true);
}
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
if (op == null)
{
Debug.LogError($"씬 로드 실패: {sceneName}");
_isChangingScene = false;
return;
}
// 자동 전환을 하고 싶지 않을 경우 false로 두었다가 true로 바꾸면 그 때 전환됨
op.allowSceneActivation = false;
// 화면에 보여줄 로딩 수치
float displayProgress = 0f;
// op.progress 0.9가 데이터 로딩이 끝난 기준
while (op.progress < 0.9f)
{
// 실제 로딩 수치
float realProgress = Mathf.Clamp01(op.progress / 0.9f);
// 보여줄 값을 실제값을 향해 부드럽게 이동
displayProgress = Mathf.MoveTowards(displayProgress, realProgress, Time.deltaTime * 0.5f);
// 로딩바 UI에 값 적용
SetSceneLoadingProgressValue(displayProgress);
// 자기자신이 파괴될때 토큰에 취소요청을 보냄
await Awaitable.NextFrameAsync(this.destroyCancellationToken);
}
// 로딩바 수치 1(100%)로 설정
SetSceneLoadingProgressValue(1f);
// 잠시 대기했다가 전환
await Awaitable.WaitForSecondsAsync(1.0f, this.destroyCancellationToken);
// 다음씬으로 넘어가도 됨을 알림
op.allowSceneActivation = true;
// 씬 활성화가 완전히 끝날 때까지 대기
while (!op.isDone)
{
await Awaitable.NextFrameAsync(this.destroyCancellationToken);
}
// VR용 로직
// 트래킹이 중단되면 안되기 때문에 카메라를 유지해야 한다
if (Camera.main != null)
{
_loadingCamTargetTransform = Camera.main.transform;
}
if (_loadingRoot != null)
{
_loadingRoot.SetActive(false);
}
_isChangingScene = false;
}
catch (OperationCanceledException)
{
Debug.Log("씬 전환 작업이 취소됨");
_isChangingScene = false;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 01c67a0d5e5e96240a6b1f1c8e34e749