From fe4dc7ca10ca572e6e21a457cebff12221623c51 Mon Sep 17 00:00:00 2001 From: Prown0 <100746335+Prown0@users.noreply.github.com> Date: Tue, 26 Nov 2024 01:17:46 +0900 Subject: [PATCH 1/3] Cleaning code (incomplete) --- 302/Assets/Scripts/SCH_AnomalyInteractable.cs | 27 +--- 302/Assets/Scripts/SCH_AnomalyManager.cs | 77 ++++------ .../Anomaly18Manager.cs | 6 +- .../Anomaly19Manager.cs | 126 +++++---------- .../SpecificAnomalyManager/Anomaly19_Slide.cs | 144 ++++++++---------- .../SpecificAnomalyManager/Anomaly1Manager.cs | 2 +- .../SpecificAnomalyManager/Anomaly2Manager.cs | 2 +- .../SpecificAnomalyManager/Anomaly6Manager.cs | 92 +++-------- .../SpecificAnomalyManager/Anomaly6_Cake.cs | 112 ++++---------- 9 files changed, 191 insertions(+), 397 deletions(-) diff --git a/302/Assets/Scripts/SCH_AnomalyInteractable.cs b/302/Assets/Scripts/SCH_AnomalyInteractable.cs index 1faa0eb..8495b34 100644 --- a/302/Assets/Scripts/SCH_AnomalyInteractable.cs +++ b/302/Assets/Scripts/SCH_AnomalyInteractable.cs @@ -7,18 +7,12 @@ public class SCH_AnomalyInteractable : SCH_AnomalyObject, IInteractable * fields * **********/ - // 오브젝트 이름 - public string nameCameraMain; - // 가변 수치 public string prompt; public float distanceInteractionMax; - // 오브젝트 - protected GameObject _objectCameraMain; - // 기타 수치 - protected bool _canInteract; + protected bool canInteract; /************** * properties * @@ -50,13 +44,13 @@ public void OnInteract() Log("Call `Manager.InteractionSuccess`: failed", mode: 1); } - _canInteract = false; + canInteract = false; } // 현재 상호작용 가능한지 여부 반환 public bool CanInteract(float distance) { - return _canInteract && distance <= distanceInteractionMax; + return canInteract && distance <= distanceInteractionMax; } /********************************* @@ -68,18 +62,9 @@ protected override bool InitFields() { bool res = base.InitFields(); - // _objectCameraMain - _objectCameraMain = GameObject.Find(nameCameraMain); - if (_objectCameraMain != null) { - Log("Initialize `_objectCameraMain`: success"); - } else { - Log("Initialize `_objectCameraMain`: failed", mode: 1); - res = false; - } - - // _canInteract - _canInteract = true; - Log("Initialize `_canInteract`: success"); + // canInteract + canInteract = true; + Log("Initialize `canInteract`: success"); return res; } diff --git a/302/Assets/Scripts/SCH_AnomalyManager.cs b/302/Assets/Scripts/SCH_AnomalyManager.cs index 9f15665..553857d 100644 --- a/302/Assets/Scripts/SCH_AnomalyManager.cs +++ b/302/Assets/Scripts/SCH_AnomalyManager.cs @@ -1,14 +1,14 @@ using System.Collections.Generic; using UnityEngine; -public class SCH_AnomalyManager : SCH_Behaviour +public class SCH_AnomalyManager : SCH_AnomalyObject { /********** * fields * **********/ // 이상현상 오브젝트 리스트 - protected List _objects; + protected List objects; /************** * properties * @@ -17,23 +17,6 @@ public class SCH_AnomalyManager : SCH_Behaviour // 클래스 이름 public override string Name { get; } = "SCH_AnomalyManager"; - /************ - * messeges * - ************/ - - // This function is called when the object becomes enabled and active. - protected override void OnEnable() - { - base.OnEnable(); - - Log("Call `SetAnomaly` begin"); - if (SetAnomaly()) { - Log("Call `SetAnomaly` end: success"); - } else { - Log("Call `SetAnomaly` end: failed", mode: 1); - } - } - /********************************* * implementation: SCH_Behaviour * *********************************/ @@ -43,9 +26,35 @@ protected override bool InitFields() { bool res = base.InitFields(); - // _objects - _objects = new List(); - Log("Initialize `_objects`: success"); + // Manager + Manager = this; + Log("Initialize `Manager`: success"); + + // objects + objects = new List(); + Log("Initialize `objects`: success"); + + return res; + } + + /************************************* + * implementation: SCH_AnomalyObject * + *************************************/ + + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); + + foreach (SCH_AnomalyObject obj in objects) { + Log("Call `obj.ResetAnomaly` begin"); + if (obj.ResetAnomaly()) { + Log("Call `obj.ResetAnomaly` end: success"); + } else { + Log("Call `obj.ResetAnomaly` end: failed", mode: 1); + res = false; + } + } return res; } @@ -73,28 +82,4 @@ public virtual bool InteractionSuccess() return res; } - - // 이상현상을 시작하는 메서드 - protected virtual bool SetAnomaly() - { - return true; - } - - // 이상현상을 초기화하는 메서드 - protected virtual bool ResetAnomaly() - { - bool res = true; - - foreach (SCH_AnomalyObject obj in _objects) { - Log("Call `obj.ResetAnomaly` begin"); - if (obj.ResetAnomaly()) { - Log("Call `obj.ResetAnomaly` end: success"); - } else { - Log("Call `obj.ResetAnomaly` end: failed", mode: 1); - res = false; - } - } - - return res; - } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18Manager.cs index 03d048e..3119b49 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly18Manager.cs @@ -36,7 +36,7 @@ protected override bool InitFields() // _objectWall _objectWall = GameObject.Find(nameWall).GetComponent(); if (_objectWall != null) { - _objects.Add(_objectWall); + objects.Add(_objectWall); Log("Initialize `_objectWall`: success"); } else { Log("Initialize `_objectWall`: failed", mode: 1); @@ -46,7 +46,7 @@ protected override bool InitFields() // _objectClock _objectClock = GameObject.Find(nameClock).GetComponent(); if (_objectClock != null) { - _objects.Add(_objectClock); + objects.Add(_objectClock); Log("Initialize `_objectClock`: success"); } else { Log("Initialize `_objectClock`: failed", mode: 1); @@ -90,7 +90,7 @@ protected override bool SetAnomaly() SCH_AnomalyObject obj = Instantiate(prefab).GetComponent(); obj.Manager = this; - _objects.Add(obj); + objects.Add(obj); Log($"Set `{prefab.name}`: success"); } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19Manager.cs index cf2513c..80c560c 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19Manager.cs @@ -1,115 +1,65 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly19Manager : MonoBehaviour +public class Anomaly19Manager : SCH_AnomalyManager { - /************* - * constants * - *************/ - - private const string NAME = "Anomaly19Manager"; - /********** * fields * **********/ - // 오브젝트의 이름 - public string nameGameManager; + // 오브젝트 이름 public string nameSlide; - // 게임 매니저 - private GameManager _manager; - - // 슬라이드 스크립트 - private Anomaly19_Slide _scriptSlide; - - /********************** - * overridden methods * - **********************/ - - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - - if (!SetAnomaly()) { - return; - } - } + // 오브젝트 + private SCH_AnomalyObject _objectSlide; - /*************** - * new methods * - ***************/ + /************** + * properties * + **************/ - // 상호작용 성공 시 처리 함수 - // - // 반환 값 - // - true: 처리 성공 - // - false: 처리 실패 - public void InteractionSuccess() - { - _manager.SetStageClear(); + // 클래스 이름 + public override string Name { get; } = "Anomaly19Manager"; - if (!ResetAnomaly()) { - return; - } - } + /********************************* + * implementation: SCH_Behaviour * + *********************************/ - // Private fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool InitFields() + // 필드를 초기화하는 메서드 + protected override bool InitFields() { - bool res = true; - - // `_manager` 초기화 - _manager = GameObject.Find(nameGameManager).GetComponent(); - if (_manager != null) { - Debug.Log($"[{NAME}] Find `_manager` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_manager`."); - res = false; - } + bool res = base.InitFields(); - // `_scriptSlide` 초기화 - _scriptSlide = GameObject.Find(nameSlide).GetComponent(); - if (_scriptSlide != null) { - Debug.Log($"[{NAME}] Find `_scriptSlide` successfully."); + // _objectSlide + _objectSlide = GameObject.Find(nameSlide).GetComponent(); + if (_objectSlide != null) { + objects.Add(_objectSlide); + Log("Initialize `_objectSlide`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_scriptSlide`."); + Log("Initialize `_objectSlide`: failed", mode: 1); res = false; } return res; } - // 이상현상을 시작하는 함수 - // - // 반환 값 - // - true: 시작 성공 - // - false: 시작 실패 - private bool SetAnomaly() + /************************************** + * implementation: SCH_AnomalyManager * + **************************************/ + + // 이상현상을 시작하는 메서드 + protected override bool SetAnomaly() { - _scriptSlide.enabled = true; - _scriptSlide.Manager = this; - Debug.Log($"[{NAME}] Anomaly is set."); + bool res = base.SetAnomaly(); - return true; - } + // 슬라이드 + if (_objectSlide != null) { + _objectSlide.enabled = true; + _objectSlide.Manager = this; + Log("Set `_objectSlide`: success"); + } else { + Log("Set `_objectSlide`: failed", mode: 1); + res = false; + } - // 이상현상을 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool ResetAnomaly() - { - return true; + return res; } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs index 4c52514..3590b0c 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs @@ -1,130 +1,112 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly19_Slide : InteractableObject +[RequireComponent(typeof(SlideController))] +public class Anomaly19_Slide : SCH_AnomalyInteractable { - /************* - * constants * - *************/ - - private const string NAME = "Anomaly19_Slide"; - /********** * fields * **********/ - // 오브젝트 이름 - public string nameCamera; + // 오브젝트 + public GameObject objectCamera; - // 기준 거리 + // 가변 수치 public float thresholdDistance; - // 오브젝트 - private GameObject _objectCamera; - // 슬라이드 컨트롤러 - private SlideController _controller; + private SlideController _script; - // 흐르기 시작했는지 여부 + // 내부 수치 private bool _isTrickling; /************** * properties * **************/ - public Anomaly19Manager Manager { get; set; } - - /********************** - * overridden methods * - **********************/ - - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } + // 클래스 이름 + public override string Name { get; } = "Anomaly19_Slide"; - gameObject.layer = 3; - } + /************ + * messeges * + ************/ // Update is called every frame, if the MonoBehaviour is enabled. void Update() { if (!_isTrickling && DistanceToCamera() <= thresholdDistance) { - _controller.StartTrickling(); + _script.StartTrickling(); _isTrickling = true; } } - // 상호작용 시 실행될 메서드 - public override void OnInteract() + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 + protected override bool InitFields() { - if (canInteract) { - canInteract = false; + bool res = base.InitFields(); - base.OnInteract(); + // _script + _script = GetComponent(); + if (_script != null) { + Log("Initialize `_script`: success"); + } else { + Log("Initialize `_script`: failed", mode: 1); + res = false; + } - if (Manager != null) { - Debug.Log($"[{NAME}] Call `Anomaly19Manager.InteractionSuccess`"); + // _isTrickling + _isTrickling = false; + Log("Initialize `_isTrickling`: success"); - Manager.InteractionSuccess(); - gameObject.layer = 0; - _controller.ResetSlide(); - enabled = false; - } else { - Debug.LogWarning($"[{NAME}] `Manager` is not set."); - } - } + return res; } - /*************** - * new methods * - ***************/ + /************************************* + * implementation: SCH_AnomalyObject * + *************************************/ - // Private fields를 초기화하는 메서드 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool InitFields() + // 이상현상을 시작하는 메서드 + protected override bool SetAnomaly() { - bool res = true; + bool res = base.SetAnomaly(); - // `_objectCamera` 초기화 - _objectCamera = GameObject.Find(nameCamera); - if (_objectCamera != null) { - Debug.Log($"[{NAME}] Find `_objectCamera` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectCamera`."); - res = false; - } + // 슬라이드 레이어(3: 상호작용 레이어) + gameObject.layer = 3; + Log("Set slide layer: success"); + + return res; + } - // `_controller` 초기화 - _controller = gameObject.GetComponent(); + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); - if (_controller != null) { - Debug.Log($"[{NAME}] Find `_controller` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_controller`."); - res = false; - } + // 슬라이드 레이어(0: 일반 레이어) + gameObject.layer = 0; + Log("Reset slide layer: success"); - // `_isTrickling` 초기화 - _isTrickling = false; - Debug.Log($"[{NAME}] Initialize `_isTrickling` successfully."); + // 슬라이드 화면 + Log("Call `_script.ResetSlide` begin"); + _script.ResetSlide(); + Log("Call `_script.ResetSlide` end: success"); + + // 실행 종료 + enabled = false; return res; } + /*********** + * methods * + ***********/ + // 카메라와의 거리를 구하는 메서드 - // - // 반환값 - // - 카메라 `_objectCamera`와의 거리 private float DistanceToCamera() { - return (_objectCamera.transform.position - transform.position).magnitude; + return (objectCamera.transform.position - transform.position).magnitude; } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1Manager.cs index 4b2e52e..a754c06 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly1Manager.cs @@ -46,7 +46,7 @@ protected override bool SetAnomaly() SCH_AnomalyObject obj = Instantiate(prefabGirl).GetComponent(); obj.Manager = this; - _objects.Add(obj); + objects.Add(obj); Log("Set `prefabGirl`: success"); } else { Log("Set `prefabGirl`: failed", mode: 1); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2Manager.cs index 860af3f..fc21d6a 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly2Manager.cs @@ -31,7 +31,7 @@ protected override bool InitFields() // _objectLaptop _objectLaptop = GameObject.Find(nameLaptop).GetComponent(); if (_objectLaptop != null) { - _objects.Add(_objectLaptop); + objects.Add(_objectLaptop); Log("Initialize `_objectLaptop`: success"); } else { Log("Initialize `_objectLaptop`: failed", mode: 1); diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6Manager.cs index c2ca644..5bc298f 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6Manager.cs @@ -1,100 +1,42 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly6Manager : MonoBehaviour +public class Anomaly6Manager : SCH_AnomalyManager { - /************* - * constants * - *************/ - - private const string NAME = "Anomaly6Manager"; - /********** * fields * **********/ - // 오브젝트의 이름 - public string nameGameManager; - // 프리팹 public GameObject prefabCake; - // 게임 메니저 - private GameManager _manager; - - /********************** - * overridden methods * - **********************/ + /************** + * properties * + **************/ - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } + // 클래스 이름 + public override string Name { get; } = "Anomaly6Manager"; - if (!SetAnomaly()) { - return; - } - } - - /*************** - * new methods * - ***************/ - - // 상호작용 성공 시 처리 메서드 - public void InteractionSuccess() - { - _manager.SetStageClear(); - - if (!ResetAnomaly()) { - return; - } - } - - // Private fields를 초기화하는 메서드 - private bool InitFields() - { - bool res = true; - - // `_manager` 초기화 - _manager = GameObject.Find(nameGameManager).GetComponent(); - if (_manager != null) { - Debug.Log($"[{NAME}] Find `_manager` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_manager`."); - res = false; - } - - return res; - } + /************************************** + * implementation: SCH_AnomalyManager * + **************************************/ // 이상현상을 시작하는 메서드 - private bool SetAnomaly() + protected override bool SetAnomaly() { - bool res = true; + bool res = base.SetAnomaly(); // 케이크 if (prefabCake != null) { - Instantiate(prefabCake).GetComponent().Manager = this; - Debug.Log($"[{NAME}] Instantiate `prefabCake` successfully."); + SCH_AnomalyObject obj = Instantiate(prefabCake).GetComponent(); + + obj.Manager = this; + objects.Add(obj); + Log("Set `prefabCake`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `prefabCake`."); + Log("Set `prefabCake`: failed", mode: 1); res = false; } - if (res) { - Debug.Log($"[{NAME}] Anomaly is set."); - } - return res; } - - // 이상현상을 초기화하는 메서드 - private bool ResetAnomaly() - { - return true; - } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs index e0df666..f31239b 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs @@ -1,114 +1,64 @@ using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly6_Cake : InteractableObject +public class Anomaly6_Cake : SCH_AnomalyInteractable { - /************* - * constants * - *************/ - - private const string NAME = "Anomaly6_Cake"; - /********** * fields * **********/ - // 오브젝트의 이름 - public string nameCamera; - - // 수치 public float duration; - // 오브젝트 - private GameObject _objectCamera; - - // 상호작용 전인지 여부 - private bool _beforeInteraction; - /************** * properties * **************/ - public Anomaly6Manager Manager { get; set; } - - /********************** - * overridden methods * - **********************/ + // 클래스 이름 + public override string Name { get; } = "Anomaly6_Cake"; - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - } - - // Update is called every frame, if the MonoBehaviour is enabled. - void Update() - { - if (_beforeInteraction) { - UpdateCanInteract(); - } - } + /************************************* + * implementation: SCH_AnomalyObject * + *************************************/ - // 상호작용 시 실행될 메서드 - public override void OnInteract() + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() { - base.OnInteract(); + bool res = base.ResetAnomaly(); - if (Manager != null) { - Debug.Log($"[{NAME}] Call `Anomaly6Manager.InteractionSuccess`"); - Manager.InteractionSuccess(); - - StartCoroutine(FadeAsync(duration)); - } else { - Debug.LogWarning($"[{NAME}] `Manager` is not set."); - } - } - - /*************** - * new methods * - ***************/ - - // Private fields를 초기화하는 메서드 - private bool InitFields() - { - bool res = true; - - // `_objectCamera` 초기화 - _objectCamera = GameObject.Find(nameCamera); - if (_objectCamera != null) { - Debug.Log($"[{NAME}] Find `_objectCamera` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectCamera`."); - res = false; - } + Log("Call `FadeAsync` asynchronously"); + StartCoroutine(FadeAsync()); return res; } - // `canInteract`를 갱신하는 메서드 - private void UpdateCanInteract() - { - float distance = (_objectCamera.transform.position - transform.position).magnitude; - - canInteract = distance <= interactionRange; - } + /*********** + * methods * + ***********/ - // 소멸 메서드 - private IEnumerator FadeAsync(float duration) + // 지속시간 동안 투명해지다가 사라지는 메서드 + private IEnumerator FadeAsync() { - Renderer[] renderers = gameObject.GetComponentsInChildren(); + Renderer[] renderers = GetComponentsInChildren(); float timeStart = Time.time; float time; - float alpha; + + foreach (Renderer renderer in renderers) { + foreach (Material material in renderer.materials) { + material.renderQueue = 3000; + material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); + material.DisableKeyword("_ALPHATEST_ON"); + material.EnableKeyword("_ALPHABLEND_ON"); + material.SetFloat("_Mode", 2); + material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); + material.SetInt("_ZWrite", 0); + } + } yield return null; while ((time = Time.time - timeStart) < duration) { - alpha = 1.0f - time / duration; + float alpha = 1.0f - time / duration; foreach (Renderer renderer in renderers) { foreach (Material material in renderer.materials) { From 98aba1c9137c9740b5bd48f92d31d52f68c19fb5 Mon Sep 17 00:00:00 2001 From: Prown0 <100746335+Prown0@users.noreply.github.com> Date: Wed, 27 Nov 2024 04:23:56 +0900 Subject: [PATCH 2/3] Cleaning code & bug fix --- .../Anomaly20InteractableBack.prefab | 4 +- .../Anomaly20InteractableFront.prefab | 4 +- .../Anomaly20InteractableRight.prefab | 4 +- .../Prefabs/Anomaly20/PlayerAnomaly.prefab | 1 + 302/Assets/Prefabs/Anomaly23/ghost.prefab | 6 +- 302/Assets/Scenes/DefaultGameScene.unity | 25 ++- 302/Assets/Scripts/LaptopFaceController.cs | 63 ++++-- 302/Assets/Scripts/LaptopScreenController.cs | 25 +-- 302/Assets/Scripts/SCH_AnomalyObject.cs | 2 +- 302/Assets/Scripts/SCH_Behaviour.cs | 2 +- 302/Assets/Scripts/SCH_Random.cs | 92 ++++++++ 302/Assets/Scripts/SCH_Random.cs.meta | 11 + 302/Assets/Scripts/SlideController.cs | 199 ++++++------------ 302/Assets/Scripts/SlideManager.cs | 129 +++++------- .../SpecificAnomalyManager/Anomaly19_Slide.cs | 2 +- .../Anomaly20Manager.cs | 154 +++----------- .../Anomaly20_Interactable.cs | 101 ++++----- .../Anomaly20_InteractableBack.cs | 35 +-- .../Anomaly20_InteractableFront.cs | 35 +-- .../Anomaly20_InteractableRight.cs | 35 +-- .../Anomaly20_Player.cs | 126 ++++++----- .../Anomaly23Manager.cs | 124 ++++------- .../SpecificAnomalyManager/Anomaly23_Ghost.cs | 155 ++++++-------- .../Anomaly23_Laptop.cs | 104 +++++++++ .../Anomaly23_Laptop.cs.meta | 11 + 25 files changed, 726 insertions(+), 723 deletions(-) create mode 100644 302/Assets/Scripts/SCH_Random.cs create mode 100644 302/Assets/Scripts/SCH_Random.cs.meta create mode 100644 302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs create mode 100644 302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs.meta diff --git a/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableBack.prefab b/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableBack.prefab index 8616bae..57bfc5b 100644 --- a/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableBack.prefab +++ b/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableBack.prefab @@ -58,8 +58,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e3abf5127f1fd514eafeb2411741d79a, type: 3} m_Name: m_EditorClassIdentifier: - promptMessage: "\uD074\uB9AD\uD558\uC5EC \uC0C1\uD638\uC791\uC6A9" - interactionRange: 1 + prompt: + distanceInteractionMax: 1.8 namePlayer: Player nameBoard: BoardBack zMin: -15.5 diff --git a/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableFront.prefab b/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableFront.prefab index ae7dcb7..4f771b5 100644 --- a/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableFront.prefab +++ b/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableFront.prefab @@ -58,8 +58,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fa6dee73251e9a04e8d20560af1f1997, type: 3} m_Name: m_EditorClassIdentifier: - promptMessage: "\uD074\uB9AD\uD558\uC5EC \uC0C1\uD638\uC791\uC6A9" - interactionRange: 1 + prompt: + distanceInteractionMax: 1.8 namePlayer: Player nameBoard: BoardFront zMin: -11.3 diff --git a/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableRight.prefab b/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableRight.prefab index 34c3b57..e6221bf 100644 --- a/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableRight.prefab +++ b/302/Assets/Prefabs/Anomaly20/Anomaly20InteractableRight.prefab @@ -58,8 +58,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5c14879ba6f660e4196accbcc95dfe7a, type: 3} m_Name: m_EditorClassIdentifier: - promptMessage: "\uD074\uB9AD\uD558\uC5EC \uC0C1\uD638\uC791\uC6A9" - interactionRange: 1 + prompt: + distanceInteractionMax: 1.8 namePlayer: Player nameBoard: BoardRight (1) x1Min: -25.2 diff --git a/302/Assets/Prefabs/Anomaly20/PlayerAnomaly.prefab b/302/Assets/Prefabs/Anomaly20/PlayerAnomaly.prefab index 0acf687..107ed3f 100644 --- a/302/Assets/Prefabs/Anomaly20/PlayerAnomaly.prefab +++ b/302/Assets/Prefabs/Anomaly20/PlayerAnomaly.prefab @@ -132,6 +132,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: namePlayer: Player + duration: 2 --- !u!1 &3565635857044313825 GameObject: m_ObjectHideFlags: 0 diff --git a/302/Assets/Prefabs/Anomaly23/ghost.prefab b/302/Assets/Prefabs/Anomaly23/ghost.prefab index d16f535..fc55bdd 100644 --- a/302/Assets/Prefabs/Anomaly23/ghost.prefab +++ b/302/Assets/Prefabs/Anomaly23/ghost.prefab @@ -773,9 +773,9 @@ MonoBehaviour: namePlayer: Player nameCamera: Main Camera position: {x: 24, y: 2, z: 0} - speedInit: 2 - speedDelta: 4 - durationChase: 20 + speedInit: 1 + speedDelta: 5 + durationChase: 25 durationFade: 5 --- !u!1 &6612614341887459618 GameObject: diff --git a/302/Assets/Scenes/DefaultGameScene.unity b/302/Assets/Scenes/DefaultGameScene.unity index 01b8cbb..fee6e94 100644 --- a/302/Assets/Scenes/DefaultGameScene.unity +++ b/302/Assets/Scenes/DefaultGameScene.unity @@ -4919,6 +4919,24 @@ Transform: m_CorrespondingSourceObject: {fileID: 1809372938388778512, guid: 474138867ca9be144953fa0ca636b7c9, type: 3} m_PrefabInstance: {fileID: 241118524} m_PrefabAsset: {fileID: 0} +--- !u!1 &243047807 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 6482429499626390066, guid: e98bfaaf0938845d098edce033f7e7a2, type: 3} + m_PrefabInstance: {fileID: 2208074503459508080} + m_PrefabAsset: {fileID: 0} +--- !u!114 &243047810 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 243047807} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d755543348868a045964c1da73713696, type: 3} + m_Name: + m_EditorClassIdentifier: + anomalyScreenIndex: 12 --- !u!1001 &245510671 PrefabInstance: m_ObjectHideFlags: 0 @@ -22951,9 +22969,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2960778f4e9343349a587d3d39be1a05, type: 3} m_Name: m_EditorClassIdentifier: - promptMessage: "\uD074\uB9AD\uD558\uC5EC \uC0C1\uD638\uC791\uC6A9" - interactionRange: 2 - nameCamera: Main Camera + prompt: + distanceInteractionMax: 0 + objectCamera: {fileID: 0} thresholdDistance: 10 --- !u!1001 &1027390622 PrefabInstance: @@ -40988,7 +41006,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 18e2c46eaa68afe458ec364512f84534, type: 3} m_Name: m_EditorClassIdentifier: - nameCameraMain: Main Camera prompt: distanceInteractionMax: 5 --- !u!65 &1875637180 diff --git a/302/Assets/Scripts/LaptopFaceController.cs b/302/Assets/Scripts/LaptopFaceController.cs index 886129f..f2cf10b 100644 --- a/302/Assets/Scripts/LaptopFaceController.cs +++ b/302/Assets/Scripts/LaptopFaceController.cs @@ -1,14 +1,10 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class LaptopFaceController : LaptopScreenController { - /********** - * fields * - **********/ - - public GameObject player; + /************* + * constants * + *************/ private int[] X0DATA = new int[] { 394, 391, 389, 387, 386, 385, 384, 383, 382, 381, 380, 379, 379, 378, 378, 377, 377, @@ -36,6 +32,14 @@ public class LaptopFaceController : LaptopScreenController 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322 }; + /********** + * fields * + **********/ + + // 오브젝트 + public GameObject player; + + // 내부 수치 private int TANGENT_MAX = 25; private float TANGENT_CONST = 12.5f; private int ORIGIN_X = 38; @@ -45,18 +49,14 @@ public class LaptopFaceController : LaptopScreenController private bool _isGazing; private int _tangent; - /********************** - * overridden methods * - **********************/ + /************ + * messages * + ************/ // Start is called on the frame when a script is enabled just // before any of the Update methods are called the first time. void Start() { - _colour = defaults[0].GetPixel(407, 297); - _isGazing = false; - _tangent = 0; - ResetScreen(); } @@ -68,9 +68,34 @@ void Update() } } - /*************** - * new methods * - ***************/ + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 + protected override bool InitFields() + { + bool res = base.InitFields(); + + // _colour + _colour = defaults[0].GetPixel(407, 297); + Log("Initialize `_colour`: success: " + + $"Color({_colour.r}, {_colour.g}, {_colour.b}, {_colour.a})"); + + // _isGazing + _isGazing = false; + Log("Initialize `_isGazing`: success"); + + // _tangent + _tangent = 0; + Log("Initialize `_tangent`: success"); + + return res; + } + + /****************************************** + * implementation: LaptopScreenController * + ******************************************/ // 화면을 초기화하는 메서드 public override void ResetScreen() @@ -95,6 +120,10 @@ public override void ResetScreen() screen.Apply(); } + /*********** + * methods * + ***********/ + // 쳐다보기 시작하는 메서드 public void StartGazing() { diff --git a/302/Assets/Scripts/LaptopScreenController.cs b/302/Assets/Scripts/LaptopScreenController.cs index c71802a..fc717b2 100644 --- a/302/Assets/Scripts/LaptopScreenController.cs +++ b/302/Assets/Scripts/LaptopScreenController.cs @@ -1,16 +1,16 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class LaptopScreenController : MonoBehaviour +public class LaptopScreenController : SCH_Behaviour { /********** * fields * **********/ + // 텍스처 public Texture2D screen; public Texture2D[] defaults; + // 가변 수치 public int screenXMin; public int screenXMax; public int screenYMin; @@ -21,12 +21,13 @@ public class LaptopScreenController : MonoBehaviour public int defaultYMin; public int defaultYMax; - public bool isFlipped; - /************** * properties * **************/ + // 클래스 이름 + public override string Name { get; } = "LaptopScreenController"; + private int _index = 0; public int Index { get => _index; @@ -39,9 +40,9 @@ public int Index { } } - /********************** - * overridden methods * - **********************/ + /************ + * messages * + ************/ // Start is called on the frame when a script is enabled just // before any of the Update methods are called the first time. @@ -50,9 +51,9 @@ void Start() ResetScreen(); } - /*************** - * new methods * - ***************/ + /*********** + * methods * + ***********/ public virtual void ResetScreen() { @@ -79,4 +80,4 @@ public void ChangeScreen(int index) Index = index; ResetScreen(); } -} \ No newline at end of file +} diff --git a/302/Assets/Scripts/SCH_AnomalyObject.cs b/302/Assets/Scripts/SCH_AnomalyObject.cs index c7a46f3..da9e9d4 100644 --- a/302/Assets/Scripts/SCH_AnomalyObject.cs +++ b/302/Assets/Scripts/SCH_AnomalyObject.cs @@ -13,7 +13,7 @@ public class SCH_AnomalyObject : SCH_Behaviour public SCH_AnomalyManager Manager { get; set; } /************ - * messeges * + * messages * ************/ // This function is called when the object becomes enabled and active. diff --git a/302/Assets/Scripts/SCH_Behaviour.cs b/302/Assets/Scripts/SCH_Behaviour.cs index 654a002..a5f9ba7 100644 --- a/302/Assets/Scripts/SCH_Behaviour.cs +++ b/302/Assets/Scripts/SCH_Behaviour.cs @@ -10,7 +10,7 @@ public class SCH_Behaviour : MonoBehaviour public virtual string Name { get; } = "SCH_Behaviour"; /************ - * messeges * + * messages * ************/ // This function is called when the object becomes enabled and active. diff --git a/302/Assets/Scripts/SCH_Random.cs b/302/Assets/Scripts/SCH_Random.cs new file mode 100644 index 0000000..2e1e883 --- /dev/null +++ b/302/Assets/Scripts/SCH_Random.cs @@ -0,0 +1,92 @@ +using System; + +// 일부 메서드는 Python의 구현을 참고해서 구현함 +// https://github.com/python/cpython/blob/3.13/Lib/random.py +public class SCH_Random : Random +{ + /************* + * constants * + *************/ + + // 4.0 * Math.Exp(-0.5) / Math.Sqrt(2.0) + private const double NORMAL_MAGICCONST = 1.7155277699214135367355993366800248622894287109375; + + /*********** + * methods * + ***********/ + + // 조합 + public int[] Combination(int n, int r) + { + int[] candidates = new int[n]; + int[] result = new int[r]; + + for (int i = 0; i < n; i++) { + candidates[i] = i; + } + + for (int i = 0; i < r; i++) { + int index = Next(i, n); + + result[i] = candidates[index]; + if (index != i) { + int tmp = candidates[i]; + + candidates[i] = candidates[index]; + candidates[index] = tmp; + } + } + + System.Array.Sort(result); + + return result; + } + + // 로그 정규 분포 + public double LogNormalDist(double mu, double sigma) + { + return Math.Exp(NormalDist(mu, sigma)); + } + + // 정규 분포 + public double NormalDist(double mu = 0.0, double sigma = 0.0) + { + double u1, u2, z, zz; + + while (true) { + u1 = Sample(); + u2 = 1.0 - Sample(); + z = NORMAL_MAGICCONST * (u1 - 0.5) / u2; + zz = z * z / 4.0; + if (zz <= -Math.Log(u2)) { + break; + } + } + + return mu + z * sigma; + } + + // 삼각 분포 + public double TriangularDist(double low = 0.0, double high = 1.0, double mode = 0.5) + { + double u, c; + + if (high == low) { + return low; + } + + u = Sample(); + c = (mode - low) / (high - low); + + if (u > c) { + double tmp = low; + + u = 1.0 - u; + c = 1.0 - c; + low = high; + high = tmp; + } + + return low + (high - low) * Math.Sqrt(u * c); + } +} diff --git a/302/Assets/Scripts/SCH_Random.cs.meta b/302/Assets/Scripts/SCH_Random.cs.meta new file mode 100644 index 0000000..863601e --- /dev/null +++ b/302/Assets/Scripts/SCH_Random.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7dc0895200fee574da5877e4032eacac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/302/Assets/Scripts/SlideController.cs b/302/Assets/Scripts/SlideController.cs index e1214a7..71c1c39 100644 --- a/302/Assets/Scripts/SlideController.cs +++ b/302/Assets/Scripts/SlideController.cs @@ -1,15 +1,20 @@ -using System.Collections; using System.Collections.Generic; -using System.IO; using UnityEngine; -public class SlideController : MonoBehaviour +public class SlideController : SCH_Behaviour { - // fields + /********** + * fields * + **********/ + + // 텍스처 public Texture2D slideTexture; public Texture2D[] defaultTextures; - private MyRandom _myRandom; + // 난수 + private SCH_Random _random; + + // 내부 수치 private List _trickleXMinList; private List _trickleXMaxList; private List _trickleYPrevList; @@ -18,11 +23,14 @@ public class SlideController : MonoBehaviour private bool _isTrickling; - private int _inputCountMax; - private int _inputCount; - private int _inputIndex; + /************** + * properties * + **************/ - // properties + // 클래스 이름 + public override string Name { get; } = "SlideController"; + + // 화면 색인 private int _index = 0; public int Index { get => _index; @@ -35,37 +43,56 @@ public int Index { } } - // overridden methods - void Start() + /************ + * messages * + ************/ + + // Update is called every frame, if the MonoBehaviour is enabled. + void Update() + { + UpdateTrickling(); + } + + /******************************** + * implmentation: SCH_Behaviour * + ********************************/ + + // 필드를 초기화하는 메서드 + protected override bool InitFields() { - // init. fields for trickling + bool res = base.InitFields(); + + // 난수 + _random = new SCH_Random(); + Log("Initialize `_random`: success"); + + // 흘러내림 관련 필드 _trickleXMinList = new List(); + Log("Initialize `_trickleXMinList`: success"); + _trickleXMaxList = new List(); + Log("Initialize `_trickleXMinList`: success"); + _trickleYPrevList = new List(); + Log("Initialize `_trickleYPrevList`: success"); + _trickleYCurrList = new List(); + Log("Initialize `_trickleYCurrList`: success"); + _trickleSpeedList = new List(); - _myRandom = new MyRandom(); + Log("Initialize `_trickleSpeedList`: success"); _isTrickling = false; + Log("Initialize `_isTrickling`: success"); - // init. fields for changing slides (no need for implementing the game) - _inputCountMax = 0; - for (int l = defaultTextures.Length; l > 0; l /= 10) { - _inputCountMax++; - } - - _inputCount = 0; - _inputIndex = 0; - - ResetSlide(); + return res; } - void Update() - { - UpdateTrickling(); - } + /*************** + * new methods * + ***************/ - // new methods + // 슬라이드를 초기화하는 메서드 public void ResetSlide() { _isTrickling = false; @@ -74,7 +101,7 @@ public void ResetSlide() slideTexture.Apply(); } - // randomly choose the location, width, speed of tricklings + // 흘러내림을 시작하는 메서드 public void StartTrickling() { if (!_isTrickling) { @@ -84,8 +111,8 @@ public void StartTrickling() _trickleYCurrList.Clear(); _trickleSpeedList.Clear(); for (int i = 0; i < 8192; i++) { - int x = _myRandom.Next(2048); - int y = _myRandom.Next(8, 2048); + int x = _random.Next(2048); + int y = _random.Next(8, 2048); if (slideTexture.GetPixel(x, y) == Color.black && slideTexture.GetPixel(x, y - 8) == Color.white) @@ -102,14 +129,14 @@ public void StartTrickling() } } - xMax = (int)_myRandom.TriangularDist(x, xMax, x); - xMin = (int)_myRandom.TriangularDist(xMin, x, x); + xMax = (int)_random.TriangularDist(x, xMax, x); + xMin = (int)_random.TriangularDist(xMin, x, x); _trickleXMaxList.Add(xMax); _trickleXMinList.Add(xMin); _trickleYPrevList.Add(y); _trickleYCurrList.Add(y); - _trickleSpeedList.Add((int)(_myRandom.LogNormalDist(0.0, 1.0) * (xMax - xMin))); + _trickleSpeedList.Add((int)(_random.LogNormalDist(0.0, 1.0) * (xMax - xMin))); } } @@ -117,12 +144,12 @@ public void StartTrickling() } } - // update the slide trickling + // 흘러내림 상태를 갱신하는 메서드 private void UpdateTrickling() { - int xMin, xMax, yMin, yMax; - if (_isTrickling) { + int xMin, xMax, yMin, yMax; + for (int idx = 0; idx < _trickleXMinList.Count; idx++) { _trickleYPrevList[idx] = _trickleYCurrList[idx]; _trickleYCurrList[idx] -= _trickleSpeedList[idx] * Time.deltaTime; @@ -144,102 +171,4 @@ private void UpdateTrickling() slideTexture.Apply(); } } - - // get input to change slides (no need for implementing the game) - private void GetNumberInput() - { - int index = -1; - bool[] keysDown = new bool[] { - Input.GetKeyDown(KeyCode.Alpha0) || Input.GetKeyDown(KeyCode.Keypad0), - Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1), - Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2), - Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3), - Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4), - Input.GetKeyDown(KeyCode.Alpha5) || Input.GetKeyDown(KeyCode.Keypad5), - Input.GetKeyDown(KeyCode.Alpha6) || Input.GetKeyDown(KeyCode.Keypad6), - Input.GetKeyDown(KeyCode.Alpha7) || Input.GetKeyDown(KeyCode.Keypad7), - Input.GetKeyDown(KeyCode.Alpha8) || Input.GetKeyDown(KeyCode.Keypad8), - Input.GetKeyDown(KeyCode.Alpha9) || Input.GetKeyDown(KeyCode.Keypad9) - }; - - if ((index = System.Array.FindIndex(keysDown, x => x)) >= 0) { - if (System.Array.FindIndex(keysDown, index + 1, x => x) >= 0) { - index = -1; - } - } - - if (index >= 0) { - _inputCount++; - _inputIndex = _inputIndex * 10 + index; - - if (_inputIndex >= defaultTextures.Length) { - _inputCount = 1; - _inputIndex = index; - } - - if (_inputCount >= _inputCountMax) { - if (_inputIndex < defaultTextures.Length) { - Index = _inputIndex; - ResetSlide(); - } - - _inputCount = 0; - _inputIndex = 0; - } - } - } -} - -// class for randomness -class MyRandom : System.Random -{ - private double NORMAL_MAGICCONST = 4.0 * System.Math.Exp(-0.5) / System.Math.Sqrt(2.0); - - // implement methods with python's implementation - // https://github.com/python/cpython/blob/3.13/Lib/random.py - - public double TriangularDist(double low = 0.0, double high = 1.0, double mode = 0.5) - { - double u, c; - - if (high == low) { - return low; - } - - u = Sample(); - c = (mode - low) / (high - low); - - if (u > c) { - double tmp = low; - - u = 1.0 - u; - c = 1.0 - c; - low = high; - high = tmp; - } - - return low + (high - low) * System.Math.Sqrt(u * c); - } - - public double NormalDist(double mu = 0.0, double sigma = 0.0) - { - double u1, u2, z, zz; - - while (true) { - u1 = Sample(); - u2 = 1.0 - Sample(); - z = NORMAL_MAGICCONST * (u1 - 0.5) / u2; - zz = z * z / 4.0; - if (zz <= -System.Math.Log(u2)) { - break; - } - } - - return mu + z * sigma; - } - - public double LogNormalDist(double mu, double sigma) - { - return System.Math.Exp(NormalDist(mu, sigma)); - } } diff --git a/302/Assets/Scripts/SlideManager.cs b/302/Assets/Scripts/SlideManager.cs index 951c925..4e842c3 100644 --- a/302/Assets/Scripts/SlideManager.cs +++ b/302/Assets/Scripts/SlideManager.cs @@ -1,15 +1,7 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class SlideManager : MonoBehaviour +public class SlideManager : SCH_Behaviour { - /************* - * constants * - *************/ - - private const string NAME = "SlideManager"; - /********** * fields * **********/ @@ -23,7 +15,7 @@ public class SlideManager : MonoBehaviour public int numStage; // 무작위성 - private SlideRandom _random; + private SCH_Random _random; // 오브젝트 private GameObject _objectLeft; @@ -40,11 +32,15 @@ public class SlideManager : MonoBehaviour * properties * **************/ + // 클래스 인자 public static SlideManager Instance { get; private set; } - /********************** - * overridden methods * - **********************/ + // 클래스 이름 + public override string Name { get; } = "SlideManager"; + + /************ + * messages * + ************/ // Unity calls Awake when an enabled script instance is being loaded. private void Awake() @@ -63,6 +59,35 @@ private void Awake() } } + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 + protected override bool InitFields() + { + bool res = base.InitFields(); + + // _random + _random = new SCH_Random(); + Log("Initialize `_random`: success"); + + // 슬라이드 초기화 + Log("Call `FindSlides` begin"); + if (FindSlides()) { + Log("Call `FindSlides` end: success"); + } else { + Log("Call `FindSlides` end: failed", mode: 1); + res = false; + } + + // _slideList + _slideList = new int[numStage]; + Log("Initialize `_slideList`: success"); + + return res; + } + /*************** * new methods * ***************/ @@ -71,7 +96,7 @@ private void Awake() public void InitSlideList() { _slideList = _random.Combination(numSlide, numStage); - Debug.Log($"[{NAME}] Set `_slideList`: [{string.Join(", ", _slideList)}]"); + Log($"Set `_slideList`: success: [{string.Join(", ", _slideList)}]"); } // 슬라이드를 초기화하는 메서드 @@ -87,7 +112,7 @@ public void SetSlide(int stage) _controllerLeft.ResetSlide(); _controllerRight.ResetSlide(); - Debug.Log($"[{NAME}] Set slides with No. {index} slide."); + Log("Set slide: success: {index}"); } else { _objectLeft.SetActive(false); _objectRight.SetActive(false); @@ -95,34 +120,7 @@ public void SetSlide(int stage) } } - // Private fields를 초기화하는 메서드 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool InitFields() - { - bool res = true; - - // `_random` 초기화 - _random = new SlideRandom(); - Debug.Log($"[{NAME}] Initialized `_random` successfully."); - - // 슬라이드 초기화 - res &= FindSlides(); - - // `_slideList` 초기화 - _slideList = new int[numStage]; - Debug.Log($"[{NAME}] Initialized `_slideList` successfully."); - - return res; - } - // 슬라이드를 찾는 메서드 - // - // 반환 값 - // - true: 찾기 성공 - // - false: 찾기 실패 private bool FindSlides() { bool res = true; @@ -130,70 +128,39 @@ private bool FindSlides() // `_objectLeft` 찾기 _objectLeft = GameObject.Find(nameLeft); if (_objectLeft != null) { - Debug.Log($"[{NAME}] Find `_objectLeft` successfully."); + Log("Find `_objectLeft`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectLeft`."); + Log("Find `_objectLeft`: failed", mode: 1); res = false; } // `_controllerLeft` 찾기 _controllerLeft = _objectLeft.GetComponent(); if (_controllerLeft != null) { - Debug.Log($"[{NAME}] Find `_controllerLeft` successfully."); + Log("Find `_controllerLeft`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_controllerLeft`."); + Log("Find `_controllerLeft`: failed", mode: 1); res = false; } // `_objectRight` 찾기 _objectRight = GameObject.Find(nameRight); if (_objectRight != null) { - Debug.Log($"[{NAME}] Find `_objectRight` successfully."); + Log("Find `_objectRight`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectRight`."); + Log("Find `_objectRight`: failed", mode: 1); res = false; } // `_controllerRight` 찾기 _controllerRight = _objectRight.GetComponent(); if (_controllerRight != null) { - Debug.Log($"[{NAME}] Find `_controllerRight` successfully."); + Log("Find `_controllerRight`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_controllerRight`."); + Log("Find `_controllerRight`: failed", mode: 1); res = false; } return res; } } - -// 무작위 조합을 생성하는 클래스 -class SlideRandom : System.Random -{ - // 무작위 조합을 생성하는 메서드 - public int[] Combination(int n, int r) - { - int[] candidates = new int[n]; - int[] result = new int[r]; - - for (int i = 0; i < n; i++) { - candidates[i] = i; - } - - for (int i = 0; i < r; i++) { - int index = Next(i, n); - - result[i] = candidates[index]; - if (index != i) { - int tmp = candidates[i]; - - candidates[i] = candidates[index]; - candidates[index] = tmp; - } - } - - System.Array.Sort(result); - - return result; - } -} diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs index 3590b0c..78d60a8 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly19_Slide.cs @@ -27,7 +27,7 @@ public class Anomaly19_Slide : SCH_AnomalyInteractable public override string Name { get; } = "Anomaly19_Slide"; /************ - * messeges * + * messages * ************/ // Update is called every frame, if the MonoBehaviour is enabled. diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20Manager.cs index d286cd0..16d57a8 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20Manager.cs @@ -1,155 +1,53 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly20Manager : MonoBehaviour +public class Anomaly20Manager : SCH_AnomalyManager { - /************* - * constants * - *************/ - - private string NAME = "Anomaly20Manager"; - /********** * fields * **********/ - // 오브젝트의 이름 - public string nameGameManager; - - // 이상현상 플레이어, 상호작용 프리팹 + // 프리팹 public GameObject prefabPlayer; public GameObject[] prefabsInteractable; - // 초기화 소요 시간 + // 가변 수치 public float duration; - // 게임 매니저 - private GameManager _manager; - - // 이상현상 플레이어, 상호작용 오브젝트 - private GameObject _objectPlayer; - private List _objectsInteractable; - - /********************** - * overridden methods * - **********************/ + /************** + * properties * + **************/ - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - - if (!InstantiatePrefabs()) { - return; - } - } + // 클래스 이름 + public override string Name { get; } = "Anomaly20Manager"; - /*************** - * new methods * - ***************/ + /************************************** + * implementation: SCH_AnomalyManager * + **************************************/ - // 상호작용 성공 시 처리 함수 - // - // 반환 값 - // - true: 처리 성공 - // - false: 처리 실패 - public void InteractionSuccess() + // 이상현상을 시작하는 메서드 + protected override bool SetAnomaly() { - _manager.SetStageClear(); - - if (!ResetAnomaly()) { - return; - } - } - - // Private fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool InitFields() - { - bool res = true; - - // `_manager` 초기화 - _manager = GameObject.Find(nameGameManager).GetComponent(); - if (_manager != null) { - Debug.Log($"[{NAME}] Find `_manager` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_manager`."); - res = false; - } - - // `_objectsInteractable` 초기화 - _objectsInteractable = new List(); - Debug.Log($"[{NAME}] Initialize `_objectsInteractable` successfully."); - - return res; - } - - // 프리팹을 생성하는 함수 - // - // 반환 값 - // - true: 생성 성공 - // - false: 생성 실패 - private bool InstantiatePrefabs() - { - GameObject obj; - bool res = true; - - _objectsInteractable.Clear(); + bool res = base.SetAnomaly(); + // 플레이어 if (prefabPlayer != null) { - _objectPlayer = Instantiate(prefabPlayer); - Debug.Log($"[{NAME}] Instantiate `prefabPlayer` successfully."); + SCH_AnomalyObject obj = Instantiate(prefabPlayer).GetComponent(); + + obj.Manager = this; + objects.Add(obj); + Log("Set `prefabPlayer`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `prefabPlayer`."); + Log("Set `prefabPlayer`: failed", mode: 1); res = false; } + // 상호작용용 오브젝트 foreach (GameObject prefab in prefabsInteractable) { - if (prefab != null) { - obj = Instantiate(prefab); - obj.GetComponent().Manager = this; - _objectsInteractable.Add(obj); - Debug.Log($"[{NAME}] Instantiate a prefab in `prefabsInteractable` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find prefab in `prefabsInteractable`."); - res = false; - } - } - - return res; - } - - // 이상현상을 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool ResetAnomaly() - { - Anomaly20_Player scriptPlayer; - bool res = true; - - // `_objectPlayer` 초기화 - scriptPlayer = _objectPlayer.GetComponent(); - if (scriptPlayer != null) { - Debug.Log($"[{NAME}] Find `Anomaly20_Player` in `_objectPlayer` successfully."); - StartCoroutine(scriptPlayer.FadeAsync(duration)); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `Anomaly20_Player` in `_objectPlayer`."); - res = false; - } + SCH_AnomalyObject obj = Instantiate(prefab).GetComponent(); - // `_objectsInteractable` 초기화 - foreach (GameObject obj in _objectsInteractable) { - Destroy(obj); - Debug.Log($"[{NAME}] Destroy an object in `_objectsInteractable` successfully."); + obj.Manager = this; + objects.Add(obj); + Log($"Set `{prefab.name}`: success"); } return res; diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs index 9fa8c94..e0042fa 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Interactable.cs @@ -1,95 +1,68 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly20_Interactable : InteractableObject +public class Anomaly20_Interactable : SCH_AnomalyInteractable { - /************* - * constants * - *************/ - - private string NAME = "Anomaly20_Interactable"; - /********** * fields * **********/ - // 오브젝트의 이름 + // 오브젝트 이름 public string namePlayer; public string nameBoard; // 오브젝트 - protected GameObject _objectPlayer; - protected GameObject _objectBoard; + protected GameObject objectPlayer; + protected GameObject objectBoard; /************** * properties * **************/ - // 해당 오브젝트를 생성한 이상현상 매니저 - public Anomaly20Manager Manager { get; set; } - - /********************** - * overridden methods * - **********************/ - - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - } - - // 상호작용 시 실행될 메서드 - public override void OnInteract() - { - if (canInteract) { - canInteract = false; - - base.OnInteract(); + // 클래스 이름 + public override string Name { get; } = "Anomaly20_Interactable"; - if (Manager != null) { - Debug.Log($"[{NAME}] Call `Anomaly20Manager.InteractionSuccess`"); - Manager.InteractionSuccess(); - } else { - Debug.LogWarning($"[{NAME}] `Manager` is not set."); - } - } - } - - /*************** - * new methods * - ***************/ + /********************************* + * implementation: SCH_Behaviour * + *********************************/ - // Protected fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - protected virtual bool InitFields() + // 필드를 초기화하는 메서드 + protected override bool InitFields() { - bool res = true; + bool res = base.InitFields(); - // `_objectPlayer` 초기화 - _objectPlayer = GameObject.Find(namePlayer); - if (_objectPlayer != null) { - Debug.Log($"[{NAME}] Find `_objectPlayer` successfully."); + // objectPlayer + objectPlayer = GameObject.Find(namePlayer); + if (objectPlayer != null) { + Log("Initialize `objectPlayer`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectPlayer`."); + Log("Initialize `objectPlayer`: failed", mode: 1); res = false; } - // `_objectBoard` 초기화 - _objectBoard = GameObject.Find(nameBoard); - if (_objectBoard != null) { - Debug.Log($"[{NAME}] Find `_objectBoard` successfully."); + // objectBoard + objectBoard = GameObject.Find(nameBoard); + if (objectBoard != null) { + Log("Initialize `objectBoard`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectBoard`."); + Log("Initialize `objectBoard`: failed", mode: 1); res = false; } return res; } + + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); + + Destroy(gameObject); + Log("Destroy game object: success"); + + return res; + } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableBack.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableBack.cs index bc67907..2b03135 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableBack.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableBack.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class Anomaly20_InteractableBack : Anomaly20_Interactable @@ -8,21 +6,28 @@ public class Anomaly20_InteractableBack : Anomaly20_Interactable * fields * **********/ - // `z` 좌표 범위 + // 가변 수치 public float zMin; public float zMax; - // `x` 좌표 + // 내부 수치 private float _x; - /********************** - * overridden methods * - **********************/ + /************** + * properties * + **************/ + + // 클래스 이름 + public override string Name { get; } = "Anomaly20_InteractableBack"; + + /************ + * messages * + ************/ // Update is called every frame, if the MonoBehaviour is enabled. void Update() { - float z = _objectPlayer.transform.position.z; + float z = objectPlayer.transform.position.z; if (z >= zMin && z <= zMax) { transform.position = new Vector3(_x, transform.position.y, z); @@ -31,16 +36,18 @@ void Update() } } - // Protected fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 protected override bool InitFields() { bool res = base.InitFields(); - _x = _objectBoard.transform.position.x + 0.01f; + // _x + _x = objectBoard.transform.position.x + 0.01f; + Log("Initialize `_x`: success"); return res; } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableFront.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableFront.cs index a584ea2..ca6262e 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableFront.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableFront.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class Anomaly20_InteractableFront : Anomaly20_Interactable @@ -8,21 +6,28 @@ public class Anomaly20_InteractableFront : Anomaly20_Interactable * fields * **********/ - // `z` 좌표 범위 + // 가변 수치 public float zMin; public float zMax; - // `x` 좌표 + // 내부 수치 private float _x; - /********************** - * overridden methods * - **********************/ + /************** + * properties * + **************/ + + // 클래스 이름 + public override string Name { get; } = "Anomaly20_InteractableFront"; + + /************ + * messages * + ************/ // Update is called every frame, if the MonoBehaviour is enabled. void Update() { - float z = _objectPlayer.transform.position.z; + float z = objectPlayer.transform.position.z; if (z >= zMin && z <= zMax) { transform.position = new Vector3(_x, transform.position.y, z); @@ -31,16 +36,18 @@ void Update() } } - // Protected fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 protected override bool InitFields() { bool res = base.InitFields(); - _x = _objectBoard.transform.position.x - 0.01f; + // _x + _x = objectBoard.transform.position.x - 0.01f; + Log("Initialize `_x`: success"); return res; } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableRight.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableRight.cs index 51b4331..5ca69ce 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableRight.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_InteractableRight.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class Anomaly20_InteractableRight : Anomaly20_Interactable @@ -8,23 +6,30 @@ public class Anomaly20_InteractableRight : Anomaly20_Interactable * fields * **********/ - // `x` 좌표 범위 + // 가변 수치 public float x1Min; public float x1Max; public float x2Min; public float x2Max; - // `z` 좌표 + // 내부 수치 private float _z; - /********************** - * overridden methods * - **********************/ + /************** + * properties * + **************/ + + // 클래스 이름 + public override string Name { get; } = "Anomaly20_InteractableRight"; + + /************ + * messages * + ************/ // Update is called every frame, if the MonoBehaviour is enabled. void Update() { - float x = _objectPlayer.transform.position.x; + float x = objectPlayer.transform.position.x; if (x >= x1Min && x <= x1Max || x >= x2Min && x <= x2Max) { transform.position = new Vector3(x, transform.position.y, _z); @@ -33,16 +38,18 @@ void Update() } } - // Protected fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 protected override bool InitFields() { bool res = base.InitFields(); - _z = _objectBoard.transform.position.z + 0.01f; + // _z + _z = objectBoard.transform.position.z + 0.01f; + Log("Initialize `_z`: success"); return res; } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Player.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Player.cs index a23c116..c8e4b07 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Player.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly20_Player.cs @@ -1,37 +1,31 @@ using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly20_Player : MonoBehaviour +public class Anomaly20_Player : SCH_AnomalyObject { - /************* - * constants * - *************/ - - private string NAME = "Anomaly20_Player"; - /********** * fields * **********/ - // 오브젝트의 이름 + // 오브젝트 이름 public string namePlayer; - // 플레이어 오브젝트 + // 가변 수치 + public float duration; + + // 오브젝트 private GameObject _objectPlayer; - /********************** - * overridden methods * - **********************/ + /************** + * properties * + **************/ - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - } + // 클래스 이름 + public override string Name { get; } = "Anomaly20_Player"; + + /************ + * messages * + ************/ // Update is called every frame, if the MonoBehaviour is enabled. void Update() @@ -42,26 +36,75 @@ void Update() transform.rotation = Quaternion.Euler(0.0f, playerTransform.rotation.eulerAngles.y, 0.0f); } - /*************** - * new methods * - ***************/ + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 + protected override bool InitFields() + { + bool res = base.InitFields(); + + // _objectPlayer + _objectPlayer = GameObject.Find(namePlayer); + if (_objectPlayer != null) { + Log("Initialize `_objectPlayer`: success"); + } else { + Log("Initialize `_objectPlayer`: failed", mode: 1); + res = false; + } + + return res; + } + + /************************************* + * implementation: SCH_AnomalyObject * + *************************************/ + + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); + + Log("Call `FadeAsync` asynchronously"); + StartCoroutine(FadeAsync()); + + return res; + } + + /*********** + * methods * + ***********/ - // 지속시간 동안 투명해지다가 사라지는 함수 - public IEnumerator FadeAsync(float duration) + // 지속시간 동안 투명해지다가 사라지는 메서드 + private IEnumerator FadeAsync() { - Renderer[] renderers = gameObject.GetComponentsInChildren(); - Color color; + Renderer[] renderers = GetComponentsInChildren(); float timeStart = Time.time; - float time, alpha; + float time; + + foreach (Renderer renderer in renderers) { + foreach (Material material in renderer.materials) { + material.renderQueue = 3000; + material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); + material.DisableKeyword("_ALPHATEST_ON"); + material.EnableKeyword("_ALPHABLEND_ON"); + material.SetFloat("_Mode", 2); + material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); + material.SetInt("_ZWrite", 0); + } + } yield return null; while ((time = Time.time - timeStart) < duration) { - alpha = 1.0f - time / duration; + float alpha = 1.0f - time / duration; foreach (Renderer renderer in renderers) { foreach (Material material in renderer.materials) { - color = material.color; + Color color = material.color; + color.a = alpha; material.color = color; } @@ -72,25 +115,4 @@ public IEnumerator FadeAsync(float duration) Destroy(gameObject); } - - // Private fields를 초기화하는 함수 - // - // 반환 값 - // - true: 초기화 성공 - // - false: 초기화 실패 - private bool InitFields() - { - bool res = true; - - // `_objectPlayer` 초기화 - _objectPlayer = GameObject.Find(namePlayer); - if (_objectPlayer != null) { - Debug.Log($"[{NAME}] Find `_objectPlayer` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectPlayer`."); - res = false; - } - - return res; - } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23Manager.cs index 839c7d0..7ed8764 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23Manager.cs @@ -1,126 +1,80 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly23Manager : MonoBehaviour +public class Anomaly23Manager : SCH_AnomalyManager { - /************* - * constants * - *************/ - - private const string NAME = "Anomaly23Manager"; - /********** * fields * **********/ - // 오브젝트의 이름 - public string nameGameManager; + // 오브젝트 이름 public string nameLaptop; // 프리팹 public GameObject prefabGhost; - // 게임 메니저 - private GameManager _manager; + // 오브젝트 + private SCH_AnomalyObject _objectLaptop; - // 노트북 스크립트 - private LaptopScreenController _scriptLaptop; + /************** + * properties * + **************/ - // 노트북 화면 색인 - private int _indexLaptop; + // 클래스 이름 + public override string Name { get; } = "Anomaly23Manager"; - /********************** - * overridden methods * - **********************/ - - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - - if (!SetAnomaly()) { - return; - } - } - - /*************** - * new methods * - ***************/ - - // 상호작용 성공 시 처리 메서드 - public void InteractionSuccess() - { - _manager.SetStageClear(); - - if (!ResetAnomaly()) { - return; - } - } + /********************************* + * implementation: SCH_Behaviour * + *********************************/ - // Private fields를 초기화하는 메서드 - private bool InitFields() + // 필드를 초기화하는 메서드 + protected override bool InitFields() { - bool res = true; + bool res = base.InitFields(); - // `_manager` 초기화 - _manager = GameObject.Find(nameGameManager).GetComponent(); - if (_manager != null) { - Debug.Log($"[{NAME}] Find `_manager` successfully."); + // _objectLaptop + _objectLaptop = GameObject.Find(nameLaptop).GetComponent(); + if (_objectLaptop != null) { + objects.Add(_objectLaptop); + Log("Initialize `_objectLaptop`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_manager`."); - res = false; - } - - // `_scriptLaptop` 초기화 - _scriptLaptop = GameObject.Find(nameLaptop).GetComponent(); - if (_scriptLaptop != null) { - Debug.Log($"[{NAME}] Find `_scriptLaptop` successfully."); - } else { - Debug.LogWarning($"[{NAME}] Cannot find `_scriptLaptop`."); + Log("Initialize `_objectLaptop`: failed", mode: 1); res = false; } return res; } + /************************************** + * implementation: SCH_AnomalyManager * + **************************************/ + // 이상현상을 시작하는 메서드 - private bool SetAnomaly() + protected override bool SetAnomaly() { - bool res = true; + bool res = base.SetAnomaly(); - // 노트북 화면 - if (_scriptLaptop != null) { - _indexLaptop = _scriptLaptop.Index; - _scriptLaptop.ChangeScreen(12); + // 노트북 + if (_objectLaptop != null) { + _objectLaptop.enabled = true; + _objectLaptop.Manager = this; + Log("Set `_objectLaptop`: success"); } else { + Log("Set `_objectLaptop`: failed", mode: 1); res = false; } // 유령 if (prefabGhost != null) { - Debug.Log($"[{NAME}] Find `prefabGhost` successfully."); - Instantiate(prefabGhost).GetComponent().Manager = this; + SCH_AnomalyObject obj = Instantiate(prefabGhost).GetComponent(); + + obj.Manager = this; + objects.Add(obj); + Log("Set `prefabGhost`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `prefabGhost`."); + Log("Set `prefabGhost`: failed", mode: 1); res = false; } - if (res) { - Debug.Log($"[{NAME}] Anomaly is set."); - } - return res; } - - // 이상현상을 초기화하는 메서드 - private bool ResetAnomaly() - { - _scriptLaptop.ChangeScreen(_indexLaptop); - - return true; - } } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs index 0760ec1..d97a175 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs @@ -1,24 +1,18 @@ using System.Collections; -using System.Collections.Generic; using UnityEngine; -public class Anomaly23_Ghost : MonoBehaviour +[RequireComponent(typeof(Animator))] +public class Anomaly23_Ghost : SCH_AnomalyObject { - /************* - * constants * - *************/ - - private const string NAME = "Anomaly23Manager"; - /********** * fields * **********/ - // 오브젝트의 이름 + // 오브젝트 이름 public string namePlayer; public string nameCamera; - // 수치 + // 가변 수치 public Vector3 position; public float speedInit; public float speedDelta; @@ -32,45 +26,33 @@ public class Anomaly23_Ghost : MonoBehaviour private GameObject _objectPlayer; private GameObject _objectCamera; - // 수치 + // 내부 수치 private float _timeStart; - - // 플래그 private bool _isChasing; /************** * properties * **************/ - public Anomaly23Manager Manager { get; set; } + public override string Name { get; } = "Anomaly23_Ghost"; - /********************** - * overridden methods * - **********************/ - - // Start is called on the frame when a script is enabled just - // before any of the Update methods are called the first time. - void Start() - { - if (!InitFields()) { - return; - } - - transform.position = position; - } + /************ + * messages * + ************/ // OnCollisionEnter is called when this collider/rigidbody // has begun touching another rigidbody/collider. void OnCollisionEnter(Collision other) { if (other.collider.CompareTag("Player") && _isChasing) { - PlayerController scriptPlayer = _objectPlayer.GetComponent(); + PlayerController script = _objectPlayer.GetComponent(); - if (scriptPlayer != null) { - Debug.Log($"[{NAME}] Find `scriptPlayer` successfully."); - scriptPlayer.GameOver(); + if (script != null) { + Log("Call `script.GameOver` begin"); + script.GameOver(); + Log("Call `script.GameOver` end"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `scriptPlayer`."); + Log("Call `script.GameOver`: failed", mode: 1); } } } @@ -92,72 +74,94 @@ void Update() _animator.SetFloat("Speed", speed); } else { _isChasing = false; + + Log("Call `Manager.InteractionSuccess` begin"); Manager.InteractionSuccess(); - StartCoroutine(FadeAsync()); + Log("Call `Manager.InteractionSuccess` end"); + + Log("Call `BlowAsync` asynchronously"); + StartCoroutine(BlowAsync()); } } } - /*************** - * new methods * - ***************/ + /********************************* + * implementation: SCH_Behaviour * + *********************************/ - // Private fields를 초기화하는 메서드 - private bool InitFields() + // 필드를 초기화하는 메서드 + protected override bool InitFields() { - bool res = true; + bool res = base.InitFields(); - // `_animator` 초기화 - _animator = gameObject.GetComponent(); + // _animator + _animator = GetComponent(); if (_animator != null) { - Debug.Log($"[{NAME}] Find `_animator` successfully."); + Log("Initialize `_animator`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_animator`."); + Log("Initialize `_animator`: failed", mode: 1); res = false; } - // `_objectPlayer` 초기화 + // _objectPlayer _objectPlayer = GameObject.Find(namePlayer); if (_objectPlayer != null) { - Debug.Log($"[{NAME}] Find `_objectPlayer` successfully."); + Log("Initialize `_objectPlayer`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectPlayer`."); + Log("Initialize `_objectPlayer`: failed", mode: 1); res = false; } - // `_objectCamera` 초기화 + // _objectCamera _objectCamera = GameObject.Find(nameCamera); if (_objectCamera != null) { - Debug.Log($"[{NAME}] Find `_objectCamera` successfully."); + Log("Initialize `_objectCamera`: success"); } else { - Debug.LogWarning($"[{NAME}] Cannot find `_objectCamera`."); + Log("Initialize `_objectCamera`: failed", mode: 1); res = false; } - // `_timeStart` 초기화 + // _timeStart _timeStart = Time.time; - Debug.Log($"[{NAME}] Initialize `_timeStart` successfully: {_timeStart}."); + Log($"Initialize `_timeStart`: success: {_timeStart}"); - // `_isChasing` 초기화 + // _isChasing _isChasing = true; - Debug.Log($"[{NAME}] Initialize `_isChasing` successfully: {_isChasing}."); + Log("Initialize `_isChasing`: success"); return res; } - // 소멸 메서드 - private IEnumerator FadeAsync() + /************************************* + * implementation: SCH_AnomalyObject * + *************************************/ + + // 이상현상을 시작하는 메서드 + protected override bool SetAnomaly() { - Renderer[] renderers = gameObject.GetComponentsInChildren(); - GhostRandom myRandom = new GhostRandom(); + bool res = base.SetAnomaly(); + + transform.position = position; + Log("Set position: success"); + + return res; + } + + /*********** + * methods * + ***********/ + + // 지속시간 동안 바람빠지다가 사라지는 메서드 + private IEnumerator BlowAsync() + { + SCH_Random random = new SCH_Random(); float timeStart = Time.time; float time; - float scale; yield return new WaitForSeconds(0.1f); while ((time = Time.time - timeStart) < durationFade) { - scale = (float)(myRandom.LogNormalDist(0.0, 1.0) * 2.0); + float scale = (float)(random.LogNormalDist(0.0, 1.0) * 1.5); transform.rotation = Random.rotation; transform.localScale = new Vector3(scale, scale, scale); @@ -168,34 +172,3 @@ private IEnumerator FadeAsync() Destroy(gameObject); } } - -// 난수 클래스 -class GhostRandom : System.Random -{ - private double NORMAL_MAGICCONST = 4.0 * System.Math.Exp(-0.5) / System.Math.Sqrt(2.0); - - // implement methods with python's implementation - // https://github.com/python/cpython/blob/3.13/Lib/random.py - - public double NormalDist(double mu = 0.0, double sigma = 0.0) - { - double u1, u2, z, zz; - - while (true) { - u1 = Sample(); - u2 = 1.0 - Sample(); - z = NORMAL_MAGICCONST * (u1 - 0.5) / u2; - zz = z * z / 4.0; - if (zz <= -System.Math.Log(u2)) { - break; - } - } - - return mu + z * sigma; - } - - public double LogNormalDist(double mu, double sigma) - { - return System.Math.Exp(NormalDist(mu, sigma)); - } -} diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs new file mode 100644 index 0000000..2967700 --- /dev/null +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs @@ -0,0 +1,104 @@ +using UnityEngine; + +[RequireComponent(typeof(LaptopScreenController))] +public class Anomaly23_Laptop : SCH_AnomalyObject +{ + /********** + * fields * + **********/ + + // 가변 수치 + public int anomalyScreenIndex; + + // 노트북 컨트롤러 + private LaptopScreenController _script; + + // 내부 수치 + private int _index; + + /************** + * properties * + **************/ + + // 클래스 이름 + public override string Name { get; } = "Anomaly23_Laptop"; + + /************ + * messages * + ************/ + + // Update is called every frame, if the MonoBehaviour is enabled. + void Update() + { + if (_script != null && _script.Index != anomalyScreenIndex) { + _script.ChangeScreen(anomalyScreenIndex); + } + } + + /********************************* + * implementation: SCH_Behaviour * + *********************************/ + + // 필드를 초기화하는 메서드 + protected override bool InitFields() + { + bool res = base.InitFields(); + + // _script + _script = GetComponent(); + if (_script != null) { + Log("Initialize `_script`: success"); + } else { + Log("Initialize `_script`: failed", mode: 1); + res = false; + } + + // _index + _index = 0; + Log("Initialize `_index`: success"); + + return res; + } + + /************************************* + * implementation: SCH_AnomalyObject * + *************************************/ + + // 이상현상을 시작하는 메서드 + protected override bool SetAnomaly() + { + bool res = base.SetAnomaly(); + + // 노트북 화면 + if (_script != null) { + _index = _script.Index; + _script.ChangeScreen(anomalyScreenIndex); + Log("Set laptop screen: success"); + } else { + Log("Set laptop screen: failed", mode: 1); + res = false; + } + + return res; + } + + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); + + // 노트북 화면 + if (_script != null) { + _script.ChangeScreen(_index); + Log("Reset laptop screen: success"); + } else { + Log("Reset laptop screen: failed", mode: 1); + res = false; + } + + // 실행 종료 + enabled = false; + + return res; + } +} diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs.meta b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs.meta new file mode 100644 index 0000000..ff1536a --- /dev/null +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Laptop.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d755543348868a045964c1da73713696 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 8d84a857973cbc4a736b2234f1d5639824121ae3 Mon Sep 17 00:00:00 2001 From: Prown0 <100746335+Prown0@users.noreply.github.com> Date: Wed, 27 Nov 2024 04:31:51 +0900 Subject: [PATCH 3/3] Readjust some variables & bug fix --- 302/Assets/Prefabs/Anomaly01/sittingGirl.prefab | 3 +-- 302/Assets/Scripts/SlideManager.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/302/Assets/Prefabs/Anomaly01/sittingGirl.prefab b/302/Assets/Prefabs/Anomaly01/sittingGirl.prefab index f2aa549..314514a 100644 --- a/302/Assets/Prefabs/Anomaly01/sittingGirl.prefab +++ b/302/Assets/Prefabs/Anomaly01/sittingGirl.prefab @@ -881,9 +881,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 13b29b2cac673a5419b45e5853d126ec, type: 3} m_Name: m_EditorClassIdentifier: - nameCameraMain: Main Camera prompt: - distanceInteractionMax: 2 + distanceInteractionMax: 4 --- !u!1 &3815843599304427073 GameObject: m_ObjectHideFlags: 0 diff --git a/302/Assets/Scripts/SlideManager.cs b/302/Assets/Scripts/SlideManager.cs index 4e842c3..830402d 100644 --- a/302/Assets/Scripts/SlideManager.cs +++ b/302/Assets/Scripts/SlideManager.cs @@ -112,7 +112,7 @@ public void SetSlide(int stage) _controllerLeft.ResetSlide(); _controllerRight.ResetSlide(); - Log("Set slide: success: {index}"); + Log($"Set slide: success: {index}"); } else { _objectLeft.SetActive(false); _objectRight.SetActive(false);