Skip to content

Commit

Permalink
Refactorings, additional base animation overloads
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
instance-id committed Jul 25, 2021
1 parent b185630 commit 14e19b8
Show file tree
Hide file tree
Showing 67 changed files with 2,841 additions and 268 deletions.
47 changes: 23 additions & 24 deletions Editor/EATKEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Linq;
using instance.id.EATK.Extensions;
using instance.id.Extensions;
using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.UIElements;
Expand Down Expand Up @@ -101,9 +100,9 @@ private void Assignments()
animatedIcon = (Texture2D) EditorGUIUtility.IconContent("ScriptableObject Icon").image;

// -- Color Assignments -----------------------
originalColor = GetColor.FromHex("#BABABA");
pulseStartColor = GetColor.FromHex("#7F3B3A");
pulseEndColor = GetColor.FromHex("#607FAE");
originalColor = ColorUtil.FromHex("#BABABA");
pulseStartColor = ColorUtil.FromHex("#7F3B3A");
pulseEndColor = ColorUtil.FromHex("#607FAE");
}

private StyleSheet StylesheetSetup()
Expand Down Expand Up @@ -277,8 +276,8 @@ private void BuildToolbarButtons(Toolbar toolbar)

// -- Register the HoverBorderPulse callback --
toolbarInfo.HoverBorderPulse(
pulseStartColor: GetColor.FromHex("#7F3B3A"),
pulseEndColor: GetColor.FromHex("#2F569C"),
pulseStartColor: ColorUtil.FromHex("#7F3B3A"),
pulseEndColor: ColorUtil.FromHex("#2F569C"),
colorDuration: 500);
}

Expand Down Expand Up @@ -754,7 +753,7 @@ private void FoldoutAnimation()
// -- AnimatedFoldout values ------------------
var openDelayMs = 500;
var closeDelayMs = 4500;
var animatedColor = GetColor.FromHex("#2F569C");
var animatedColor = ColorUtil.FromHex("#2F569C");

// -- Animated Label values -------------------
var cascadeMs = 50;
Expand Down Expand Up @@ -802,7 +801,7 @@ private void AnimateIdLabel()

instanceidLabel.AnimCharacterSequence(
color1: originalColor,
color2: GetColor.FromHex("#2F569C"),
color2: ColorUtil.FromHex("#2F569C"),
cascadeMs: cascadeMs,
durationMS: durationMs);
}
Expand All @@ -816,8 +815,8 @@ private void AnimateIdLabel()
private void ButtonCascadeAnimation() // @formatter:on
{
// -- Image colors ------------------
var buttonColor = GetColor.FromHex("#676767");
var endButtonColor = GetColor.FromHex("#2F569C");
var buttonColor = ColorUtil.FromHex("#676767");
var endButtonColor = ColorUtil.FromHex("#2F569C");
const int durationInMs = 500;
const int delayInMs = 1000;

Expand Down Expand Up @@ -910,9 +909,9 @@ private void HeaderInfoMenuAnimation(bool evt, VisualElement menuInfoContainer,
const int durationMs = 500;
const int inDurationMs = 300;
const int outDurationMs = 150;
var hoverLabelColor = GetColor.FromHex("#2F569C");
var originalInfoBgColor = GetColor.FromHex("#303030");
var toolbarHoverColor = GetColor.FromHex("#2F569C");
var hoverLabelColor = ColorUtil.FromHex("#2F569C");
var originalInfoBgColor = ColorUtil.FromHex("#303030");
var toolbarHoverColor = ColorUtil.FromHex("#2F569C");

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

menuInfoContainer.schedule.Execute(() =>
{
VisualElementBaseAnimation.AnimateBackgroundColor(menuInfoContainer, GetColor.FromHex("#212121"),
VisualElementBaseAnimation.AnimateBackgroundColor(menuInfoContainer, ColorUtil.FromHex("#212121"),
originalInfoBgColor,
400);
}).StartingIn(0);
Expand All @@ -1055,8 +1054,8 @@ void UnregisterHoverCallback()
private void ImageAnimation(VisualElement imageButton, Func<float, float> easing = null) // @formatter:on
{
// -- Image colors ------------------
var originalImageColor = GetColor.FromHex("#000000");
var targetImageColor = GetColor.FromHex("#607FAE");
var originalImageColor = ColorUtil.FromHex("#000000");
var targetImageColor = ColorUtil.FromHex("#607FAE");
const int durationInMs = 1000;
const int delayInMs = 1000;

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

const string newText = "then back to the original!";
var originalTextColor = GetColor.FromHex("#BABABA");
var animatedTextColor = GetColor.FromHex("#607FAE");
var originalTextColor = ColorUtil.FromHex("#BABABA");
var animatedTextColor = ColorUtil.FromHex("#607FAE");

fadeTextAnimationLabel.AnimFadeInSequence(
newText,
Expand All @@ -1110,10 +1109,10 @@ private void FadeColorAnimation(VisualElement fadeColorAnimationLabel, Func<floa
{
// -- Background colors -------------
var originalBackgroundColor = new StyleColor(StyleKeyword.Initial).value;
var targetBackgroundColor = GetColor.FromHex("#607FAE");
var targetBackgroundColor = ColorUtil.FromHex("#607FAE");
// -- Text colors -------------------
var originalTextColor = GetColor.FromHex("#BABABA");
var targetTextColor = GetColor.FromHex("#000000");
var originalTextColor = ColorUtil.FromHex("#BABABA");
var targetTextColor = ColorUtil.FromHex("#000000");
// -- Duration values ---------------
const int backgroundDurationMs = 500;
const int textDurationMs = 500;
Expand Down Expand Up @@ -1170,7 +1169,7 @@ private void WidthAnimation(VisualElement widthChangeAnimationLabel, Func<float,
const int durationInMs = 1000;
const int delayInMs = 1000;

widthChangeAnimationLabel.SetBorderColor(GetColor.FromHex("#6B7DFF"));
widthChangeAnimationLabel.SetBorderColor(ColorUtil.FromHex("#6B7DFF"));
widthAnimateFrom = widthChangeAnimationLabel.AnimateWidth(
currentWidth,
desiredWidth,
Expand Down Expand Up @@ -1211,7 +1210,7 @@ private void HeightAnimation(VisualElement heightChangeAnimationLabel, Func<floa

// -- Not necessarily needed, they just help --
// -- make the demo cleaner while animating --
heightChangeAnimationLabel.SetBorderColor(GetColor.FromHex("#6B7DFF"));
heightChangeAnimationLabel.SetBorderColor(ColorUtil.FromHex("#6B7DFF"));
button.style.alignSelf = Align.FlexStart;
buttonContainer.style.alignSelf = Align.FlexStart;
buttonContainer.style.paddingTop = 1;
Expand Down
3 changes: 3 additions & 0 deletions Editor/ElementData.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Editor/ElementData/ObjectElementData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------------
// -- Project : https://github.com/instance-id/ElementAnimationToolkit --
// -- instance.id 2020 | http://github.com/instance-id | http://instance.id --
// ----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;

namespace instance.id.EATK
{
[Serializable]
public class ObjectElementData
{
[SerializeField] public string objectName;
[SerializeField] public Object objectReference;
[SerializeField] public Type objectType;
[SerializeField] public Dictionary<string, VisualElement> elementData = new Dictionary<string, VisualElement>();

public ObjectElementData(Object obj)
{
objectReference = obj;
objectName = obj.name;
objectType = obj.GetType();
}
}
}
3 changes: 3 additions & 0 deletions Editor/ElementData/ObjectElementData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Editor/id.instance.elementanimationtoolkit.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "id.instance.elementanimationtoolkit.Editor",
"rootNamespace": "",
"references": [
"id.instance.elementanimationtoolkit",
"id.instance.extensions"
"id.instance.extensions",
"id.instance.extensions.Editor"
],
"includePlatforms": [
"Editor"
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Animations.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// -- Project : https://github.com/instance-id/ElementAnimationToolkit --
// -- instance.id 2020 | http://github.com/instance-id | http://instance.id --
// ----------------------------------------------------------------------------

#if UNITY_EDITOR
using System;
using UnityEngine.UIElements;

namespace instance.id.EATK.Extensions
namespace instance.id.EATK
{
public static class AnimationExtensions
{
Expand All @@ -21,3 +21,4 @@ public static void ExecuteIn(this Action action, VisualElement element, long de
}
}
}
#endif
11 changes: 11 additions & 0 deletions Runtime/Animations/AnimationExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
// -- Note: EATK is still currently being developed - API subject to change --
// ----------------------------------------------------------------------------

#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Linq;
using instance.id.Extensions;
using instance.id.EATK.Extensions;
// using instance.id.Extensions;
// using instance.id.Extensions;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;

namespace instance.id.EATK.Extensions
namespace instance.id.EATK
{
public static class AnimationSequences
{
Expand All @@ -35,16 +38,17 @@ public static class AnimationSequences
/// <param name="callback">Function that can be called when the animation is completed</param>
/// <param name="flexBasis">Set a custom flex basis</param>
public static List<ValueAnimation<StyleValues>> AnimCharacterSequence(this VisualElement target, Color color1, Color color2, int cascadeMs, int durationMS,
bool reverse = false,
Action callback = null,
float flexBasis = default)
bool reverse = false,
Action callback = null,
float flexBasis = default)
{
var animatedValues = new List<ValueAnimation<StyleValues>>();
VisualElementStyleStore styleData = new VisualElementStyleStore();
var textString = "";

Label labelRef = new Label();


if (target is AnimatedLabel label)
{
labelRef = label.GetLabel();
Expand All @@ -53,15 +57,6 @@ public static List<ValueAnimation<StyleValues>> AnimCharacterSequence(this Visua
styleData.SourceName = target.name;
}

if (doDebug)
{
var table = new TableBuilder();
table.WithHeader("Name", "Value", "GetProperties - AnimSeq - l-54");
var fields = styleData.GetType().GetProperties().ToList();
fields.ForEach(x => { table.WithRow(x.Name, x.GetValue(styleData)); });
table.ToConsole();
}

new VisualElement().Create(out var animatedContainer).ToUSS(nameof(animatedContainer), "animated-label-container");
animatedContainer.style.height = new StyleLength(StyleKeyword.Auto);

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

if (!doDebug) animLabel = styleData.FromStyleData(new Label(textString[i].ToString()));
else if (i == 0) animLabel = styleData.FromStyleData(new Label(textString[i].ToString()), doDebug);
else if (i == 0) animLabel = styleData.FromStyleData(new Label(textString[i].ToString()));

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


public static void AnimFadeInSequence(this Label element, string newText = default, Color textColor = default, Color textDefaultColor = default, float fadeIn = 0f,
float display = 0f,
float fadeOut = 0f,
Func<float, float> easing = null)
float display = 0f,
float fadeOut = 0f,
Func<float, float> easing = null)
{
DoFadeInSequence(element, newText, textColor, textDefaultColor, fadeIn, display, fadeOut, element.text, easing);
}

public static void AnimFadeInSequence(this VisualElement element, Color textColor = default, Color textDefaultColor = default, float fadeIn = 0f,
float display = 0f,
float fadeOut = 0f,
Func<float, float> easing = null)
float display = 0f,
float fadeOut = 0f,
Func<float, float> easing = null)
{
DoFadeInSequence(element, default, textColor, textDefaultColor, fadeIn, display, fadeOut, easing: easing);
}

private static void DoFadeInSequence(this VisualElement element, string newText = default, Color textColor = default, Color textDefaultColor = default, float fadeIn = 0f,
float display = 0f,
float fadeOut = 0f,
string originalText = default,
Func<float, float> easing = null)
float display = 0f,
float fadeOut = 0f,
string originalText = default,
Func<float, float> easing = null)
{
var animFadeIn = new ValueAnimation<StyleValues>();
var animWaiter = new ValueAnimation<StyleValues>();
Expand Down Expand Up @@ -240,7 +235,7 @@ private static ValueAnimation<StyleValues> DoFadeIn(VisualElement elementToFadeI
{
if (easing == null) easing = Easy.OutQuad;
return elementToFadeIn.experimental.animation
.Start(new StyleValues {opacity = 0.Zero()}, new StyleValues {opacity = 1}, (int) durationMs)
.Start(new StyleValues { opacity = 0.Zero() }, new StyleValues { opacity = 1 }, (int)durationMs)
.Ease(easing)
.OnCompleted(callback);
}
Expand All @@ -251,7 +246,7 @@ private static ValueAnimation<StyleValues> DoDisplayMessage(VisualElement elemen
{
if (easing == null) easing = Easy.OutQuad;
return elementToDisplay.experimental.animation
.Start(new StyleValues {opacity = 1}, new StyleValues {opacity = 1}, (int) durationMs)
.Start(new StyleValues { opacity = 1 }, new StyleValues { opacity = 1 }, (int)durationMs)
.Ease(easing)
.OnCompleted(callback);
}
Expand All @@ -262,11 +257,12 @@ private static ValueAnimation<StyleValues> DoFadeOut(VisualElement elementToFade
{
if (easing == null) easing = Easy.OutQuad;
return elementToFadeOut.experimental.animation
.Start(new StyleValues {opacity = 1}, new StyleValues {opacity = 0.Zero()}, (int) durationMs)
.Start(new StyleValues { opacity = 1 }, new StyleValues { opacity = 0.Zero() }, (int)durationMs)
.Ease(easing)
.OnCompleted(callback);
}

#endregion
}
}
#endif
11 changes: 11 additions & 0 deletions Runtime/Animations/AnimationSequences.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 14e19b8

Please sign in to comment.