207 lines
5.9 KiB
C#
207 lines
5.9 KiB
C#
using UnityEngine;
|
|
|
|
public class RaftRideEndHandler : MonoBehaviour
|
|
{
|
|
[Header("Player")]
|
|
[SerializeField] private Transform xrOrigin;
|
|
|
|
[Tooltip("도착 후 XR Origin을 뗏목에서 분리할지 여부")]
|
|
[SerializeField] private bool detachPlayerFromRaft = true;
|
|
|
|
[Header("Exit / Land")]
|
|
[SerializeField] private Transform exitPoint;
|
|
|
|
[Tooltip("도착 후 켤 육지 이동 구역, 안내 오브젝트, 길 표시 등")]
|
|
[SerializeField] private GameObject landAreaObject;
|
|
|
|
[Header("Next Mission")]
|
|
[Tooltip("도착 후 활성화할 조개 미션 오브젝트")]
|
|
[SerializeField] private GameObject clamMissionObject;
|
|
|
|
[Tooltip("기억의 조각 획득 후 켤 다음 문 오브젝트")]
|
|
[SerializeField] private GameObject nextDoorObject;
|
|
|
|
[Header("Clam Bite Mission")]
|
|
[Tooltip("도착 후 조개 물림 판정을 시작할지 여부")]
|
|
[SerializeField] private bool startClamBiteMissionOnArrive = true;
|
|
|
|
[Tooltip("직접 연결할 조개 물림 판정 스크립트들입니다. 비워두면 Clam Mission Object 아래에서 자동 탐색합니다.")]
|
|
[SerializeField] private ClamBiteDetector[] clamBiteDetectors;
|
|
|
|
[Header("Clear Options")]
|
|
[Tooltip("조개 미션 성공 시 조개 물림 판정을 정지합니다.")]
|
|
[SerializeField] private bool stopClamBiteMissionOnClear = true;
|
|
|
|
[Tooltip("조개 미션 성공 시 조개 오브젝트를 계속 유지할지 여부입니다.")]
|
|
[SerializeField] private bool keepClamMissionObjectAfterClear = true;
|
|
|
|
[Tooltip("조개 미션 성공 시 Next Door Object를 켭니다.")]
|
|
[SerializeField] private bool activateNextDoorOnClear = true;
|
|
|
|
[Header("Debug")]
|
|
[SerializeField] private bool showDebugLog = true;
|
|
|
|
private bool hasArrived;
|
|
private bool clamMissionCleared;
|
|
|
|
public void OnRaftArrived()
|
|
{
|
|
if (hasArrived)
|
|
return;
|
|
|
|
hasArrived = true;
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] 뗏목 도착 처리 시작.");
|
|
|
|
if (detachPlayerFromRaft && xrOrigin != null)
|
|
{
|
|
xrOrigin.SetParent(null);
|
|
}
|
|
|
|
if (exitPoint != null && xrOrigin != null)
|
|
{
|
|
// 현재는 강제 이동하지 않음.
|
|
// 필요하면 아래 두 줄을 활성화.
|
|
// xrOrigin.position = exitPoint.position;
|
|
// xrOrigin.rotation = exitPoint.rotation;
|
|
}
|
|
|
|
if (landAreaObject != null)
|
|
{
|
|
landAreaObject.SetActive(true);
|
|
}
|
|
|
|
if (clamMissionObject != null)
|
|
{
|
|
clamMissionObject.SetActive(true);
|
|
}
|
|
|
|
if (nextDoorObject != null)
|
|
{
|
|
nextDoorObject.SetActive(false);
|
|
}
|
|
|
|
if (startClamBiteMissionOnArrive)
|
|
{
|
|
StartClamBiteMission();
|
|
}
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] 도착 처리 완료. 육지/조개 미션 진행 가능.");
|
|
}
|
|
|
|
public void OnClamMissionCleared()
|
|
{
|
|
if (clamMissionCleared)
|
|
return;
|
|
|
|
clamMissionCleared = true;
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] 조개 미션 클리어. 다음 문을 엽니다.");
|
|
|
|
if (stopClamBiteMissionOnClear)
|
|
{
|
|
StopClamBiteMission();
|
|
}
|
|
|
|
if (clamMissionObject != null && !keepClamMissionObjectAfterClear)
|
|
{
|
|
clamMissionObject.SetActive(false);
|
|
}
|
|
|
|
if (activateNextDoorOnClear && nextDoorObject != null)
|
|
{
|
|
nextDoorObject.SetActive(true);
|
|
}
|
|
else if (activateNextDoorOnClear && nextDoorObject == null)
|
|
{
|
|
Debug.LogWarning("[RaftRideEndHandler] Next Door Object가 연결되지 않았습니다.", this);
|
|
}
|
|
}
|
|
|
|
public void OpenNextDoor()
|
|
{
|
|
if (nextDoorObject == null)
|
|
{
|
|
Debug.LogWarning("[RaftRideEndHandler] Next Door Object가 연결되지 않았습니다.", this);
|
|
return;
|
|
}
|
|
|
|
nextDoorObject.SetActive(true);
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] Next Door Object 활성화.");
|
|
}
|
|
|
|
public void CloseNextDoor()
|
|
{
|
|
if (nextDoorObject == null)
|
|
return;
|
|
|
|
nextDoorObject.SetActive(false);
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] Next Door Object 비활성화.");
|
|
}
|
|
|
|
private void StartClamBiteMission()
|
|
{
|
|
ResolveClamBiteDetectors();
|
|
|
|
if (clamBiteDetectors == null || clamBiteDetectors.Length == 0)
|
|
{
|
|
if (showDebugLog)
|
|
Debug.LogWarning("[RaftRideEndHandler] ClamBiteDetector를 찾지 못했습니다.", this);
|
|
|
|
return;
|
|
}
|
|
|
|
foreach (ClamBiteDetector detector in clamBiteDetectors)
|
|
{
|
|
if (detector == null)
|
|
continue;
|
|
|
|
detector.StartBiteMission();
|
|
}
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] 조개 물림 미션 시작.");
|
|
}
|
|
|
|
private void StopClamBiteMission()
|
|
{
|
|
ResolveClamBiteDetectors();
|
|
|
|
if (clamBiteDetectors == null || clamBiteDetectors.Length == 0)
|
|
return;
|
|
|
|
foreach (ClamBiteDetector detector in clamBiteDetectors)
|
|
{
|
|
if (detector == null)
|
|
continue;
|
|
|
|
detector.StopBiteMission();
|
|
}
|
|
|
|
if (showDebugLog)
|
|
Debug.Log("[RaftRideEndHandler] 조개 물림 미션 정지.");
|
|
}
|
|
|
|
private void ResolveClamBiteDetectors()
|
|
{
|
|
if (clamBiteDetectors != null && clamBiteDetectors.Length > 0)
|
|
return;
|
|
|
|
if (clamMissionObject != null)
|
|
{
|
|
clamBiteDetectors = clamMissionObject.GetComponentsInChildren<ClamBiteDetector>(true);
|
|
}
|
|
|
|
if (clamBiteDetectors == null || clamBiteDetectors.Length == 0)
|
|
{
|
|
clamBiteDetectors = FindObjectsByType<ClamBiteDetector>(FindObjectsSortMode.None);
|
|
}
|
|
}
|
|
} |