/// <summary> /// Consumes all subscribed functions /// </summary> public static void ConsumeAll() { #if UNITY_EDITOR EHS_Manager.LogMessage("[CONSUMING ALL]"); #endif HandleEvent = null; }
/// <summary> /// Unsubscribes all functions /// </summary> public static void UnsubscribeAll() { #if UNITY_EDITOR EHS_Manager.LogMessage("[UNSUBSCRIBING ALL]"); #endif Subscribers = new List <__eHandle <object, __eArg <_T> > >(); }
public override void OnInspectorGUI() { EditorGUILayout.HelpBox("The EHS is used to dynamically and efficiently create events and invoke them during runtime using event delegates.", MessageType.Info); EditorGUILayout.Space(); GUILayout.BeginVertical(EditorStyles.textArea); for (int index = 0; index < EHS_Manager.MESSAGE_COUNT; index++) { if (EHS_Manager.Messages[index] == null) { EditorGUILayout.LabelField(""); } else { EditorGUILayout.LabelField(EHS_Manager.Messages[index]); } } GUILayout.EndVertical(); if (GUILayout.Button("Clear")) { EHS_Manager.ClearMessages(); } GUI.enabled = true; }
private void Awake() { if (s_instance != null) { Destroy(gameObject); return; } s_instance = this; if (s_everInialized) { throw new System.Exception("Tried to initialize twice in one session"); } DontDestroyOnLoad(gameObject); int handle = __event <__eType> .Raise(HandleEvents); if (handle == RESULTS.FAILURE) { LogMessage("[ERROR] Could no initialize manager!"); throw new System.Exception("Failed to create a raise a message loop"); } m_initialized = true; s_everInialized = true; }
/// <summary> /// Creates a new Subscriber and adds it to storage /// </summary> /// <param name="f">function to subscribe</param> /// <param name="MSA">Max Subscriber amount</param> /// <returns></returns> public static int CreateSubscriber(__eHandle <object, __eArg <_T> > f) { if (f == null) { #if UNITY_EDITOR EHS_Manager.LogMessage("[SUBSCRIBING FAILED, ID=" + (Subscribers.Count - 1) + 1 + ", NAME=" + f.Method.Name + "]"); #endif return(-1); } Subscribers.Add(f); #if UNITY_EDITOR EHS_Manager.LogMessage("[SUBSCRIBING ID=" + (Subscribers.Count - 1) + ", NAME=" + f.Method.Name + "]"); #endif return(Subscribers.Count - 1); }
/// <summary> /// Consumes a subscribed function /// </summary> /// <param name="i">Index of subscribed function to consume</param> /// <returns></returns> public static int Consume(int i) { if (i == -1 || i >= Subscribers.Count) { #if UNITY_EDITOR EHS_Manager.LogMessage("[CONSUMING FAILED ID=" + i + "]"); #endif return(-1); } #if UNITY_EDITOR EHS_Manager.LogMessage("[CONSUMING ID=" + i + "]"); #endif HandleEvent -= Subscribers[i]; Subscribers.RemoveAt(i); return(i); }
/// <summary> /// Raises a new function /// </summary> /// <param name="f">function to raise</param> public static int Raise(__eHandle <object, __eArg <_T> > f) { int i = Raise(CreateSubscriber(f)); if (i == -1) { #if UNITY_EDITOR EHS_Manager.LogMessage("[RAISING FAILED, NAME=" + f.Method.Name + ", FROM=" + f.Target.ToString() + "]"); #endif return(i); } #if UNITY_EDITOR EHS_Manager.LogMessage("[RAISING NAME=" + f.Method.Name + ", FROM=" + f.Target.ToString() + "]"); #endif return(i); }
/// <summary> /// Invokes an event using the arguments that where passed /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">arguments for the event</param> public static void InvokeEvent(object sender, __eArg <_T> e) { #if UNITY_EDITOR if (e.value != null) { try { EHS_Manager.LogMessage("[INVOKING ARG=" + e.arg.ToString() + ", VALUE=" + e.value.ToString() + "]"); } catch { EHS_Manager.LogMessage("[INVOKING ARG=" + e.arg.ToString() + ", VALUE=N/A]"); } } else { EHS_Manager.LogMessage("[INVOKING ARG=" + e.arg.ToString() + ", VALUE=NULL]"); } #endif if (HandleEvent != null) { HandleEvent(sender, e); } }