From fb373ebeb99db3b4b7fa78c50bc74a31264a2be6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-6U5DPEC\\koush" Date: Sat, 21 Sep 2024 18:37:13 +0530 Subject: [PATCH 1/2] Implemented trigger for LightsOffByGhost event. --- Assets/Art/Prefabs/House.prefab | 2 +- Assets/Scenes/GameScene.unity | 71 +------------------ .../Scripts/Events/LightsOffByGhostEvent.cs | 12 ++++ 3 files changed, 14 insertions(+), 71 deletions(-) diff --git a/Assets/Art/Prefabs/House.prefab b/Assets/Art/Prefabs/House.prefab index a3aa13a1..5f1aa969 100644 --- a/Assets/Art/Prefabs/House.prefab +++ b/Assets/Art/Prefabs/House.prefab @@ -13297,7 +13297,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: keysRequiredToTrigger: 1 - soundToPlay: 4 + soundType: 4 --- !u!1 &7927258282318190006 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 977b4717..c6ed6eb8 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -2228,30 +2228,6 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: - - target: {fileID: 667724600942481522, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 2005042993226810447, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 2196900891731812331, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 3492344741786150290, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: gameUIView - value: - objectReference: {fileID: 2132082659} - - target: {fileID: 3492344741786150290, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 3542250534102899431, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - target: {fileID: 5325831579243014017, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} propertyPath: m_RootOrder value: 0 @@ -2296,56 +2272,11 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 6752750673420198879, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 6752750673610657977, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 6752750674094668609, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - target: {fileID: 8090694453975587124, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} propertyPath: m_Name value: House objectReference: {fileID: 0} - - target: {fileID: 8410985323073775251, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 8410985323525627662, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 8410985323951209738, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 8410985324532678281, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 8410985324693255829, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 8410985324735834856, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - - target: {fileID: 8410985324760981946, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - propertyPath: soundService - value: - objectReference: {fileID: 203687011} - m_RemovedComponents: - - {fileID: 8410985324760981946, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - - {fileID: 6752750673610657977, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - - {fileID: 8410985324735834856, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - - {fileID: 3542250534102899431, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} - - {fileID: 6752750674094668609, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} + m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3} --- !u!65 &8225950124344110251 BoxCollider: diff --git a/Assets/Scripts/Events/LightsOffByGhostEvent.cs b/Assets/Scripts/Events/LightsOffByGhostEvent.cs index 696d998a..0f6edb92 100644 --- a/Assets/Scripts/Events/LightsOffByGhostEvent.cs +++ b/Assets/Scripts/Events/LightsOffByGhostEvent.cs @@ -2,5 +2,17 @@ public class LightsOffByGhostEvent : MonoBehaviour { + [SerializeField] private int keysRequiredToTrigger; + [SerializeField] private SoundType soundType; + + private void OnTriggerEnter(Collider other) + { + if(other.GetComponent() != null && keysRequiredToTrigger == GameService.Instance.GetPlayerController().KeysEquipped) + { + EventService.Instance.OnLightsOffByGhostEvent.InvokeEvent(); + GameService.Instance.GetSoundView().PlaySoundEffects(soundType); + this.enabled = false; + } + } } \ No newline at end of file From 5f7c44229b5f17fb7d5c931f7485ba7b7d578ac6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-6U5DPEC\\koush" Date: Sun, 22 Sep 2024 00:32:02 +0530 Subject: [PATCH 2/2] Implemented onLightsTurnedOffByGhost event in LightSwitch view and PlayerController. --- .../Scripts/Interactables/LightSwitchView.cs | 32 +++++++++++++++++-- Assets/Scripts/Player/PlayerController.cs | 5 +++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index 5fb2cc95..8480c85c 100644 --- a/Assets/Scripts/Interactables/LightSwitchView.cs +++ b/Assets/Scripts/Interactables/LightSwitchView.cs @@ -8,9 +8,17 @@ public class LightSwitchView : MonoBehaviour, IInteractable [SerializeField] private List lightsources = new List(); private SwitchState currentState; - private void OnEnable() => EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + private void OnEnable() + { + EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightTurnedOffByGhost); + } - private void OnDisable() => EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch); + private void OnDisable() + { + EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightTurnedOffByGhost); + } private void Start() => currentState = SwitchState.Off; @@ -39,10 +47,30 @@ private void toggleLights() } } + private void setLights(bool lights) + { + foreach (Light lightSource in lightsources) + { + lightSource.enabled = lights; + } + + if (lights) + currentState = SwitchState.On; + else + currentState = SwitchState.Off; + } + private void onLightSwitch() { toggleLights(); GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.SwitchSound); GameService.Instance.GetInstructionView().HideInstruction(); } + + private void onLightTurnedOffByGhost() + { + setLights(false); + GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.SwitchSound); + GameService.Instance.GetInstructionView().ShowInstruction(InstructionType.LightsOff); + } } diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index d89709d0..2685e3ac 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -27,12 +27,14 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri playerState = PlayerState.InDark; EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsTurnedOffByGhost); EventService.Instance.OnKeyPickedUp.AddListener(onKeysPickedUp); } ~PlayerController() { EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsTurnedOffByGhost); EventService.Instance.OnKeyPickedUp.RemoveListener(onKeysPickedUp); } public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted); @@ -87,6 +89,9 @@ private void onLightSwitch() else PlayerState = PlayerState.InDark; } + + private void onLightsTurnedOffByGhost() => PlayerState = PlayerState.InDark; + private void onKeysPickedUp(int keys) { KeysEquipped = keys;