12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- namespace KairoEngine.Inventory
- {
- public static class GenericEventsInventoryExtensions
- {
- public static Dictionary<string, System.Action<ItemContainer, ItemRef>> list = new Dictionary<string, System.Action<ItemContainer, ItemRef>>();
-
- public static void StartListening(this GenericEvents e, string title, System.Action<ItemContainer, ItemRef> listener)
- {
- System.Action<ItemContainer, ItemRef> action = null;
- if (list.TryGetValue(title, out action))
- {
- action += listener;
- list[title] = action;
- }
- else
- {
- action += listener;
- list.Add(title, action);
- }
- }
- public static void StopListening(this GenericEvents e,string title, System.Action<ItemContainer, ItemRef> listener)
- {
- System.Action<ItemContainer, ItemRef> action = null;
- if (list.TryGetValue(title, out action))
- {
- action -= listener;
- list[title] = action;
- }
- }
- public static void Trigger(this GenericEvents e, string title, ItemContainer container, ItemRef item)
- {
- System.Action<ItemContainer, ItemRef> action = null;
- if (list.TryGetValue(title, out action))
- {
- if(action != null) action(container, item);
- }
- }
- }
- }
|