2
2
// -- Project : https://github.com/instance-id/ElementAnimationToolkit --
3
3
// -- instance.id 2020 | http://github.com/instance-id | http://instance.id --
4
4
// ----------------------------------------------------------------------------
5
+
5
6
#if UNITY_EDITOR
6
7
using System ;
7
8
using UnityEngine . UIElements ;
@@ -10,15 +11,63 @@ namespace instance.id.EATK
10
11
{
11
12
public static class AnimationExtensions
12
13
{
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>
13
20
public static void ExecuteIn ( this VisualElement element , Action action , long delayMs = 0 )
14
21
{
15
22
element . schedule . Execute ( action ) . StartingIn ( delayMs ) ;
16
23
}
17
24
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 )
19
32
{
20
33
element . schedule . Execute ( action ) . StartingIn ( delayMs ) ;
21
34
}
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
+ }
22
71
}
23
72
}
24
73
#endif
0 commit comments