using System.Collections; using System.Collections.Generic; using UnityEngine; namespace KairoEngine.Core { public class RequestEvents { #region Request_bool_with_no_args public Dictionary> list = new Dictionary>(); public void Bind(string title, System.Func listener) { System.Func action = null; if (list.TryGetValue(title, out action) == false) { action += listener; list.Add(title, action); } } public void Unbind(string title, System.Func listener) { System.Func action = null; if (list.TryGetValue(title, out action)) { action -= listener; list.Remove(title); } } // public bool Get(string title) // { // System.Func action = null; // if (list.TryGetValue(title, out action)) // { // if(action != null) return action(); // } // return false; // } public EventResponse GetBool(string title) { System.Func action = null; EventResponse response = new EventResponse(); if (list.TryGetValue(title, out action)) { if(action != null) { bool result = action(); response.value = result; response.status = EventResponseStatus.OK; } } else response.status = EventResponseStatus.NotFound; return response; } #endregion #region Request_GameObject_with_no_args public Dictionary> list2 = new Dictionary>(); public void Bind(string title, System.Func listener) { System.Func action = null; if (list2.TryGetValue(title, out action) == false) { action += listener; list2.Add(title, action); } } public void Unbind(string title, System.Func listener) { System.Func action = null; if (list2.TryGetValue(title, out action)) { action -= listener; list2.Remove(title); } } public EventResponse GetGameObject(string title) { System.Func action = null; EventResponse response = new EventResponse(); if (list2.TryGetValue(title, out action)) { if(action != null) { GameObject result = action(); response.value = result; if(response.value == null) response.status = EventResponseStatus.EmptyResponse; else response.status = EventResponseStatus.OK; } } else response.status = EventResponseStatus.NotFound; return response; } #endregion } }