using System.Collections; using System.Collections.Generic; using UnityEngine; namespace KairoEngine.Inventory { public class ItemContainerEvents { public static Dictionary> OnOpen = new Dictionary>(); public static Dictionary OnClose = new Dictionary(); public static event System.Action 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 listener) { System.Action 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 listener) { System.Action 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; } } } }