Last active
July 13, 2023 12:28
-
-
Save TheLouisHong/1d5f123ac1097e8f4c055cd5cbf9a438 to your computer and use it in GitHub Desktop.
SimpleMessage: A performant alternative to SendMessage in Unity. (A simple wrapper around the Unity UI event system)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.EventSystems; | |
public static class SimpleMessage | |
{ | |
public delegate void EventFunction<T1,T2>(T1 handler, T2 eventData); | |
public static bool Send<T,T2>(GameObject target, object eventData, EventFunction<T, T2> functor) | |
where T : IEventSystemHandler | |
{ | |
return ExecuteEvents.Execute<T>(target, null, (x, y) => functor(x, (T2)eventData)); | |
} | |
public static void SendHierarchy<T, T2>(GameObject root, object eventData, EventFunction<T,T2> functor) where T : IEventSystemHandler | |
{ | |
ExecuteEvents.ExecuteHierarchy<T>(root, null, (x, y) => functor(x, (T2)eventData)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment