diff --git a/302/Assets/Scripts/AbstractBehaviour.cs b/302/Assets/Scripts/AbstractBehaviour.cs index 5562c50..e040a43 100644 --- a/302/Assets/Scripts/AbstractBehaviour.cs +++ b/302/Assets/Scripts/AbstractBehaviour.cs @@ -126,16 +126,19 @@ public class MyManager : AbstractBehaviour // TODO: 클래스 이름 수정하 // `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 base.Awake_(); + return res; } // 필드를 초기화하는 메서드 diff --git a/302/Assets/Scripts/SlideManager.cs b/302/Assets/Scripts/SlideManager.cs index 6200a33..028b79e 100644 --- a/302/Assets/Scripts/SlideManager.cs +++ b/302/Assets/Scripts/SlideManager.cs @@ -46,40 +46,29 @@ public bool UpdateStage() bool res = true; if (stage == 0) { - // generate random slide index list - _slideList = _random.Combination(numSlide, numStage); - Log($"Generate `_slideList` success: [{string.Join(", ", _slideList)}]"); - - // find and put away the slides - Log("Call `FindSlides` begin"); - if (FindSlides()) { - Log("Call `FindSlides` success"); - - foreach (GameObject obj in _objects) { - obj.transform.Translate(Vector3.down * 100.0f); - } - - Log("Set slide success: off"); + Log("Call `PutAwaySlides` begin"); + if (PutAwaySlides()) { + Log("Call `PutAwaySlides` success"); } else { - Log("Call `FindSlides` failed", mode: 1); + Log("Call `PutAwaySlides` failed", mode: 1); res = false; } } else if (stage > 0 && stage <= numStage) { - // find and update slides - Log("Call `FindSlides` begin"); - if (FindSlides()) { - Log("Call `FindSlides` success"); - - int index = _slideList[stage - 1]; - - foreach (SlideController controller in _controllers) { - controller.Index = index; - controller.ResetSlide(); + if (stage == 1) { + Log("Call `GenerateList` begin"); + if (GenerateList()) { + Log("Call `GenerateList` success"); + } else { + Log("Call `GenerateList` failed", mode: 1); + res = false; } + } - Log($"Set slide success: {index}"); + Log("Call `UpdateSlides` begin"); + if (UpdateSlides(stage)) { + Log("Call `UpdateSlides` success"); } else { - Log("Call `FindSlides` failed", mode: 1); + Log("Call `UpdateSlides` failed", mode: 1); res = false; } } else { @@ -97,16 +86,19 @@ public bool UpdateStage() // `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 base.Awake_(); + return res; } // 필드를 초기화하는 메서드 @@ -118,6 +110,12 @@ protected override bool InitFields() _random = new SCH_Random(); Log("Initialize `_random` success"); + // _objects + _objects = new List(); + + // _controllers + _controllers = new List(); + // _slideList _slideList = new int[numStage]; Log("Initialize `_slideList` success"); @@ -129,11 +127,71 @@ protected override bool InitFields() * new methods * ***************/ + // 슬라이드를 치우는 메서드 + private bool PutAwaySlides() + { + bool res = true; + + Log("Call `FindSlides` begin"); + if (FindSlides()) { + Log("Call `FindSlides` success"); + + foreach (GameObject obj in _objects) { + obj.transform.Translate(Vector3.down * 100.0f); + } + + Log("Set slide success: off"); + } else { + Log("Call `FindSlides` failed", mode: 1); + res = false; + } + + return res; + } + + // 슬라이드 색인 리스트를 생성하는 메서드 + private bool GenerateList() + { + bool res = true; + + _slideList = _random.Combination(numSlide, numStage); + Log($"Generate `_slideList` success: [{string.Join(", ", _slideList)}]"); + + return res; + } + + // 슬라이드를 갱신하는 메서드 + private bool UpdateSlides(int stage) + { + int index = _slideList[stage - 1]; + bool res = true; + + Log("Call `FindSlides` begin"); + if (FindSlides()) { + Log("Call `FindSlides` success"); + + foreach (SlideController controller in _controllers) { + controller.Index = index; + controller.ResetSlide(); + } + + Log($"Set slide success: {index}"); + } else { + Log("Call `FindSlides` failed", mode: 1); + res = false; + } + + return res; + } + // 슬라이드를 찾는 메서드 private bool FindSlides() { bool res = true; + _objects.Clear(); + _controllers.Clear(); + for (int idx = 0; idx < names.Length; idx++) { GameObject obj = GameObject.Find(names[idx]); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18_Interactable.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18_Interactable.cs index 3171391..e11998b 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18_Interactable.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18_Interactable.cs @@ -31,7 +31,7 @@ public override void OnInteract() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly18Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (18)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs index b235615..7f7fa80 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs @@ -54,7 +54,7 @@ public override void OnInteract() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly19Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (19)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1_Girl.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1_Girl.cs index 4027ac7..c0b305f 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1_Girl.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1_Girl.cs @@ -24,7 +24,7 @@ public override void OnInteract() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly1Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (1)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs index 3a3748e..18d06d9 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs @@ -35,7 +35,7 @@ public override void OnInteract() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly20Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (20)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs index 0491e0b..6997717 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs @@ -91,7 +91,7 @@ void Update() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly23Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (23)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2_Laptop.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2_Laptop.cs index 8f14570..0107b80 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2_Laptop.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2_Laptop.cs @@ -34,7 +34,7 @@ public override void OnInteract() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly2Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (2)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs index a085b91..c1a79b0 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs @@ -30,7 +30,7 @@ public override void OnInteract() Log("Call `GameManager.SetStageClear` end"); // Code used before `GameManager` updates begin - GameObject controllerObject = GameObject.Find("Anomaly6Manager"); + GameObject controllerObject = GameObject.Find("AnomalyManager (6)(Clone)"); AbstractAnomalyObject controller = controllerObject.GetComponent(); Log($"Call `{controller.Name}.ResetAnomaly` begin"); diff --git a/302/Assets/Scripts/TimeManager.cs b/302/Assets/Scripts/TimeManager.cs new file mode 100644 index 0000000..3332940 --- /dev/null +++ b/302/Assets/Scripts/TimeManager.cs @@ -0,0 +1,109 @@ +using UnityEngine; + +public class TimeManager : AbstractBehaviour, IStageObserver +{ + /********** + * fields * + **********/ + + // 오브젝트 이름 + public string nameClock; + public string nameLaptop; + + /************** + * properties * + **************/ + + // 클래스 이름 + public override string Name { get; } = "TimeManager"; + + // 클래스 인스턴스 + public static TimeManager Instance { get; private set; } + + /********************************** + * implementation: IStageObserver * + **********************************/ + + // 단계 변경 시 불리는 메서드 + public bool UpdateStage() + { + int stage = GameManager.Instance.GetCurrentStage(); + ClockController clock = FindClock(); + LaptopScreenController laptop = FindLaptop(); + bool res = true; + + if (clock != null) { + Log("Find `ClockController` success"); + clock.SetTime(stage); + } else { + Log("Find `ClockController` failed", mode: 1); + res = false; + } + + if (laptop != null) { + Log("Find `LaptopScreenController` success"); + laptop.ChangeScreen(stage); + } else { + Log("Find `LaptopScreenController` failed", mode: 1); + res = false; + } + + return res; + } + + /************************************* + * 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; + } + + /*************** + * new methods * + ***************/ + + // 시계를 찾는 메서드 + private ClockController FindClock() + { + GameObject obj = GameObject.Find(nameClock); + ClockController clock; + + if (obj != null) { + clock = obj.GetComponent(); + } else { + clock = null; + } + + return clock; + } + + // 노트북을 찾는 메서드 + private LaptopScreenController FindLaptop() + { + GameObject obj = GameObject.Find(nameLaptop); + LaptopScreenController laptop; + + if (obj != null) { + laptop = obj.GetComponent(); + } else { + laptop = null; + } + + return laptop; + } +} diff --git a/302/Assets/Scripts/TimeManager.cs.meta b/302/Assets/Scripts/TimeManager.cs.meta new file mode 100644 index 0000000..6a4b083 --- /dev/null +++ b/302/Assets/Scripts/TimeManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27f34bf521656324bb91ded1d2864982 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: