1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace KairoEngine
- {
- public class EventData
- {
- public GameObject obj;
- public EventData(GameObject obj = null)
- {
- this.obj = obj;
- }
- }
- public class InteractionEvents
- {
- public static Dictionary<string, System.Action<EventData>> list = new Dictionary<string, System.Action<EventData>>();
- public static void StartListening(string title, System.Action<EventData> listener)
- {
- System.Action<EventData> action = null;
- if (list.TryGetValue(title, out action))
- {
- action += listener;
- list[title] = action;
- }
- else
- {
- action += listener;
- list.Add(title, action);
- }
- }
- public static void StopListening(string title, System.Action<EventData> listener)
- {
- System.Action<EventData> action = null;
- if (list.TryGetValue(title, out action))
- {
- action -= listener;
- list[title] = action;
- }
- }
- public static void Trigger(string title, EventData eventData)
- {
- System.Action<EventData> action = null;
- if (list.TryGetValue(title, out action))
- {
- if(action != null) action(eventData);
- }
- }
- }
- }
|