Skip to content

Commit 14e19b8

Browse files
committed
Refactorings, additional base animation overloads
Some refactorings so that eventually it can be used for in-game UI and additional base animation overloads to allow and parse HTML hex color string to be passed in color fields.
1 parent b185630 commit 14e19b8

File tree

67 files changed

+2841
-268
lines changed

Some content is hidden

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

67 files changed

+2841
-268
lines changed

Editor/EATKEditor.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Collections.Generic;
1010
using System.Linq;
1111
using instance.id.EATK.Extensions;
12-
using instance.id.Extensions;
1312
using JetBrains.Annotations;
1413
using UnityEditor;
1514
using UnityEditor.UIElements;
@@ -101,9 +100,9 @@ private void Assignments()
101100
animatedIcon = (Texture2D) EditorGUIUtility.IconContent("ScriptableObject Icon").image;
102101

103102
// -- Color Assignments -----------------------
104-
originalColor = GetColor.FromHex("#BABABA");
105-
pulseStartColor = GetColor.FromHex("#7F3B3A");
106-
pulseEndColor = GetColor.FromHex("#607FAE");
103+
originalColor = ColorUtil.FromHex("#BABABA");
104+
pulseStartColor = ColorUtil.FromHex("#7F3B3A");
105+
pulseEndColor = ColorUtil.FromHex("#607FAE");
107106
}
108107

109108
private StyleSheet StylesheetSetup()
@@ -277,8 +276,8 @@ private void BuildToolbarButtons(Toolbar toolbar)
277276

278277
// -- Register the HoverBorderPulse callback --
279278
toolbarInfo.HoverBorderPulse(
280-
pulseStartColor: GetColor.FromHex("#7F3B3A"),
281-
pulseEndColor: GetColor.FromHex("#2F569C"),
279+
pulseStartColor: ColorUtil.FromHex("#7F3B3A"),
280+
pulseEndColor: ColorUtil.FromHex("#2F569C"),
282281
colorDuration: 500);
283282
}
284283

@@ -754,7 +753,7 @@ private void FoldoutAnimation()
754753
// -- AnimatedFoldout values ------------------
755754
var openDelayMs = 500;
756755
var closeDelayMs = 4500;
757-
var animatedColor = GetColor.FromHex("#2F569C");
756+
var animatedColor = ColorUtil.FromHex("#2F569C");
758757

759758
// -- Animated Label values -------------------
760759
var cascadeMs = 50;
@@ -802,7 +801,7 @@ private void AnimateIdLabel()
802801

803802
instanceidLabel.AnimCharacterSequence(
804803
color1: originalColor,
805-
color2: GetColor.FromHex("#2F569C"),
804+
color2: ColorUtil.FromHex("#2F569C"),
806805
cascadeMs: cascadeMs,
807806
durationMS: durationMs);
808807
}
@@ -816,8 +815,8 @@ private void AnimateIdLabel()
816815
private void ButtonCascadeAnimation() // @formatter:on
817816
{
818817
// -- Image colors ------------------
819-
var buttonColor = GetColor.FromHex("#676767");
820-
var endButtonColor = GetColor.FromHex("#2F569C");
818+
var buttonColor = ColorUtil.FromHex("#676767");
819+
var endButtonColor = ColorUtil.FromHex("#2F569C");
821820
const int durationInMs = 500;
822821
const int delayInMs = 1000;
823822

@@ -910,9 +909,9 @@ private void HeaderInfoMenuAnimation(bool evt, VisualElement menuInfoContainer,
910909
const int durationMs = 500;
911910
const int inDurationMs = 300;
912911
const int outDurationMs = 150;
913-
var hoverLabelColor = GetColor.FromHex("#2F569C");
914-
var originalInfoBgColor = GetColor.FromHex("#303030");
915-
var toolbarHoverColor = GetColor.FromHex("#2F569C");
912+
var hoverLabelColor = ColorUtil.FromHex("#2F569C");
913+
var originalInfoBgColor = ColorUtil.FromHex("#303030");
914+
var toolbarHoverColor = ColorUtil.FromHex("#2F569C");
916915

917916
// -- Local Func which is used as a callback for AnimateWidth() --
918917
// -- so that when the large => small animation completes, --
@@ -970,7 +969,7 @@ void UnregisterHoverCallback()
970969
menuInfoContainer.schedule.Execute(() =>
971970
{
972971
var menupg = VisualElementBaseAnimation.AnimateBackgroundColor(menuInfoContainer, startColor: originalInfoBgColor,
973-
endColor: GetColor.FromHex("#212121"),
972+
endColor: ColorUtil.FromHex("#212121"),
974973
durationMs: 600);
975974
menupg.Start();
976975
}).StartingIn(0);
@@ -1034,7 +1033,7 @@ void UnregisterHoverCallback()
10341033

10351034
menuInfoContainer.schedule.Execute(() =>
10361035
{
1037-
VisualElementBaseAnimation.AnimateBackgroundColor(menuInfoContainer, GetColor.FromHex("#212121"),
1036+
VisualElementBaseAnimation.AnimateBackgroundColor(menuInfoContainer, ColorUtil.FromHex("#212121"),
10381037
originalInfoBgColor,
10391038
400);
10401039
}).StartingIn(0);
@@ -1055,8 +1054,8 @@ void UnregisterHoverCallback()
10551054
private void ImageAnimation(VisualElement imageButton, Func<float, float> easing = null) // @formatter:on
10561055
{
10571056
// -- Image colors ------------------
1058-
var originalImageColor = GetColor.FromHex("#000000");
1059-
var targetImageColor = GetColor.FromHex("#607FAE");
1057+
var originalImageColor = ColorUtil.FromHex("#000000");
1058+
var targetImageColor = ColorUtil.FromHex("#607FAE");
10601059
const int durationInMs = 1000;
10611060
const int delayInMs = 1000;
10621061

@@ -1091,8 +1090,8 @@ private void FadeTextAnimation(Label fadeTextAnimationLabel, Func<float, float>
10911090
const int fadeOutTime = 500;
10921091

10931092
const string newText = "then back to the original!";
1094-
var originalTextColor = GetColor.FromHex("#BABABA");
1095-
var animatedTextColor = GetColor.FromHex("#607FAE");
1093+
var originalTextColor = ColorUtil.FromHex("#BABABA");
1094+
var animatedTextColor = ColorUtil.FromHex("#607FAE");
10961095

10971096
fadeTextAnimationLabel.AnimFadeInSequence(
10981097
newText,
@@ -1110,10 +1109,10 @@ private void FadeColorAnimation(VisualElement fadeColorAnimationLabel, Func<floa
11101109
{
11111110
// -- Background colors -------------
11121111
var originalBackgroundColor = new StyleColor(StyleKeyword.Initial).value;
1113-
var targetBackgroundColor = GetColor.FromHex("#607FAE");
1112+
var targetBackgroundColor = ColorUtil.FromHex("#607FAE");
11141113
// -- Text colors -------------------
1115-
var originalTextColor = GetColor.FromHex("#BABABA");
1116-
var targetTextColor = GetColor.FromHex("#000000");
1114+
var originalTextColor = ColorUtil.FromHex("#BABABA");
1115+
var targetTextColor = ColorUtil.FromHex("#000000");
11171116
// -- Duration values ---------------
11181117
const int backgroundDurationMs = 500;
11191118
const int textDurationMs = 500;
@@ -1170,7 +1169,7 @@ private void WidthAnimation(VisualElement widthChangeAnimationLabel, Func<float,
11701169
const int durationInMs = 1000;
11711170
const int delayInMs = 1000;
11721171

1173-
widthChangeAnimationLabel.SetBorderColor(GetColor.FromHex("#6B7DFF"));
1172+
widthChangeAnimationLabel.SetBorderColor(ColorUtil.FromHex("#6B7DFF"));
11741173
widthAnimateFrom = widthChangeAnimationLabel.AnimateWidth(
11751174
currentWidth,
11761175
desiredWidth,
@@ -1211,7 +1210,7 @@ private void HeightAnimation(VisualElement heightChangeAnimationLabel, Func<floa
12111210

12121211
// -- Not necessarily needed, they just help --
12131212
// -- make the demo cleaner while animating --
1214-
heightChangeAnimationLabel.SetBorderColor(GetColor.FromHex("#6B7DFF"));
1213+
heightChangeAnimationLabel.SetBorderColor(ColorUtil.FromHex("#6B7DFF"));
12151214
button.style.alignSelf = Align.FlexStart;
12161215
buttonContainer.style.alignSelf = Align.FlexStart;
12171216
buttonContainer.style.paddingTop = 1;

Editor/ElementData.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ----------------------------------------------------------------------------
2+
// -- Project : https://github.com/instance-id/ElementAnimationToolkit --
3+
// -- instance.id 2020 | http://github.com/instance-id | http://instance.id --
4+
// ----------------------------------------------------------------------------
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using UnityEngine;
9+
using UnityEngine.UIElements;
10+
using Object = UnityEngine.Object;
11+
12+
namespace instance.id.EATK
13+
{
14+
[Serializable]
15+
public class ObjectElementData
16+
{
17+
[SerializeField] public string objectName;
18+
[SerializeField] public Object objectReference;
19+
[SerializeField] public Type objectType;
20+
[SerializeField] public Dictionary<string, VisualElement> elementData = new Dictionary<string, VisualElement>();
21+
22+
public ObjectElementData(Object obj)
23+
{
24+
objectReference = obj;
25+
objectName = obj.name;
26+
objectType = obj.GetType();
27+
}
28+
}
29+
}

Editor/ElementData/ObjectElementData.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/id.instance.elementanimationtoolkit.Editor.asmdef

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"name": "id.instance.elementanimationtoolkit.Editor",
3+
"rootNamespace": "",
34
"references": [
45
"id.instance.elementanimationtoolkit",
5-
"id.instance.extensions"
6+
"id.instance.extensions",
7+
"id.instance.extensions.Editor"
68
],
79
"includePlatforms": [
810
"Editor"

Runtime/Animations.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Extensions/Animations/AnimationExtensions.cs renamed to Runtime/Animations/AnimationExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// -- Project : https://github.com/instance-id/ElementAnimationToolkit --
33
// -- instance.id 2020 | http://github.com/instance-id | http://instance.id --
44
// ----------------------------------------------------------------------------
5-
5+
#if UNITY_EDITOR
66
using System;
77
using UnityEngine.UIElements;
88

9-
namespace instance.id.EATK.Extensions
9+
namespace instance.id.EATK
1010
{
1111
public static class AnimationExtensions
1212
{
@@ -21,3 +21,4 @@ public static void ExecuteIn(this Action action, VisualElement element, long de
2121
}
2222
}
2323
}
24+
#endif

Runtime/Animations/AnimationExtensions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Extensions/Animations/AnimationSequences.cs renamed to Runtime/Animations/AnimationSequences.cs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
// -- Note: EATK is still currently being developed - API subject to change --
66
// ----------------------------------------------------------------------------
77

8+
#if UNITY_EDITOR
89
using System;
910
using System.Collections.Generic;
1011
using System.Linq;
11-
using instance.id.Extensions;
12+
using instance.id.EATK.Extensions;
13+
// using instance.id.Extensions;
14+
// using instance.id.Extensions;
1215
using UnityEngine;
1316
using UnityEngine.UIElements;
1417
using UnityEngine.UIElements.Experimental;
1518

16-
namespace instance.id.EATK.Extensions
19+
namespace instance.id.EATK
1720
{
1821
public static class AnimationSequences
1922
{
@@ -35,16 +38,17 @@ public static class AnimationSequences
3538
/// <param name="callback">Function that can be called when the animation is completed</param>
3639
/// <param name="flexBasis">Set a custom flex basis</param>
3740
public static List<ValueAnimation<StyleValues>> AnimCharacterSequence(this VisualElement target, Color color1, Color color2, int cascadeMs, int durationMS,
38-
bool reverse = false,
39-
Action callback = null,
40-
float flexBasis = default)
41+
bool reverse = false,
42+
Action callback = null,
43+
float flexBasis = default)
4144
{
4245
var animatedValues = new List<ValueAnimation<StyleValues>>();
4346
VisualElementStyleStore styleData = new VisualElementStyleStore();
4447
var textString = "";
4548

4649
Label labelRef = new Label();
4750

51+
4852
if (target is AnimatedLabel label)
4953
{
5054
labelRef = label.GetLabel();
@@ -53,15 +57,6 @@ public static List<ValueAnimation<StyleValues>> AnimCharacterSequence(this Visua
5357
styleData.SourceName = target.name;
5458
}
5559

56-
if (doDebug)
57-
{
58-
var table = new TableBuilder();
59-
table.WithHeader("Name", "Value", "GetProperties - AnimSeq - l-54");
60-
var fields = styleData.GetType().GetProperties().ToList();
61-
fields.ForEach(x => { table.WithRow(x.Name, x.GetValue(styleData)); });
62-
table.ToConsole();
63-
}
64-
6560
new VisualElement().Create(out var animatedContainer).ToUSS(nameof(animatedContainer), "animated-label-container");
6661
animatedContainer.style.height = new StyleLength(StyleKeyword.Auto);
6762

@@ -71,7 +66,7 @@ public static List<ValueAnimation<StyleValues>> AnimCharacterSequence(this Visua
7166
Label animLabel = new Label();
7267

7368
if (!doDebug) animLabel = styleData.FromStyleData(new Label(textString[i].ToString()));
74-
else if (i == 0) animLabel = styleData.FromStyleData(new Label(textString[i].ToString()), doDebug);
69+
else if (i == 0) animLabel = styleData.FromStyleData(new Label(textString[i].ToString()));
7570

7671
if (!flexBasis.Equals(default)) animLabel.style.flexBasis = new Length(flexBasis);
7772
animLabel.SetMargin();
@@ -162,26 +157,26 @@ void AnimationComplete()
162157

163158

164159
public static void AnimFadeInSequence(this Label element, string newText = default, Color textColor = default, Color textDefaultColor = default, float fadeIn = 0f,
165-
float display = 0f,
166-
float fadeOut = 0f,
167-
Func<float, float> easing = null)
160+
float display = 0f,
161+
float fadeOut = 0f,
162+
Func<float, float> easing = null)
168163
{
169164
DoFadeInSequence(element, newText, textColor, textDefaultColor, fadeIn, display, fadeOut, element.text, easing);
170165
}
171166

172167
public static void AnimFadeInSequence(this VisualElement element, Color textColor = default, Color textDefaultColor = default, float fadeIn = 0f,
173-
float display = 0f,
174-
float fadeOut = 0f,
175-
Func<float, float> easing = null)
168+
float display = 0f,
169+
float fadeOut = 0f,
170+
Func<float, float> easing = null)
176171
{
177172
DoFadeInSequence(element, default, textColor, textDefaultColor, fadeIn, display, fadeOut, easing: easing);
178173
}
179174

180175
private static void DoFadeInSequence(this VisualElement element, string newText = default, Color textColor = default, Color textDefaultColor = default, float fadeIn = 0f,
181-
float display = 0f,
182-
float fadeOut = 0f,
183-
string originalText = default,
184-
Func<float, float> easing = null)
176+
float display = 0f,
177+
float fadeOut = 0f,
178+
string originalText = default,
179+
Func<float, float> easing = null)
185180
{
186181
var animFadeIn = new ValueAnimation<StyleValues>();
187182
var animWaiter = new ValueAnimation<StyleValues>();
@@ -240,7 +235,7 @@ private static ValueAnimation<StyleValues> DoFadeIn(VisualElement elementToFadeI
240235
{
241236
if (easing == null) easing = Easy.OutQuad;
242237
return elementToFadeIn.experimental.animation
243-
.Start(new StyleValues {opacity = 0.Zero()}, new StyleValues {opacity = 1}, (int) durationMs)
238+
.Start(new StyleValues { opacity = 0.Zero() }, new StyleValues { opacity = 1 }, (int)durationMs)
244239
.Ease(easing)
245240
.OnCompleted(callback);
246241
}
@@ -251,7 +246,7 @@ private static ValueAnimation<StyleValues> DoDisplayMessage(VisualElement elemen
251246
{
252247
if (easing == null) easing = Easy.OutQuad;
253248
return elementToDisplay.experimental.animation
254-
.Start(new StyleValues {opacity = 1}, new StyleValues {opacity = 1}, (int) durationMs)
249+
.Start(new StyleValues { opacity = 1 }, new StyleValues { opacity = 1 }, (int)durationMs)
255250
.Ease(easing)
256251
.OnCompleted(callback);
257252
}
@@ -262,11 +257,12 @@ private static ValueAnimation<StyleValues> DoFadeOut(VisualElement elementToFade
262257
{
263258
if (easing == null) easing = Easy.OutQuad;
264259
return elementToFadeOut.experimental.animation
265-
.Start(new StyleValues {opacity = 1}, new StyleValues {opacity = 0.Zero()}, (int) durationMs)
260+
.Start(new StyleValues { opacity = 1 }, new StyleValues { opacity = 0.Zero() }, (int)durationMs)
266261
.Ease(easing)
267262
.OnCompleted(callback);
268263
}
269264

270265
#endregion
271266
}
272267
}
268+
#endif

Runtime/Animations/AnimationSequences.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)