Skip to content

Commit 411a7bf

Browse files
committed
Added several new animations, helper datatypes, etc. Updated to 2022.2
1 parent 9174582 commit 411a7bf

File tree

170 files changed

+9267
-2778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+9267
-2778
lines changed

Assets/instance.id/ElementAnimationToolkit/Runtime/Animations/ContinuousAnimations.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public static class ContinuousAnimations
1616
{
1717
public static bool debug = false;
1818

19+
public static IVisualElementScheduledItem AnimBorderPulse(
20+
this VisualElement element,
21+
AnimValueStore<Color> valueStore)
22+
{
23+
return AnimBorderPulse(element, valueStore.initial, valueStore.final);
24+
}
1925
// -------------------------------------------------- @HoverBorder
2026
// ---------------------------------------------------------------
2127
/// <summary>

Assets/instance.id/ElementAnimationToolkit/Runtime/Animations/Easy.cs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,15 @@ namespace instance.id.EATK
1414
public static class Easy
1515
{
1616
private const float HalfPi = 1.570796f;
17-
1817
public static float Step(float t) => (double) t < 0.5 ? 0.0f : 1f;
19-
2018
public static float Linear(float t) => t;
21-
2219
public static float InSine(float t) => Mathf.Sin((float) (1.57079637050629 * ((double) t - 1.0))) + 1f;
23-
2420
public static float OutSine(float t) => Mathf.Sin(t * 1.570796f);
25-
2621
public static float InOutSine(float t) => (float) (((double) Mathf.Sin((float) (3.14159274101257 * ((double) t - 0.5))) + 1.0) * 0.5);
27-
2822
public static float InQuad(float t) => t * t;
29-
3023
public static float OutQuad(float t) => t * (2f - t);
31-
3224
public static float OutExpo(float t) {
3325
return t.Equals(1f) ? 1 : 1 - Mathf.Pow(2, -10 * t);
34-
3526
}
3627

3728
public static float InOutQuad(float t)
@@ -41,13 +32,9 @@ public static float InOutQuad(float t)
4132
}
4233

4334
public static float InCubic(float t) => Easy.InPower(t, 3);
44-
4535
public static float OutCubic(float t) => Easy.OutPower(t, 3);
46-
4736
public static float InOutCubic(float t) => Easy.InOutPower(t, 3);
48-
4937
public static float InPower(float t, int power) => Mathf.Pow(t, (float) power);
50-
5138
public static float OutPower(float t, int power)
5239
{
5340
int num = power % 2 == 0 ? -1 : 1;
@@ -57,20 +44,16 @@ public static float OutPower(float t, int power)
5744
public static float InOutPower(float t, int power)
5845
{
5946
t *= 2f;
60-
if ((double) t < 1.0)
61-
return Easy.InPower(t, power) * 0.5f;
47+
if ((double) t < 1.0) return Easy.InPower(t, power) * 0.5f;
6248
int num = power % 2 == 0 ? -1 : 1;
6349
return (float) ((double) num * 0.5 * ((double) Mathf.Pow(t - 2f, (float) power) + (double) (num * 2)));
6450
}
6551

6652
public static float InBounce(float t) => 1f - Easy.OutBounce(1f - t);
67-
6853
public static float OutBounce(float t)
6954
{
70-
if ((double) t < 0.363636374473572)
71-
return 121f / 16f * t * t;
72-
if ((double) t < 0.727272748947144)
73-
return (float) (121.0 / 16.0 * (double) (t -= 0.5454546f) * (double) t + 0.75);
55+
if ((double) t < 0.363636374473572) return 121f / 16f * t * t;
56+
if ((double) t < 0.727272748947144) return (float) (121.0 / 16.0 * (double) (t -= 0.5454546f) * (double) t + 0.75);
7457
return (double) t < 0.909090936183929
7558
? (float) (121.0 / 16.0 * (double) (t -= 0.8181818f) * (double) t + 15.0 / 16.0)
7659
: (float) (121.0 / 16.0 * (double) (t -= 0.9545454f) * (double) t + 63.0 / 64.0);
@@ -81,21 +64,17 @@ public static float InOutBounce(float t) =>
8164

8265
public static float InElastic(float t)
8366
{
84-
if ((double) t == 0.0)
85-
return 0.0f;
86-
if ((double) t == 1.0)
87-
return 1f;
67+
if ((double) t == 0.0) return 0.0f;
68+
if ((double) t == 1.0) return 1f;
8869
float num1 = 0.3f;
8970
float num2 = num1 / 4f;
9071
return (float) -((double) Mathf.Pow(2f, 10f * --t) * (double) Mathf.Sin((float) (((double) t - (double) num2) * 6.28318548202515) / num1));
9172
}
9273

9374
public static float OutElastic(float t)
9475
{
95-
if ((double) t == 0.0)
96-
return 0.0f;
97-
if ((double) t == 1.0)
98-
return 1f;
76+
if ((double) t == 0.0) return 0.0f;
77+
if ((double) t == 1.0) return 1f;
9978
float num1 = 0.3f;
10079
float num2 = num1 / 4f;
10180
return (float) ((double) Mathf.Pow(2f, -10f * t) * (double) Mathf.Sin((float) (((double) t - (double) num2) * 6.28318548202515) / num1) + 1.0);
@@ -116,9 +95,7 @@ public static float InOutBack(float t) =>
11695
(double) t < 0.5 ? Easy.InBack(t * 2f) * 0.5f : (float) ((double) Easy.OutBack((float) (((double) t - 0.5) * 2.0)) * 0.5 + 0.5);
11796

11897
public static float InBack(float t, float s) => (float) ((double) t * (double) t * (((double) s + 1.0) * (double) t - (double) s));
119-
12098
public static float OutBack(float t, float s) => 1f - Easy.InBack(1f - t, s);
121-
12299
public static float InOutBack(float t, float s) =>
123100
(double) t < 0.5 ? Easy.InBack(t * 2f, s) * 0.5f : (float) ((double) Easy.OutBack((float) (((double) t - 0.5) * 2.0), s) * 0.5 + 0.5);
124101

@@ -139,7 +116,6 @@ public static float InOutCirc(float t)
139116
return (float) (0.5 * ((double) Mathf.Sqrt((float) (1.0 - (double) t * (double) t)) + 1.0));
140117
}
141118

142-
143119
public static float EaseInOutQuint(float t)
144120
{
145121
return (float) (t < 0.5f ? 16f * t * t * t * t * t : 1 - Math.Pow(-2 * t + 2, 5) / 2);

Assets/instance.id/ElementAnimationToolkit/Runtime/Animations/HoverAnimations.cs

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace instance.id.EATK
1616
public static class HoverAnimations
1717
{
1818
#region Hover Animations
19-
2019
// --------------------------------------------------- @HoverColor
2120
// ---------------------------------------------------------------
2221
/// <summary>
@@ -38,7 +37,7 @@ public static class HoverAnimations
3837
/// <param name="animate">Whether to animate the transition of the background color</param>
3938
/// <param name="unregister">Whether this command is issued to register or unregister this event</param>
4039
public static void HoverColor<T>(this T target, StyleColor original, Color hoverColor, Func<T, bool> condition = null,
41-
T conditionElement = null, bool animate = false, bool unregister = false) where T : VisualElement
40+
T conditionElement = null, bool animate = false, bool unregister = false) where T : VisualElement
4241
{
4342
ValueAnimation<StyleValues> mouseOver = new ValueAnimation<StyleValues>();
4443
ValueAnimation<StyleValues> mouseOut = new ValueAnimation<StyleValues>();
@@ -123,7 +122,7 @@ public static void HoverColor<T>(this T target, StyleColor original, Color hover
123122
/// <param name="conditionElement">The element in which the optional condition will be evaluated. Ex. in the example of 'bool Condition(VisualElement sRow) => selectedRow == packageListRow;', the conditionalElement would be 'VisualElement selectedRow'</param>
124123
/// <param name="animate">Whether to animate the transition of the background color</param>
125124
public static void HoverBackground(this VisualElement target, StyleColor original, Color hoverColor, Func<VisualElement, bool> condition = null,
126-
VisualElement conditionElement = null, bool animate = false, int animDuration = 250)
125+
VisualElement conditionElement = null, bool animate = false, int animDuration = 250)
127126
{
128127
var mouseOver = new ValueAnimation<StyleValues>();
129128
var mouseOut = new ValueAnimation<StyleValues>();
@@ -189,7 +188,6 @@ public static void HoverBorder(this VisualElement target, Color original, Color
189188
target.style.borderRightColor = hoverColor;
190189
target.style.borderTopColor = hoverColor;
191190

192-
193191
evt.StopPropagation();
194192
});
195193
target.RegisterCallback<MouseOutEvent>(evt =>
@@ -202,7 +200,6 @@ public static void HoverBorder(this VisualElement target, Color original, Color
202200
target.style.borderTopWidth = borderStartEndWidth.y;
203201
}
204202

205-
206203
target.style.borderBottomColor = original;
207204
target.style.borderLeftColor = original;
208205
target.style.borderRightColor = original;
@@ -242,18 +239,18 @@ public static void HoverBorder(this VisualElement target, Color original, Color
242239
/// </example>
243240
public static AnimatedItems<MouseOverEvent, MouseOutEvent>
244241
HoverBorderPulse(
245-
this VisualElement target,
246-
Color pulseStartColor,
247-
Color pulseEndColor,
248-
Color original = default,
249-
bool addBorder = false,
250-
Vector2 borderStartEndWidth = default,
251-
int colorDuration = 1000,
252-
bool includeChildren = true,
253-
bool stopPropagation = true,
254-
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown,
255-
AnimatedItems<MouseOverEvent, MouseOutEvent> animatedItems = null,
256-
params ValueAnimation<StyleValues>[] animRunCheck)
242+
this VisualElement target,
243+
Color pulseStartColor,
244+
Color pulseEndColor,
245+
Color original = default,
246+
bool addBorder = false,
247+
Vector2 borderStartEndWidth = default,
248+
int colorDuration = 1000,
249+
bool includeChildren = true,
250+
bool stopPropagation = true,
251+
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown,
252+
AnimatedItems<MouseOverEvent, MouseOutEvent> animatedItems = null,
253+
params ValueAnimation<StyleValues>[] animRunCheck)
257254
{
258255
if (borderStartEndWidth == default)
259256
borderStartEndWidth = new Vector2(1, 0);
@@ -340,20 +337,19 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
340337
target.RegisterCallback(mouseOverEvent, includeChildren, useTrickleDown);
341338
target.RegisterCallback(mouseOutEvent, includeChildren, useTrickleDown);
342339

343-
animatedItems.AnimatedItemList = new List<ValueAnimation<StyleValues>> { pulseIn, pulseOut };
340+
animatedItems.AnimatedItemList = new List<ValueAnimation<StyleValues>> {pulseIn, pulseOut};
344341
animatedItems.EventCallbacks = (mouseOverEvent, mouseOutEvent);
345342
return animatedItems;
346343
}
347344

348345
#region Unregister
349-
350346
public static void HoverBorderPulseUnregister(
351-
this VisualElement target, Color pulseStartColor, Color pulseEndColor, Color original = default, bool addBorder = false,
352-
Vector2 borderStartEndWidth = default,
353-
int colorDuration = 1000,
354-
bool includeChildren = true,
355-
bool stopPropagation = true,
356-
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
347+
this VisualElement target, Color pulseStartColor, Color pulseEndColor, Color original = default, bool addBorder = false,
348+
Vector2 borderStartEndWidth = default,
349+
int colorDuration = 1000,
350+
bool includeChildren = true,
351+
bool stopPropagation = true,
352+
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
357353
{
358354
if (borderStartEndWidth == default)
359355
borderStartEndWidth = new Vector2(1, 0);
@@ -419,7 +415,6 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
419415
if (pulseIn.isRunning) pulseIn.Stop();
420416
if (pulseOut.isRunning) pulseOut.Stop();
421417

422-
423418
target.style.borderBottomColor = original;
424419
target.style.borderLeftColor = original;
425420
target.style.borderRightColor = original;
@@ -428,10 +423,9 @@ void PulseOut(in ValueAnimation<StyleValues> pulse)
428423
if (stopPropagation) evt.StopPropagation();
429424
}, includeChildren);
430425
}
431-
432426
#endregion
433427

434-
// -------------------------------------------------- @HoverBorder
428+
// -------------------------------------------------- @HoverBorder
435429
// ---------------------------------------------------------------
436430
/// <summary>
437431
/// Adds background hover capability that will not be lost like CSS:hover when programatically setting background color
@@ -457,17 +451,17 @@ public static void HoverOpacity(this VisualElement target, float startValue, flo
457451
evt.StopPropagation();
458452
});
459453
}
460-
454+
461455
// -------------------------------------------------------- @HoverWidth
462456
// -- Animate the width of target element to desired value on hover --
463457
// --------------------------------------------------------------------
464458
public static AnimatedItems<MouseOverEvent, MouseOutEvent> HoverWidth(
465-
this VisualElement target, float initialWidth = 0f, float desiredWidth = 100f, int duration = 1000, Action hoverCallback = null,
466-
Action leaveCallback = null,
467-
bool afterAnimation = false,
468-
bool includeChildren = true,
469-
bool stopPropagation = true,
470-
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
459+
this VisualElement target, float initialWidth = 0f, float desiredWidth = 100f, int duration = 1000, Action hoverCallback = null,
460+
Action leaveCallback = null,
461+
bool afterAnimation = false,
462+
bool includeChildren = true,
463+
bool stopPropagation = true,
464+
TrickleDown useTrickleDown = TrickleDown.NoTrickleDown)
471465
{
472466
initialWidth = initialWidth == 0f ? target.resolvedStyle.width : initialWidth;
473467
var enterAnim = new ValueAnimation<StyleValues>();
@@ -510,7 +504,7 @@ void MouseEnter()
510504

511505
return new AnimatedItems<MouseOverEvent, MouseOutEvent>(target)
512506
{
513-
AnimatedItemList = new List<ValueAnimation<StyleValues>> { enterAnim, leaveAnim },
507+
AnimatedItemList = new List<ValueAnimation<StyleValues>> {enterAnim, leaveAnim},
514508
EventCallbacks = (mouseOverEvent, mouseOutEvent)
515509
};
516510
}
@@ -519,13 +513,13 @@ void MouseEnter()
519513
// -- Animate the Height of target element to desired value on hover --
520514
// --------------------------------------------------------------------
521515
public static AnimatedItems<MouseOverEvent, MouseOutEvent> HoverHeight(
522-
this VisualElement target,
523-
float initialHeight = 0f,
524-
float desiredHeight = 100f,
525-
int duration = 1000,
526-
Action hoverCallback = null,
527-
Action leaveCallback = null,
528-
bool afterAnimation = false)
516+
this VisualElement target,
517+
float initialHeight = 0f,
518+
float desiredHeight = 100f,
519+
int duration = 1000,
520+
Action hoverCallback = null,
521+
Action leaveCallback = null,
522+
bool afterAnimation = false)
529523
{
530524
initialHeight = initialHeight == 0f ? target.resolvedStyle.height : initialHeight;
531525
var enterAnim = new ValueAnimation<StyleValues>();
@@ -562,7 +556,7 @@ void MouseEnter()
562556

563557
return new AnimatedItems<MouseOverEvent, MouseOutEvent>(target)
564558
{
565-
AnimatedItemList = new List<ValueAnimation<StyleValues>> { enterAnim, leaveAnim },
559+
AnimatedItemList = new List<ValueAnimation<StyleValues>> {enterAnim, leaveAnim},
566560
EventCallbacks = (mouseOverEvent, mouseOutEvent)
567561
};
568562
}
@@ -583,6 +577,43 @@ public static void HoverToolTip(this VisualElement target, Action callback)
583577
});
584578
}
585579

580+
public static void HoverAction(this VisualElement target, Action mouseInAction, Action mouseOutAction = default, List<VisualElement> extendedTargets = default)
581+
{
582+
target.RegisterCallback<MouseOverEvent>(evt =>
583+
{
584+
mouseInAction?.Invoke();
585+
// evt.StopPropagation();
586+
});
587+
588+
if (extendedTargets != default)
589+
{
590+
foreach (var extendedTarget in extendedTargets)
591+
{
592+
extendedTarget.RegisterCallback<MouseOverEvent>(evt =>
593+
{
594+
mouseInAction?.Invoke();
595+
// evt.StopPropagation();
596+
});
597+
}
598+
}
599+
600+
target.RegisterCallback<MouseLeaveEvent>(evt =>
601+
{
602+
if (extendedTargets != default && extendedTargets.Contains(evt.currentTarget)) return;
603+
mouseOutAction?.Invoke();
604+
// evt.StopPropagation();
605+
});
606+
607+
if (extendedTargets == default) return;
608+
foreach (var extendedTarget in extendedTargets)
609+
{
610+
extendedTarget.RegisterCallback<MouseLeaveEvent>(evt =>
611+
{
612+
mouseOutAction?.Invoke();
613+
// evt.StopPropagation();
614+
});
615+
}
616+
}
586617
#endregion
587618
}
588619
}

0 commit comments

Comments
 (0)