From 4a8067d3d7a3553c903f4239767a22f2c5e2993c Mon Sep 17 00:00:00 2001 From: dhain Date: Fri, 24 Jun 2022 08:38:28 +0200 Subject: [PATCH] NO LONGER CLICK THROUGH UI OMG --- Assets/Scripts/Actions/ActionManager.cs | 31 ++++++++++++------- Assets/Scripts/Actions/ClickActionHandlers.cs | 5 +-- Assets/Scripts/InventoryUI.cs | 17 +++++++++- Assets/Scripts/Shop/ShopUI.cs | 20 +++++++++++- Assets/Scripts/TileController.cs | 14 +++++++++ Packages/packages-lock.json | 13 ++------ ProjectSettings/ProjectVersion.txt | 4 +-- 7 files changed, 76 insertions(+), 28 deletions(-) diff --git a/Assets/Scripts/Actions/ActionManager.cs b/Assets/Scripts/Actions/ActionManager.cs index ac054f9..c0dd8a3 100644 --- a/Assets/Scripts/Actions/ActionManager.cs +++ b/Assets/Scripts/Actions/ActionManager.cs @@ -23,12 +23,19 @@ namespace Actions { private List _clickActionHandlers; private List _nextDayActionHandlers; + private bool _enabled; + + public bool Enabled { + get => _enabled; + set => _enabled = value; + } private ActionManager() { _clickActionHandlers = new List(); _nextDayActionHandlers = new List(); instantiateClickActionHandlers(); instantiateNextDayActionHandlers(); + Enabled = true; } /// @@ -65,26 +72,28 @@ namespace Actions { /// The affected gameObject /// the current tool public void ClickAction(GameObject gameObject, UsableItem usableItem) { - foreach (ClickActionHandler actionHandler in _clickActionHandlers) { - if(actionHandler.Matches(gameObject, usableItem)) { - actionHandler.InvokeAction(gameObject); - break; // Ja Herr Professor, Sie sehen richtig. Voller Stolz verwende ich ein break. + if(Enabled) { + foreach(ClickActionHandler actionHandler in _clickActionHandlers) { + if(actionHandler.Matches(gameObject, usableItem)) { + actionHandler.InvokeAction(gameObject); + break; // Ja Herr Professor, Sie sehen richtig. Voller Stolz verwende ich ein break. + } } } } /// - /// Used to Invoke ClickActions, all ClickActionHandlers in ClickActionHandlers list are iterated through, + /// Used to Invoke NextDay, all NextDayActionHandlers in NextDayActionHandlers list are iterated through, /// only one will be invoked per method call /// /// The affected gameObject - /// the current tool public void NextDayAction(GameObject gameObject) { - Debug.Log("nextday action"); - foreach (NextDayActionHandler actionHandler in _nextDayActionHandlers) { - if(actionHandler.Matches(gameObject)) { - actionHandler.InvokeAction(gameObject); - break; // Gleich noch einmal. Und ich kann nachts immer noch zufrieden schlafen. + if(Enabled) { + foreach(NextDayActionHandler actionHandler in _nextDayActionHandlers) { + if(actionHandler.Matches(gameObject)) { + actionHandler.InvokeAction(gameObject); + break; // Gleich noch einmal. Und ich kann nachts immer noch zufrieden schlafen. + } } } } diff --git a/Assets/Scripts/Actions/ClickActionHandlers.cs b/Assets/Scripts/Actions/ClickActionHandlers.cs index ced75a5..8ddf48e 100644 --- a/Assets/Scripts/Actions/ClickActionHandlers.cs +++ b/Assets/Scripts/Actions/ClickActionHandlers.cs @@ -100,7 +100,7 @@ namespace Assets.Scripts.Actions { bool rv = false; try { _animal = gameObject.GetComponent(); - rv = true; + rv = _animal != null; } catch { } return rv; @@ -277,7 +277,8 @@ namespace Assets.Scripts.Actions { public override bool Matches(GameObject gameObject, UsableItem usableItem) { bool rv = base.Matches(gameObject, usableItem); if(rv) { - rv = _animal.displayName.Equals("Cow") && usableItem.ID == ItemContainer.Instance.GetItemIdByName("Bucket"); + rv = _animal.displayName.Equals("Cow") && + usableItem.ID == ItemContainer.Instance.GetItemIdByName("Bucket"); } return rv; } diff --git a/Assets/Scripts/InventoryUI.cs b/Assets/Scripts/InventoryUI.cs index 1119c72..8aa5919 100644 --- a/Assets/Scripts/InventoryUI.cs +++ b/Assets/Scripts/InventoryUI.cs @@ -1,9 +1,10 @@ using System; using System.Linq; +using Actions; using UnityEngine; using UnityEngine.EventSystems; -public class InventoryUI : MonoBehaviour { +public class InventoryUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { public Transform itemsParent; public GameObject inventoryUI; private Inventory _inventory; @@ -59,4 +60,18 @@ public class InventoryUI : MonoBehaviour { } } } + + /** + * Turn off ActionManager when Pointer over UI + */ + public void OnPointerEnter(PointerEventData eventData) { + ActionManager.Instance.Enabled = false; + } + + /** + * Turn on ActionManager when Pointer over UI + */ + public void OnPointerExit(PointerEventData eventData) { + ActionManager.Instance.Enabled = true; + } } diff --git a/Assets/Scripts/Shop/ShopUI.cs b/Assets/Scripts/Shop/ShopUI.cs index 9e34d4f..7507eff 100644 --- a/Assets/Scripts/Shop/ShopUI.cs +++ b/Assets/Scripts/Shop/ShopUI.cs @@ -1,8 +1,12 @@ +using System.Collections.Generic; using System.Linq; +using Actions; +using Tiles; using UnityEngine; +using UnityEngine.EventSystems; namespace Shop { - public class ShopUI : MonoBehaviour { + public class ShopUI : MonoBehaviour , IPointerEnterHandler, IPointerExitHandler{ public Transform itemsParent; public Transform animalsParent; public GameObject shopUI; @@ -81,5 +85,19 @@ namespace Shop { } } } + + /** + * Turn off ActionManager when Pointer over UI + */ + public void OnPointerEnter(PointerEventData eventData) { + ActionManager.Instance.Enabled = false; + } + + /** + * Turn on ActionManager when Pointer over UI + */ + public void OnPointerExit(PointerEventData eventData) { + ActionManager.Instance.Enabled = true; + } } } \ No newline at end of file diff --git a/Assets/Scripts/TileController.cs b/Assets/Scripts/TileController.cs index 8a409fb..48176f7 100644 --- a/Assets/Scripts/TileController.cs +++ b/Assets/Scripts/TileController.cs @@ -7,6 +7,20 @@ using UnityEngine.Tilemaps; /// Instatiates Tiles at beginning of the game /// public class TileController : MonoBehaviour { + #region Singleton + + public static TileController instance; + + private void Awake() { + if (instance != null) { + Debug.LogWarning("More than one instance of TileController found"); + } + + instance = this; + } + + #endregion + public GameObject tile; public GameObject cameraGameObject; diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 40769bb..4f0557e 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -137,21 +137,12 @@ "dependencies": {}, "url": "https://packages.unity.com" }, - "com.unity.nuget.newtonsoft-json": { - "version": "3.0.2", - "depth": 2, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" - }, "com.unity.services.core": { - "version": "1.3.1", + "version": "1.0.1", "depth": 1, "source": "registry", "dependencies": { - "com.unity.modules.unitywebrequest": "1.0.0", - "com.unity.nuget.newtonsoft-json": "3.0.2", - "com.unity.modules.androidjni": "1.0.0" + "com.unity.modules.unitywebrequest": "1.0.0" }, "url": "https://packages.unity.com" }, diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 3dcb827..90d6509 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.2f1 -m_EditorVersionWithRevision: 2021.3.2f1 (d6360bedb9a0) +m_EditorVersion: 2021.3.1f1 +m_EditorVersionWithRevision: 2021.3.1f1 (3b70a0754835)