Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using Sirenix.OdinInspector;
  2. using System;
  3. using System.Collections.Generic;
  4. using UnityEngine.Events;
  5.  
  6. [Serializable]
  7. public struct BetterEvent
  8. {
  9.     [HideReferenceObjectPicker, ListDrawerSettings(CustomAddFunction = "GetDefaultBetterEvent", OnTitleBarGUI = "DrawInvokeButton")]
  10.     public List<BetterEventEntry> Events;
  11.  
  12.     public void Invoke()
  13.     {
  14.         if (this.Events == null) return;
  15.         for (int i = 0; i < this.Events.Count; i++)
  16.         {
  17.             this.Events[i].Invoke();
  18.         }
  19.     }
  20.  
  21.     public void AddCallback(UnityAction callback)
  22.     {
  23.         if (Events == null)
  24.             Events = new List<BetterEventEntry>();
  25.         Events.Add(new BetterEventEntry(callback));
  26.     }
  27.  
  28. #if UNITY_EDITOR
  29.  
  30.     private BetterEventEntry GetDefaultBetterEvent()
  31.     {
  32.         return new BetterEventEntry(null);
  33.     }
  34.  
  35.     private void DrawInvokeButton()
  36.     {
  37.         if (Sirenix.Utilities.Editor.SirenixEditorGUI.ToolbarButton("Invoke"))
  38.         {
  39.             this.Invoke();
  40.         }
  41.     }
  42.  
  43. #endif
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement