diff --git a/Assets/Scripts/Events.meta b/Assets/Scripts/Events.meta index 571ab406..682589a1 100644 --- a/Assets/Scripts/Events.meta +++ b/Assets/Scripts/Events.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 +<<<<<<< HEAD +guid: 9848fe8237deaf542bdfbaf041b885ae +======= guid: dd99e40aa78884b4a82e24941c389e05 +>>>>>>> 7af302e5914538fcafa3dceb0b3c8164f4f00ac0 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Events/EventController.cs b/Assets/Scripts/Events/EventController.cs index da1926b4..45e79dce 100644 --- a/Assets/Scripts/Events/EventController.cs +++ b/Assets/Scripts/Events/EventController.cs @@ -1,10 +1,28 @@ using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EventController +{ + public Action baseEvent; + + public void AddListener(Action Listener) => baseEvent += Listener; + + public void RemoveListener(Action Listener) => baseEvent -= Listener; + + public void InvokeEvent(T type) => baseEvent?.Invoke(type); + +} public class EventController { public Action baseEvent; - public void AddListener(Action listener) => baseEvent += listener; - public void RemoveListener(Action listener) => baseEvent -= listener; + + public void AddListener(Action Listener) => baseEvent += Listener; + + public void RemoveListener(Action Listener) => baseEvent -= Listener; + public void InvokeEvent() => baseEvent?.Invoke(); -} +} diff --git a/Assets/Scripts/Events/EventController.cs.meta b/Assets/Scripts/Events/EventController.cs.meta index d43c10f3..538720cb 100644 --- a/Assets/Scripts/Events/EventController.cs.meta +++ b/Assets/Scripts/Events/EventController.cs.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 +<<<<<<< HEAD +guid: 2349e3744fb7a514c8f4dad3859ae586 +======= guid: 0bc029dcd0768aa458c3576f7406f7c9 +>>>>>>> 7af302e5914538fcafa3dceb0b3c8164f4f00ac0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Interactables/KeyView.cs b/Assets/Scripts/Interactables/KeyView.cs index 9e5b0238..a49e2fec 100644 --- a/Assets/Scripts/Interactables/KeyView.cs +++ b/Assets/Scripts/Interactables/KeyView.cs @@ -5,11 +5,11 @@ public class KeyView : MonoBehaviour, IInteractable [SerializeField] GameUIView gameUIView; public void Interact() { + int currentKey = GameService.Instance.GetPlayerController().KeysEquipped; GameService.Instance.GetInstructionView().HideInstruction(); GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.KeyPickUp); - GameService.Instance.GetPlayerController().KeysEquipped++; - gameUIView.UpdateKeyText(); - + currentKey++; + EventService.Instance.OnKeyPickedUp.InvokeEvent(currentKey); gameObject.SetActive(false); } } diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index 7449d10f..c0c147ea 100644 --- a/Assets/Scripts/Interactables/LightSwitchView.cs +++ b/Assets/Scripts/Interactables/LightSwitchView.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using UnityEditor.MPE; using UnityEngine; using static LightSwitchView; @@ -8,14 +7,15 @@ public class LightSwitchView : MonoBehaviour, IInteractable { [SerializeField] private List lightsources = new List(); private SwitchState currentState; + public static event Action lightToggledAction; - private void OnEnable() => EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + private void OnEnable() => EventService.Instance.lightToggledAction.AddListener(onLightSwitch); - private void OnDisable() => EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch); + private void OnDisable() => EventService.Instance.lightToggledAction.RemoveListener(onLightSwitch); private void Start() => currentState = SwitchState.Off; - public void Interact() => EventService.Instance.OnLightSwitchToggled.InvokeEvent(); + public void Interact() => EventService.Instance.lightToggledAction.InvokeEvent(); private void toggleLights() { diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index a7febc8b..f7fab7e0 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -24,15 +24,19 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri this.playerView.SetController(this); this.playerScriptableObject = playerScriptableObject; this.playerScriptableObject.KeysEquipped = 0; - playerState = PlayerState.InDark; - EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + + playerState = PlayerState.InDark; + EventService.Instance.lightToggledAction.AddListener(LightSwitchToggled); + EventService.Instance.OnKeyPickedUp.AddListener(onKeysPickedUp); } - ~PlayerController() - { - EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch); + ~PlayerController() { + EventService.Instance.lightToggledAction.RemoveListener(LightSwitchToggled); + EventService.Instance.OnKeyPickedUp.RemoveListener(onKeysPickedUp); } + + public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted); public void Jump(Rigidbody playerRigidbody, Transform transform) @@ -77,12 +81,20 @@ private void calculatePositionRotation(Rigidbody playerRigidbody, Transform tran rotation = playerRigidbody.rotation * Quaternion.Euler(lookRotation); position = (transform.position) + (velocity * movement) * Time.fixedDeltaTime; } - - private void onLightSwitch() + private void LightSwitchToggled() { if (PlayerState == PlayerState.InDark) + { PlayerState = PlayerState.None; + } else + { PlayerState = PlayerState.InDark; + } + } + + private void onKeysPickedUp(int keys) + { + KeysEquipped = keys; } } diff --git a/Assets/Scripts/Service/EventService.cs b/Assets/Scripts/Service/EventService.cs index fb22c2b5..f24283a5 100644 --- a/Assets/Scripts/Service/EventService.cs +++ b/Assets/Scripts/Service/EventService.cs @@ -1,4 +1,9 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + public class EventService { private static EventService instance; @@ -14,10 +19,13 @@ public static EventService Instance } } - public EventController OnLightSwitchToggled { get; private set; } + public EventController lightToggledAction { get; private set; } + public EventController OnKeyPickedUp { get; private set; } public EventService() { - OnLightSwitchToggled = new EventController(); + lightToggledAction = new EventController(); + OnKeyPickedUp = new EventController(); } } + diff --git a/Assets/Scripts/Service/EventService.cs.meta b/Assets/Scripts/Service/EventService.cs.meta index 80d10e9c..7d51622d 100644 --- a/Assets/Scripts/Service/EventService.cs.meta +++ b/Assets/Scripts/Service/EventService.cs.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 +<<<<<<< HEAD +guid: e31cd314a935b6d4f87c18700006968c +======= guid: 1e8354395b6d60748b4f1366e990b284 +>>>>>>> 7af302e5914538fcafa3dceb0b3c8164f4f00ac0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/UI/GameUIView.cs b/Assets/Scripts/UI/GameUIView.cs index b4468eee..175e016f 100644 --- a/Assets/Scripts/UI/GameUIView.cs +++ b/Assets/Scripts/UI/GameUIView.cs @@ -21,13 +21,16 @@ public class GameUIView : MonoBehaviour private void OnEnable() { - tryAgainButton.onClick.AddListener(OnTryAgainButtonClicked); - quitButton.onClick.AddListener(OnQuitButtonClicked); + tryAgainButton.onClick.AddListener(onTryAgainButtonClicked); + quitButton.onClick.AddListener(onQuitButtonClicked); + EventService.Instance.OnKeyPickedUp.AddListener(updateKeyText); } + + private void OnDisable() => EventService.Instance.OnKeyPickedUp.RemoveListener(updateKeyText); public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1); - public void UpdateKeyText() => keysFoundText.SetText($"Keys Found: {GameService.Instance.GetPlayerController().KeysEquipped}/3"); + private void updateKeyText(int keys) => keysFoundText.SetText($"Keys Found: {keys}/3"); - private void OnQuitButtonClicked() => Application.Quit(); - private void OnTryAgainButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); + private void onQuitButtonClicked() => Application.Quit(); + private void onTryAgainButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); }