22// -- Project : https://github.com/instance-id/ElementAnimationToolkit --
33// -- instance.id 2020 | http://github.com/instance-id | http://instance.id --
44// ----------------------------------------------------------------------------
5+
56#if UNITY_EDITOR
67using System ;
78using UnityEngine . UIElements ;
@@ -10,15 +11,63 @@ namespace instance.id.EATK
1011{
1112 public static class AnimationExtensions
1213 {
14+ /// <summary>
15+ /// Shorter extension in which to specify when an action should be started, and then proceed start it after specified amount of time.
16+ /// </summary>
17+ /// <param name="element">The target element in which to register the callback</param>
18+ /// <param name="action">The action to perform</param>
19+ /// <param name="delayMs">The amount of time in milliseconds that should be waited until the action begins</param>
1320 public static void ExecuteIn ( this VisualElement element , Action action , long delayMs = 0 )
1421 {
1522 element . schedule . Execute ( action ) . StartingIn ( delayMs ) ;
1623 }
1724
18- public static void ExecuteIn ( this Action action , VisualElement element , long delayMs = 0 )
25+ /// <summary>
26+ /// Shorter extension in which to specify when an action should be started, and then proceed start it after specified amount of time.
27+ /// </summary>
28+ /// <param name="action">The action to perform</param>
29+ /// <param name="element">The target element in which to register the callback</param>
30+ /// <param name="delayMs">The amount of time in milliseconds that should be waited until the action begins</param>
31+ public static void ExecuteIn ( this Action action , VisualElement element , long delayMs = 0 )
1932 {
2033 element . schedule . Execute ( action ) . StartingIn ( delayMs ) ;
2134 }
35+
36+ // -- Register Callback with element return ------------
37+ /// <summary>
38+ /// RegisterCallback on element, as well as children, and return the element
39+ /// </summary>
40+ /// <param name="element">The target element in which to register the callback</param>
41+ /// <param name="callback">The callback in which to register</param>
42+ /// <param name="includeChildren">Register child elements in addition to the target element</param>
43+ /// <typeparam name="TEventType">The event callback type in which to register</typeparam>
44+ /// <returns>The target element</returns>
45+ public static VisualElement RegisterCallback < TEventType > ( this VisualElement element , EventCallback < TEventType > callback , bool includeChildren )
46+ where TEventType : EventBase < TEventType > , new ( )
47+ {
48+ element . RegisterCallback ( callback ) ;
49+ if ( ! includeChildren ) return element ;
50+ var children = element . Query < VisualElement > ( ) . Descendents < VisualElement > ( ) . ToList ( ) ;
51+ children . ForEach ( x => x . RegisterCallback ( callback ) ) ;
52+ return element ;
53+ }
54+
55+ /// <summary>
56+ /// RegisterCallback on element, as well as children, and return the element
57+ /// </summary>
58+ /// <param name="element">The target element in which to register the callback</param>
59+ /// <param name="callback">The callback in which to register</param>
60+ /// <param name="includeChildren">Register child elements in addition to the target element</param>
61+ /// <typeparam name="TEventType">The event callback type in which to register</typeparam>
62+ /// <returns>The target element</returns>
63+ public static void UnregisterCallback < TEventType > ( this VisualElement element , EventCallback < TEventType > callback , bool includeChildren )
64+ where TEventType : EventBase < TEventType > , new ( )
65+ {
66+ element . UnregisterCallback ( callback ) ;
67+ if ( ! includeChildren ) return ;
68+ var children = element . Query < VisualElement > ( ) . Descendents < VisualElement > ( ) . ToList ( ) ;
69+ children . ForEach ( x => x . UnregisterCallback ( callback ) ) ;
70+ }
2271 }
2372}
2473#endif
0 commit comments