12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace KairoEngine.Inventory
- {
- public class ItemContainerEvents
- {
- public static Dictionary<string, System.Action<ItemContainer>> OnOpen = new Dictionary<string, System.Action<ItemContainer>>();
- public static Dictionary<string, System.Action> OnClose = new Dictionary<string, System.Action>();
- public static event System.Action<ItemContainer> OnUpdate;
-
- public static void Open(string title, ItemContainer itemContainer)
- {
- if(OnOpen[title] != null)
- {
- //Debug.Log("ItemContainerEvents.OnOpen has been triggered");
- OnOpen[title](itemContainer);
- }
- }
- public static void Close(string title)
- {
- if(OnClose[title] != null)
- {
- //Debug.Log("ItemContainerEvents.OnOpen has been triggered");
- OnClose[title]();
- }
- }
- public static void Update(ItemContainer itemContainer)
- {
- if(OnUpdate != null)
- {
- //Debug.Log("ItemContainerEvents.OnOpen has been triggered");
- OnUpdate(itemContainer);
- }
- }
- public static void StartListeningOnOpen(string title, System.Action<ItemContainer> listener)
- {
- System.Action<ItemContainer> action = null;
- if (OnOpen.TryGetValue(title, out action))
- {
- action += listener;
- OnOpen[title] = action;
- }
- else
- {
- action += listener;
- OnOpen.Add(title, action);
- }
- }
- public static void StartListeningOnClose(string title, System.Action listener)
- {
- System.Action action = null;
- if (OnClose.TryGetValue(title, out action))
- {
- action += listener;
- OnClose[title] = action;
- }
- else
- {
- action += listener;
- OnClose.Add(title, action);
- }
- }
- public static void StopListeningOnOpen(string title, System.Action<ItemContainer> listener)
- {
- System.Action<ItemContainer> action = null;
- if (OnOpen.TryGetValue(title, out action))
- {
- action -= listener;
- OnOpen[title] = action;
- }
- }
- public static void StopListeningOnClose(string title, System.Action listener)
- {
- System.Action action = null;
- if (OnClose.TryGetValue(title, out action))
- {
- action -= listener;
- OnClose[title] = action;
- }
- }
- }
- }
|