From f7e90895fc0e95d8f0547a77da5a3fff6d9479fd Mon Sep 17 00:00:00 2001 From: "DESKTOP-6U5DPEC\\koush" Date: Thu, 19 Sep 2024 11:08:32 +0530 Subject: [PATCH 1/2] Converted light switch delegate into an event. --- Assets/Scripts/Interactables/LightSwitchView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index e96c6032..5c07fbdb 100644 --- a/Assets/Scripts/Interactables/LightSwitchView.cs +++ b/Assets/Scripts/Interactables/LightSwitchView.cs @@ -7,7 +7,7 @@ public class LightSwitchView : MonoBehaviour, IInteractable [SerializeField] private List lightsources = new List(); private SwitchState currentState; public delegate void LightSwitchDelegate(); - public static LightSwitchDelegate lightToggled; + public static event LightSwitchDelegate lightToggled; private void OnEnable() => lightToggled += onLightSwitch; From 9bfcd8b0a0e3df48ff261b0ad89f4f640f5d941c Mon Sep 17 00:00:00 2001 From: "DESKTOP-6U5DPEC\\koush" Date: Thu, 19 Sep 2024 12:28:41 +0530 Subject: [PATCH 2/2] Converted delegate to action. --- Assets/Scripts/Interactables/LightSwitchView.cs | 11 ++++++----- Assets/Scripts/Player/PlayerController.cs | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index 5c07fbdb..03630219 100644 --- a/Assets/Scripts/Interactables/LightSwitchView.cs +++ b/Assets/Scripts/Interactables/LightSwitchView.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; using static LightSwitchView; @@ -6,16 +7,16 @@ public class LightSwitchView : MonoBehaviour, IInteractable { [SerializeField] private List lightsources = new List(); private SwitchState currentState; - public delegate void LightSwitchDelegate(); - public static event LightSwitchDelegate lightToggled; + + public static event Action lightToggledAction; - private void OnEnable() => lightToggled += onLightSwitch; + private void OnEnable() => lightToggledAction += onLightSwitch; - private void OnDisable() => lightToggled -= onLightSwitch; + private void OnDisable() => lightToggledAction -= onLightSwitch; private void Start() => currentState = SwitchState.Off; - public void Interact() => lightToggled?.Invoke(); + public void Interact() => lightToggledAction?.Invoke(); private void toggleLights() { diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 054fc215..2a14c50e 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -25,14 +25,15 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri this.playerScriptableObject = playerScriptableObject; this.playerScriptableObject.KeysEquipped = 0; - LightSwitchView.lightToggled += onLightSwitch; + LightSwitchView.lightToggledAction += onLightSwitch; playerState = PlayerState.InDark; } ~PlayerController() { - LightSwitchView.lightToggled -= onLightSwitch; + LightSwitchView.lightToggledAction -= onLightSwitch; } + public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted); public void Jump(Rigidbody playerRigidbody, Transform transform)