1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- namespace KairoEngine.CharacterSystem
- {
- public static class RequestEventExtensions
- {
- public static Dictionary<string, System.Func<CharacterController>> list = new Dictionary<string, System.Func<CharacterController>>();
-
- public static void Bind(this RequestEvents e, string title, System.Func<CharacterController> listener)
- {
- System.Func<CharacterController> action = null;
- if (list.TryGetValue(title, out action) == false)
- {
- action += listener;
- list.Add(title, action);
- }
- }
- public static void Unbind(this RequestEvents e, string title, System.Func<CharacterController> listener)
- {
- System.Func<CharacterController> action = null;
- if (list.TryGetValue(title, out action))
- {
- action -= listener;
- list.Remove(title);
- }
- }
- public static EventResponse<CharacterController> GetCharacterController(this RequestEvents e, string title)
- {
- System.Func<CharacterController> action = null;
- EventResponse<CharacterController> response = new EventResponse<CharacterController>();
- if (list.TryGetValue(title, out action))
- {
- if(action != null)
- {
- CharacterController 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;
- }
- }
- }
|