123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- namespace KairoEngine.Inventory
- {
- public static class RequestEventsInventoryExtensions
- {
- public static Dictionary<string, System.Func<ItemContainer>> list = new Dictionary<string, System.Func<ItemContainer>>();
- public static void Bind(this RequestEvents e, string title, System.Func<ItemContainer> listener)
- {
- System.Func<ItemContainer> 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<ItemContainer> listener)
- {
- System.Func<ItemContainer> action = null;
- if (list.TryGetValue(title, out action))
- {
- action -= listener;
- list.Remove(title);
- }
- }
- public static EventResponse<ItemContainer> GetItemContainer(this RequestEvents e, string title)
- {
- System.Func<ItemContainer> action = null;
- EventResponse<ItemContainer> response = new EventResponse<ItemContainer>();
- if (list.TryGetValue(title, out action))
- {
- if(action != null)
- {
- ItemContainer 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;
- }
- }
- }
|