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<NextDayActionHandler> _nextDayActionHandlers;
|
||||
private bool _enabled;
|
||||
|
||||
public bool Enabled {
|
||||
get => _enabled;
|
||||
set => _enabled = value;
|
||||
}
|
||||
|
||||
private ActionManager() {
|
||||
_clickActionHandlers = new List<ClickActionHandler>();
|
||||
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
||||
instantiateClickActionHandlers();
|
||||
instantiateNextDayActionHandlers();
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -65,6 +72,7 @@ namespace Actions {
|
|||
/// <param name="gameObject">The affected gameObject</param>
|
||||
/// <param name="usableItem">the current tool</param>
|
||||
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
|
||||
if(Enabled) {
|
||||
foreach(ClickActionHandler actionHandler in _clickActionHandlers) {
|
||||
if(actionHandler.Matches(gameObject, usableItem)) {
|
||||
actionHandler.InvokeAction(gameObject);
|
||||
|
|
@ -72,15 +80,15 @@ namespace Actions {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The affected gameObject</param>
|
||||
/// <param name="usableItem">the current tool</param>
|
||||
public void NextDayAction(GameObject gameObject) {
|
||||
Debug.Log("nextday action");
|
||||
if(Enabled) {
|
||||
foreach(NextDayActionHandler actionHandler in _nextDayActionHandlers) {
|
||||
if(actionHandler.Matches(gameObject)) {
|
||||
actionHandler.InvokeAction(gameObject);
|
||||
|
|
@ -90,3 +98,4 @@ namespace Actions {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ namespace Assets.Scripts.Actions {
|
|||
bool rv = false;
|
||||
try {
|
||||
_animal = gameObject.GetComponent<Animal>();
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,20 @@ using UnityEngine.Tilemaps;
|
|||
/// Instatiates Tiles at beginning of the game
|
||||
/// </summary>
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue