diff --git a/302/Assets/Scripts/InteractionManager.cs b/302/Assets/Scripts/InteractionManager.cs index 48ae7fa..3a10bb1 100644 --- a/302/Assets/Scripts/InteractionManager.cs +++ b/302/Assets/Scripts/InteractionManager.cs @@ -21,7 +21,7 @@ public class InteractionManager : AbstractStageObserver public override string Name { get; } = "InteractionManager"; // 클래스 인스턴스 - public static PlayerManager Instance { get; private set; } + public static InteractionManager Instance { get; private set; } /************ * messages * diff --git a/302/Assets/Scripts/PauseManager.cs b/302/Assets/Scripts/PauseManager.cs new file mode 100644 index 0000000..f946437 --- /dev/null +++ b/302/Assets/Scripts/PauseManager.cs @@ -0,0 +1,152 @@ +using UnityEngine; + +public class PauseManager : AbstractStageObserver +{ + /********** + * fields * + **********/ + + // 캔버스 이름 + public string nameCanvas; + + // 종료를 위한 입력 시간 + public double timeExit; + + // 캔버스 + private Canvas _canvas; + + // 시간 + private double _timeKeyDown; + + /************** + * properties * + **************/ + + // 클래스 이름 + public override string Name { get; } = "PauseManager"; + + // 클래스 인스턴스 + public static PauseManager Instance { get; private set; } + + /************ + * messages * + ************/ + + void Update() + { + double time = Time.unscaledTimeAsDouble; + + if (Input.GetKeyDown(KeyCode.Escape)) { + _timeKeyDown = time; + } else if (Input.GetKey(KeyCode.Escape) && time - _timeKeyDown >= timeExit) { + ExitGame(); + } else if (Input.GetKeyUp(KeyCode.Escape) && time - _timeKeyDown < timeExit) { + if (GameManager.Instance.State == GameManager.GameState.Playing) { + PauseGame(); + } else if (GameManager.Instance.State == GameManager.GameState.Paused) { + ResumeGame(); + } + } + } + + /************************************* + * implementation: AbstractBehaviour * + *************************************/ + + // `Awake` 메시지 용 메서드 + protected override bool Awake_() + { + bool res = false; + + if (Instance == null) { + Log($"`Instance` has not been set => set `Instance` as `{Name}`"); + Instance = this; + DontDestroyOnLoad(gameObject); + res = base.Awake_(); + } else { + Log($"`Instance` has already been set => destroy `{gameObject.name}`"); + Destroy(gameObject); + } + + return res; + } + + // `Start` 메시지 용 메서드 + protected override bool Start_() + { + bool res = base.Start_(); + + // TODO: `Start` 메시지에서 해야할 것 넣기. 없으면 메서드를 아예 지워도 됨. + // 함수가 제대로 작동했으면 `true`를, 아니면 `false`를 반환. + + return res; + } + + // 필드를 초기화하는 메서드 + protected override bool InitFields() + { + bool res = base.InitFields(); + + // TODO: 필드 초기화할 것 넣기. 없으면 메서드를 아예 지워도 됨. + // (사실 필드 말고 초기화할 것도 넣어도 됨....) + // 함수가 제대로 작동했으면 `true`를, 아니면 `false`를 반환. + + return res; + } + + /***************************************** + * implementation: AbstractStageObserver * + *****************************************/ + + // 단계 변경 시 불리는 메서드 + public override bool UpdateStage() + { + GameObject obj = GameObject.Find(nameCanvas); + bool res = base.UpdateStage(); + + if (obj != null) { + Log($"Find `{nameCanvas}` success"); + + _canvas = obj.GetComponent(); + if (_canvas != null) { + Log("Find `Canvas` success"); + } else { + Log("Find `Canvas` failed", mode: 1); + res = false; + } + } else { + Log($"Find `{nameCanvas}` failed", mode: 1); + res = false; + } + + return res; + } + + /*************** + * new methods * + ***************/ + + private void PauseGame() + { + Log("Pause the game"); + GameManager.Instance.PauseGame(); + _canvas.gameObject.SetActive(true); + } + + private void ResumeGame() + { + Log("Resume the game"); + GameManager.Instance.ResumeGame(); + _canvas.gameObject.SetActive(false); + } + + private void ExitGame() + { + Log("Exit the game"); +#if UNITY_EDITOR + UnityEditor.EditorApplication.isPlaying = false; +#else + Application.Quit(); +#endif + } +} diff --git a/302/Assets/Scripts/PauseManager.cs.meta b/302/Assets/Scripts/PauseManager.cs.meta new file mode 100644 index 0000000..992d3c3 --- /dev/null +++ b/302/Assets/Scripts/PauseManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca352e3a141129743824a83b5d7a231f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly15_spider.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly15_spider.cs index f612da5..eeb7f63 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly15_spider.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly15_spider.cs @@ -10,9 +10,13 @@ public class Anomaly15_spider : AbstractAnomalyInteractable private Transform cameraTransform; private AudioSource audioSource; - private void Start() + protected override bool Start_() { + bool res = base.Start_(); + StartAnomaly(); + + return res; } public override bool StartAnomaly() diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly16_marker.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly16_marker.cs index b04d613..525ace7 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly16_marker.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly16_marker.cs @@ -62,9 +62,13 @@ public override bool StartAnomaly() return true; } - private void Start() + protected override bool Start_() { + bool res = base.Start_(); + StartAnomaly(); + + return res; } public override bool ResetAnomaly() diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs index 3c3d6b5..24b6985 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs @@ -62,9 +62,13 @@ public override bool StartAnomaly() return true; } - private void Start() + protected override bool Start_() { + bool res = base.Start_(); + StartAnomaly(); + + return res; } public override bool ResetAnomaly() diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly29_banana.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly29_banana.cs index 75d0ae0..752b678 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly29_banana.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly29_banana.cs @@ -7,7 +7,7 @@ public class Anomaly29_banana : MonoBehaviour void Start() { - anomalyManager = FindObjectOfType(); + anomalyManager = FindObjectOfType(); } private void OnCollisionEnter(Collision collision) diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs index 2761889..e8d7fb4 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs @@ -23,9 +23,13 @@ public class Anomaly30_window : AbstractAnomalyInteractable private AudioSource audioSource; private static GameObject coroutineRunner; - private void Start() + protected override bool Start_() { + bool res = base.Start_(); + StartAnomaly(); + + return res; } public override bool StartAnomaly()