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/Scripts/Events/LightsOffByGhostEvent.cs b/Assets/Scripts/Events/LightsOffByGhostEvent.cs index 696d998a..0ba13ce9 100644 --- a/Assets/Scripts/Events/LightsOffByGhostEvent.cs +++ b/Assets/Scripts/Events/LightsOffByGhostEvent.cs @@ -2,5 +2,16 @@ 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 diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index 5fb2cc95..73b2bb45 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; @@ -38,6 +46,22 @@ private void toggleLights() lightSource.enabled = lights; } } + + private void setLights(bool light) + { + foreach (Light lightSource in lightsources) + { + lightSource.enabled = light; + } + if(light) + { + currentState = SwitchState.On; + } + else + { + currentState = SwitchState.Off; + } + } private void onLightSwitch() { @@ -45,4 +69,11 @@ private void onLightSwitch() 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..79f0022c 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -27,6 +27,7 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri playerState = PlayerState.InDark; EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsTurnedOffByGhost); EventService.Instance.OnKeyPickedUp.AddListener(onKeysPickedUp); } @@ -34,6 +35,8 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri { EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch); EventService.Instance.OnKeyPickedUp.RemoveListener(onKeysPickedUp); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsTurnedOffByGhost); + } public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted); @@ -87,6 +90,12 @@ private void onLightSwitch() else PlayerState = PlayerState.InDark; } + + private void onLightsTurnedOffByGhost() + { + playerState = PlayerState.InDark; + } + private void onKeysPickedUp(int keys) { KeysEquipped = keys; diff --git a/Assets/Scripts/UI/GameUIView.cs b/Assets/Scripts/UI/GameUIView.cs index 3f22cdc9..90e3df2b 100644 --- a/Assets/Scripts/UI/GameUIView.cs +++ b/Assets/Scripts/UI/GameUIView.cs @@ -24,9 +24,13 @@ private void OnEnable() tryAgainButton.onClick.AddListener(onTryAgainButtonClicked); quitButton.onClick.AddListener(onQuitButtonClicked); EventService.Instance.OnKeyPickedUp.AddListener(updateKeyText); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(setRedVignette); + } + private void OnDisable() + { + EventService.Instance.OnKeyPickedUp.RemoveListener(updateKeyText); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(setRedVignette); } - private void OnDisable() => EventService.Instance.OnKeyPickedUp.RemoveListener(updateKeyText); - public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1); private void updateKeyText(int keys) => keysFoundText.SetText($"Keys Found: {keys}/ 3"); diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 3d6c323f..a7a5887e 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -72,13 +72,13 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.ide.visualstudio": "2.0.17", - "com.unity.ide.rider": "3.0.18", + "com.unity.ide.visualstudio": "2.0.16", + "com.unity.ide.rider": "3.0.15", "com.unity.ide.vscode": "1.2.5", "com.unity.editorcoroutines": "1.0.0", - "com.unity.performance.profile-analyzer": "1.2.2", + "com.unity.performance.profile-analyzer": "1.1.1", "com.unity.test-framework": "1.1.31", - "com.unity.testtools.codecoverage": "1.2.2" + "com.unity.testtools.codecoverage": "1.0.1" } }, "com.unity.ide.rider": { @@ -114,7 +114,7 @@ "url": "https://packages.unity.com" }, "com.unity.performance.profile-analyzer": { - "version": "1.2.2", + "version": "1.1.1", "depth": 1, "source": "registry", "dependencies": {}, @@ -139,7 +139,7 @@ "url": "https://packages.unity.com" }, "com.unity.testtools.codecoverage": { - "version": "1.2.2", + "version": "1.0.1", "depth": 1, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index bca3d022..1f883d75 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.21f1 -m_EditorVersionWithRevision: 2021.3.21f1 (1b156197d683) +m_EditorVersion: 2021.3.10f1 +m_EditorVersionWithRevision: 2021.3.10f1 (1c7d0df0160b)