123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace KairoEngine.Core
- {
- public class RequestEvents
- {
- #region Request_bool_with_no_args
- public Dictionary<string, System.Func<bool>> list = new Dictionary<string, System.Func<bool>>();
-
- public void Bind(string title, System.Func<bool> listener)
- {
- System.Func<bool> action = null;
- if (list.TryGetValue(title, out action) == false)
- {
- action += listener;
- list.Add(title, action);
- }
- }
- public void Unbind(string title, System.Func<bool> listener)
- {
- System.Func<bool> action = null;
- if (list.TryGetValue(title, out action))
- {
- action -= listener;
- list.Remove(title);
- }
- }
- // public bool Get(string title)
- // {
- // System.Func<bool> action = null;
- // if (list.TryGetValue(title, out action))
- // {
- // if(action != null) return action();
- // }
- // return false;
- // }
- public EventResponse<bool> GetBool(string title)
- {
- System.Func<bool> action = null;
- EventResponse<bool> response = new EventResponse<bool>();
- 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<string, System.Func<GameObject>> list2 = new Dictionary<string, System.Func<GameObject>>();
-
- public void Bind(string title, System.Func<GameObject> listener)
- {
- System.Func<GameObject> action = null;
- if (list2.TryGetValue(title, out action) == false)
- {
- action += listener;
- list2.Add(title, action);
- }
- }
- public void Unbind(string title, System.Func<GameObject> listener)
- {
- System.Func<GameObject> action = null;
- if (list2.TryGetValue(title, out action))
- {
- action -= listener;
- list2.Remove(title);
- }
- }
- public EventResponse<GameObject> GetGameObject(string title)
- {
- System.Func<GameObject> action = null;
- EventResponse<GameObject> response = new EventResponse<GameObject>();
- 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
- }
- }
|