Background Color Fade-In |
|
---|---|
(The initial fade from gray to blue) |
Color originalColor = GetColor.FromHex("#BABABA");
Color fadeColor = GetColor.FromHex("#2F569C");
var durationOfFade = 250; // In milliseconds
VisualElement visualElement = new VisualElement();
visualElement.AnimateBackgroundColor(originalColor, fadeColor, durationOfFade);
Hover Border Pulse |
|
---|---|
VisualElement visualElement = new VisualElement();
visualElement.HoverBorderPulse(pulseStartColor: GetColor.FromHex("#7F3B3A"), pulseEndColor: GetColor.FromHex("#2F569C"), colorDuration: 500);
Fade-in sequence |
|
---|---|
Label label = new Label {text = "Click button to make me fade!"};
const int fadeInTime = 500;
const float displayTime = 2000f;
const int fadeOutTime = 500;
string newText = "then back to the original!";
var originalTextColor = GetColor.FromHex("#BABABA");
var animatedTextColor = GetColor.FromHex("#607FAE");
label.AnimFadeInSequence(newText, animatedTextColor, originalTextColor, fadeInTime, displayTime, fadeOutTime);
Then, of course, there is everything in between.
Additionally there are many helper methods relating to many different Types from Color to opening weblinks in the browser.
Usage:
Color color = GetColor.FromHex("#CCCCCC");
Implementation:
public static Color FromHex(this string color)
{
if (!color.StartsWith("#")) Debug.LogWarning("The FromHex() function must be used on a hexadecimal string beginning with #");
ColorUtility.TryParseHtmlString(color, out var outColor);
return outColor;
}
Usage:
VisualElement visualElement = new VisualElement();
visualElement.OpenURL("https://github.com/instance-id/ElementAnimationToolkit");
Implementation:
public static T OpenURL<T>(this T element, string url) where T : VisualElement
{
element.RegisterCallback<MouseUpEvent>(evt =>
{
if (evt.button == 0)
{
Application.OpenURL(url);
evt.StopPropagation();
}
});
return element;
}