114 lines
2.9 KiB
C#
114 lines
2.9 KiB
C#
using UnityEngine;
|
|
|
|
public class RoomClearGateController : MonoBehaviour
|
|
{
|
|
[Header("룸 클리어 후 열릴 게이트")]
|
|
[SerializeField] private RoomExitGate exitGate;
|
|
|
|
[Header("Option")]
|
|
[SerializeField] private bool requireRoomClearedBeforeOpen = true;
|
|
|
|
private bool isRoomCleared = false;
|
|
private bool gateOpened = false;
|
|
|
|
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);
|
|
|
|
public void MarkRoomCleared()
|
|
{
|
|
isRoomCleared = true;
|
|
Debug.Log("방 클리어 완료. 이제 선택지에서 다음 방을 고를 수 있습니다.");
|
|
}
|
|
|
|
// 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 (requireRoomClearedBeforeOpen && !isRoomCleared)
|
|
{
|
|
Debug.Log("아직 방 클리어 전이라 게이트를 열 수 없습니다.");
|
|
return;
|
|
}
|
|
|
|
if (!HasSelectedScene)
|
|
{
|
|
Debug.Log("아직 다음 방을 선택하지 않아서 게이트를 열지 않습니다.");
|
|
return;
|
|
}
|
|
|
|
if (gateOpened)
|
|
{
|
|
return;
|
|
}
|
|
|
|
gateOpened = true;
|
|
|
|
if (exitGate != null)
|
|
{
|
|
exitGate.OpenGate();
|
|
Debug.Log("클리어 게이트 열림. 선택된 다음 씬: " + selectedSceneCode);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("Exit Gate가 연결되지 않았습니다.");
|
|
}
|
|
}
|
|
|
|
public void ResetClearState()
|
|
{
|
|
isRoomCleared = false;
|
|
gateOpened = false;
|
|
selectedSceneCode = "";
|
|
choiceSceneCode1 = "";
|
|
choiceSceneCode2 = "";
|
|
}
|
|
} |