게임클리어 이벤트
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user