From 1f0170bdc8b62f0b0290c18b7b61f0783abbe7aa Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Thu, 22 Feb 2024 23:23:05 +0530 Subject: [PATCH 1/2] fix:Delegats to Event --- Assets/Scripts/Interactables/LightSwitchView.cs | 2 +- Packages/packages-lock.json | 12 ++++++------ ProjectSettings/ProjectVersion.txt | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) 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; 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) From 712eebf7f67e145fcef494ce1fda08b2b67ca477 Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Fri, 23 Feb 2024 22:20:16 +0530 Subject: [PATCH 2/2] fix:Converting delegate into the Action --- Assets/Scripts/Interactables/LightSwitchView.cs | 11 ++++++----- Assets/Scripts/Player/PlayerController.cs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index 5c07fbdb..894d5eed 100644 --- a/Assets/Scripts/Interactables/LightSwitchView.cs +++ b/Assets/Scripts/Interactables/LightSwitchView.cs @@ -1,21 +1,22 @@ using System.Collections.Generic; using UnityEngine; +using System; using static LightSwitchView; public class LightSwitchView : MonoBehaviour, IInteractable { [SerializeField] private List lightsources = new List(); private SwitchState currentState; - public delegate void LightSwitchDelegate(); - public static event LightSwitchDelegate lightToggled; - private void OnEnable() => lightToggled += onLightSwitch; + public static event Action lightToggledAction; - private void OnDisable() => lightToggled -= onLightSwitch; + private void OnEnable() => lightToggledAction += 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..bd0e4bd6 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -25,13 +25,13 @@ 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);