게임클리어 이벤트
This commit is contained in:
107
Assets/02_Scripts/Managers/GameClear.cs
Normal file
107
Assets/02_Scripts/Managers/GameClear.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
// 게임 클리어 시 처리:
|
||||
// - NPC(오브젝트)들을 지정 위치로 재배치
|
||||
// - 대화 존(DialogRegion)들을 활성/비활성 전환
|
||||
// 리듬게임의 On Cleared 같은 UnityEvent에 OnGameClear()를 연결하면 한 번에 처리된다.
|
||||
public class GameClear : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RoomClearGateController _clearGate;
|
||||
|
||||
// 옮길 오브젝트 ↔ 목적지(빈 Transform) 한 쌍
|
||||
[System.Serializable]
|
||||
public struct Relocation
|
||||
{
|
||||
public GameObject Target; // 옮길 오브젝트 (NPC 등)
|
||||
public Transform Destination; // 옮길 위치/회전 기준
|
||||
}
|
||||
|
||||
// 클리어 시 적용할 존 상태 한 쌍
|
||||
[System.Serializable]
|
||||
public struct ZoneState
|
||||
{
|
||||
public DialogRegion Zone; // 대상 존
|
||||
public bool Active; // 이 상태로 전환
|
||||
}
|
||||
|
||||
[Header("NPC 재배치")]
|
||||
[SerializeField] private List<Relocation> _relocations = new();
|
||||
|
||||
[Header("대화 존 상태")]
|
||||
[SerializeField] private List<ZoneState> _zoneStates = new();
|
||||
|
||||
// ── 클리어 시 한 번에 (UnityEvent 연결용) ─────────────────────
|
||||
public void OnGameClear()
|
||||
{
|
||||
if(_clearGate != null)
|
||||
{
|
||||
//_clearGate.OpenClearGate();
|
||||
_clearGate.MarkRoomCleared();
|
||||
}
|
||||
|
||||
Relocate();
|
||||
ApplyZoneStates();
|
||||
|
||||
SetClearDialogParameter();
|
||||
}
|
||||
|
||||
// ── NPC 재배치 ───────────────────────────────────────────────
|
||||
// 리스트의 각 오브젝트를 지정 위치(위치+회전)로 이동.
|
||||
public void Relocate()
|
||||
{
|
||||
foreach (var r in _relocations)
|
||||
Relocate(r.Target, r.Destination);
|
||||
}
|
||||
|
||||
// 단일 오브젝트 재배치. NavMeshAgent가 있으면 Warp로 옮겨야 경로/내부상태가 안 깨진다.
|
||||
public void Relocate(GameObject target, Transform destination)
|
||||
{
|
||||
if (target == null || destination == null) return;
|
||||
|
||||
// 따라다니던 중이면 멈춰서 재배치 위치에 머물게 (다시 플레이어를 향해 가지 않도록)
|
||||
if (target.TryGetComponent(out FollowObject follow) && follow.FollowEnabled)
|
||||
follow.DisableFollow();
|
||||
|
||||
if (target.TryGetComponent(out NavMeshAgent agent) && agent.isOnNavMesh)
|
||||
{
|
||||
agent.Warp(destination.position);
|
||||
target.transform.rotation = destination.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.transform.SetPositionAndRotation(destination.position, destination.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 대화 존 활성/비활성 ──────────────────────────────────────
|
||||
// 인스펙터에 설정한 _zoneStates를 한 번에 적용.
|
||||
public void ApplyZoneStates()
|
||||
{
|
||||
foreach (var z in _zoneStates)
|
||||
SetZoneActive(z.Zone, z.Active);
|
||||
}
|
||||
|
||||
// 특정 존을 활성/비활성 (존 오브젝트째로 토글 → 트리거도 같이 꺼짐).
|
||||
public void SetZoneActive(DialogRegion zone, bool active)
|
||||
{
|
||||
if (zone != null)
|
||||
zone.gameObject.SetActive(active);
|
||||
}
|
||||
|
||||
public void SetClearDialogParameter()
|
||||
{
|
||||
|
||||
//DialogVariables.Set("SpaceSceneName1", RandomSceneRouteManager.Instance.GetNextSceneName1());
|
||||
//DialogVariables.Set("SpaceSceneCode1", RandomSceneRouteManager.Instance.GetNextSceneCode1());
|
||||
//DialogVariables.Set("SpaceSceneName2", RandomSceneRouteManager.Instance.GetNextSceneName2());
|
||||
//DialogVariables.Set("SpaceSceneCode2", RandomSceneRouteManager.Instance.GetNextSceneCode2());
|
||||
|
||||
//테스트용
|
||||
DialogVariables.Set("SpaceSceneName1", "블랙잭");
|
||||
DialogVariables.Set("SpaceSceneCode1", "blackjack");
|
||||
DialogVariables.Set("SpaceSceneName2", "미로방");
|
||||
DialogVariables.Set("SpaceSceneCode2", "MazeRoom");
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/GameClear.cs.meta
Normal file
2
Assets/02_Scripts/Managers/GameClear.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22b271cf4093f3e458ae92b4a993272b
|
||||
@@ -12,6 +12,7 @@ public class InputManager : MonoBehaviour, GameInput.IPlayerActions
|
||||
// ─── 입력 이벤트들 (PlayerController 등이 구독) ──────────────────────
|
||||
public event Action OnJump_Event; // 한 번씩 (눌렀을 때)
|
||||
public event Action OnInteract_Event; // 상호작용 키 (앉기 등) — 눌렀을 때 한 번씩
|
||||
public event Action OnDialogNext_Event; // 대화 다음 진행 (VR B버튼) — 눌렀을 때 한 번씩
|
||||
|
||||
//키보드로 테스트용
|
||||
public event Action OnKey_Left_Event;
|
||||
@@ -51,6 +52,12 @@ public void OnInteract(InputAction.CallbackContext ctx)
|
||||
OnInteract_Event?.Invoke();
|
||||
}
|
||||
|
||||
public void OnDialogNext(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if (ctx.phase == InputActionPhase.Started)
|
||||
OnDialogNext_Event?.Invoke();
|
||||
}
|
||||
|
||||
public void OnKey_Left(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if (ctx.phase == InputActionPhase.Started)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public class RoomClearGateController : MonoBehaviour
|
||||
{
|
||||
[Header("방 클리어 후 열릴 게이트")]
|
||||
[Header("<EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ")]
|
||||
[SerializeField] private RoomExitGate exitGate;
|
||||
|
||||
private bool isRoomCleared = false;
|
||||
@@ -10,20 +10,20 @@ public class RoomClearGateController : MonoBehaviour
|
||||
|
||||
public bool IsRoomCleared => isRoomCleared;
|
||||
|
||||
// 블랙잭 최종 승리 후 호출
|
||||
// 이 함수는 게이트를 바로 열지 않고, "방 클리어 완료" 상태만 저장함
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>¸<EFBFBD> <20><> ȣ<><C8A3>
|
||||
// <EFBFBD><EFBFBD> <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("방 클리어 완료. 이제 오픈존에 들어가면 게이트가 열립니다.");
|
||||
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>.");
|
||||
}
|
||||
|
||||
// 오픈존에 들어갔을 때 호출
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EEB0AC> <20><> ȣ<><C8A3>
|
||||
public void OpenClearGate()
|
||||
{
|
||||
if (!isRoomCleared)
|
||||
{
|
||||
Debug.Log("아직 방 클리어 전이라 게이트를 열 수 없습니다.");
|
||||
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>.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ public void OpenClearGate()
|
||||
if (exitGate != null)
|
||||
{
|
||||
exitGate.OpenGate();
|
||||
Debug.Log("방 클리어 게이트 오픈");
|
||||
Debug.Log("<EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD>");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Exit Gate가 연결되지 않았습니다.");
|
||||
Debug.LogWarning("Exit Gate<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,10 @@ public void ResetClearState()
|
||||
isRoomCleared = false;
|
||||
gateOpened = false;
|
||||
}
|
||||
|
||||
public void OpenDoor(string code)
|
||||
{
|
||||
Debug.Log($"다음씬코드 : {code}");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user