Pro_Unit

EnumActionSelector

Dec 4th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using Object = UnityEngine.Object;
  9.  
  10. namespace GameCore
  11. {
  12.     public abstract class EnumActionSelector<EnumType> : MonoBehaviour where EnumType : EnumScriptable
  13.     {
  14.         public List<TypeAction> actions = new List<TypeAction> ();
  15.         Dictionary<EnumType, UnityEvent> selector = null;
  16.         Dictionary<EnumType, UnityEvent> Selector { get { return selector ?? (selector = actions.ToDictionary (a => a.type as EnumType, a => a.action)); } }
  17.  
  18.         public virtual void Invoke (EnumType parameter)
  19.         {
  20.             Selector[parameter].Invoke ();
  21.         }
  22.         public Action this [EnumType parametr]
  23.         {
  24.             get { return Selector[parametr].Invoke; }
  25.         }
  26.  
  27.     }
  28.  
  29.     [Serializable]
  30.     public class TypeAction
  31.     {
  32.         public EnumScriptable type;
  33.         [Sirenix.OdinInspector.DrawWithUnity]
  34.         public UnityEvent action;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment