NO LONGER CLICK THROUGH UI OMG
This commit is contained in:
parent
d3a06effc5
commit
4a8067d3d7
7 changed files with 76 additions and 28 deletions
|
|
@ -23,12 +23,19 @@ namespace Actions {
|
||||||
|
|
||||||
private List<ClickActionHandler> _clickActionHandlers;
|
private List<ClickActionHandler> _clickActionHandlers;
|
||||||
private List<NextDayActionHandler> _nextDayActionHandlers;
|
private List<NextDayActionHandler> _nextDayActionHandlers;
|
||||||
|
private bool _enabled;
|
||||||
|
|
||||||
|
public bool Enabled {
|
||||||
|
get => _enabled;
|
||||||
|
set => _enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
private ActionManager() {
|
private ActionManager() {
|
||||||
_clickActionHandlers = new List<ClickActionHandler>();
|
_clickActionHandlers = new List<ClickActionHandler>();
|
||||||
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
||||||
instantiateClickActionHandlers();
|
instantiateClickActionHandlers();
|
||||||
instantiateNextDayActionHandlers();
|
instantiateNextDayActionHandlers();
|
||||||
|
Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -65,26 +72,28 @@ namespace Actions {
|
||||||
/// <param name="gameObject">The affected gameObject</param>
|
/// <param name="gameObject">The affected gameObject</param>
|
||||||
/// <param name="usableItem">the current tool</param>
|
/// <param name="usableItem">the current tool</param>
|
||||||
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
|
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
|
||||||
foreach (ClickActionHandler actionHandler in _clickActionHandlers) {
|
if(Enabled) {
|
||||||
if(actionHandler.Matches(gameObject, usableItem)) {
|
foreach(ClickActionHandler actionHandler in _clickActionHandlers) {
|
||||||
actionHandler.InvokeAction(gameObject);
|
if(actionHandler.Matches(gameObject, usableItem)) {
|
||||||
break; // Ja Herr Professor, Sie sehen richtig. Voller Stolz verwende ich ein break.
|
actionHandler.InvokeAction(gameObject);
|
||||||
|
break; // Ja Herr Professor, Sie sehen richtig. Voller Stolz verwende ich ein break.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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
|
/// only one will be invoked per method call
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gameObject">The affected gameObject</param>
|
/// <param name="gameObject">The affected gameObject</param>
|
||||||
/// <param name="usableItem">the current tool</param>
|
|
||||||
public void NextDayAction(GameObject gameObject) {
|
public void NextDayAction(GameObject gameObject) {
|
||||||
Debug.Log("nextday action");
|
if(Enabled) {
|
||||||
foreach (NextDayActionHandler actionHandler in _nextDayActionHandlers) {
|
foreach(NextDayActionHandler actionHandler in _nextDayActionHandlers) {
|
||||||
if(actionHandler.Matches(gameObject)) {
|
if(actionHandler.Matches(gameObject)) {
|
||||||
actionHandler.InvokeAction(gameObject);
|
actionHandler.InvokeAction(gameObject);
|
||||||
break; // Gleich noch einmal. Und ich kann nachts immer noch zufrieden schlafen.
|
break; // Gleich noch einmal. Und ich kann nachts immer noch zufrieden schlafen.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Assets.Scripts.Actions {
|
||||||
bool rv = false;
|
bool rv = false;
|
||||||
try {
|
try {
|
||||||
_animal = gameObject.GetComponent<Animal>();
|
_animal = gameObject.GetComponent<Animal>();
|
||||||
rv = true;
|
rv = _animal != null;
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
return rv;
|
return rv;
|
||||||
|
|
@ -277,7 +277,8 @@ namespace Assets.Scripts.Actions {
|
||||||
public override bool Matches(GameObject gameObject, UsableItem usableItem) {
|
public override bool Matches(GameObject gameObject, UsableItem usableItem) {
|
||||||
bool rv = base.Matches(gameObject, usableItem);
|
bool rv = base.Matches(gameObject, usableItem);
|
||||||
if(rv) {
|
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;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Actions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
public class InventoryUI : MonoBehaviour {
|
public class InventoryUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
||||||
public Transform itemsParent;
|
public Transform itemsParent;
|
||||||
public GameObject inventoryUI;
|
public GameObject inventoryUI;
|
||||||
private Inventory _inventory;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Actions;
|
||||||
|
using Tiles;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace Shop {
|
namespace Shop {
|
||||||
public class ShopUI : MonoBehaviour {
|
public class ShopUI : MonoBehaviour , IPointerEnterHandler, IPointerExitHandler{
|
||||||
public Transform itemsParent;
|
public Transform itemsParent;
|
||||||
public Transform animalsParent;
|
public Transform animalsParent;
|
||||||
public GameObject shopUI;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,20 @@ using UnityEngine.Tilemaps;
|
||||||
/// Instatiates Tiles at beginning of the game
|
/// Instatiates Tiles at beginning of the game
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TileController : MonoBehaviour {
|
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 tile;
|
||||||
|
|
||||||
public GameObject cameraGameObject;
|
public GameObject cameraGameObject;
|
||||||
|
|
|
||||||
|
|
@ -137,21 +137,12 @@
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.com"
|
"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": {
|
"com.unity.services.core": {
|
||||||
"version": "1.3.1",
|
"version": "1.0.1",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.unity.modules.unitywebrequest": "1.0.0",
|
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||||
"com.unity.nuget.newtonsoft-json": "3.0.2",
|
|
||||||
"com.unity.modules.androidjni": "1.0.0"
|
|
||||||
},
|
},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
m_EditorVersion: 2021.3.2f1
|
m_EditorVersion: 2021.3.1f1
|
||||||
m_EditorVersionWithRevision: 2021.3.2f1 (d6360bedb9a0)
|
m_EditorVersionWithRevision: 2021.3.1f1 (3b70a0754835)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue