How-to change an UIAnimation through script

To switch or change a UIAnimation through script one only needs a reference to the target component.

Instructions

UIView

The following example shows how one can change the move direction animation parameter of a UIView’s show animation.

By following this example you can change any of the animation parameters of a target UIAnimation

This works for any component that has uses UIAnimations (eg. UIView, UIButton, UIToggle, etc…)

using Doozy.Engine.UI; using Doozy.Engine.UI.Animation; namespace MyNamespace { public class TestScript { /// <summary> Public reference to the target UIView </summary> public UIView MyUIView; /// <summary> This method sets the move from location for the target UIView and triggers it's show animation </summary> /// <param name="instantAction"> Should the animation happen instantly? (zero seconds) </param> public void ShowViewFromDirection(UIView targetView, Direction moveFrom, bool instantAction = false) { if(targetView == null) return; //check target view for null targetView.ShowBehavior.Animation.Move.Direction = moveFrom; //set move from direction targetView.Show(instantAction); //trigger the show animation for the target view } //------------------------- //---- How-to use examples //------------------------- public void ShowViewFromLeft() { ShowViewFromDirection(MyUIView, Direction.Left); } public void ShowViewFromRight() { ShowViewFromDirection(MyUIView, Direction.Right); } public void ShowViewFromTop() => ShowViewFromDirection(MyUIView, Direction.Top); public void ShowViewFromBottom() => ShowViewFromDirection(MyUIView, Direction.Bottom); } }

 

UIButton

The following example shows how one can swap an UIAnimation with another for an UIButton component.

This works for any component that has uses UIAnimations (eg. UIView, UIButton, UIToggle, etc…)

using Doozy.Engine.UI; using Doozy.Engine.UI.Animation; namespace MyNamespace { public class TestScript { /// <summary> Public reference to a target UIButton </summary> public UIButton MyUIButton; /// <summary> Custom UIAnimation A (you can edit it in the Editor) </summary> public UIAnimation MyCustomPunchUIAnimationA; /// <summary> Custom UIAnimation B (you can edit it in the Editor) </summary> public UIAnimation MyCustomPunchUIAnimationB; public void SetCustomOnClickButtonAnimation(UIButton targetButton, UIAnimation targetPunchAnimation) { if (targetButton == null) return; //null check for the button if (targetPunchAnimation == null) return; //null check for the animation if (targetPunchAnimation.AnimationType != AnimationType.Punch) return; //make sure this is the proper animation type targetButton.OnClick.Enabled = true; //force on click animation to be enabled (optional step) targetButton.OnClick.PunchAnimation = targetPunchAnimation; //change the on click animation for the button } //------------------------- //---- How-to use examples //------------------------- public void SetAnimationA() { SetCustomOnClickButtonAnimation(MyUIButton, MyCustomPunchUIAnimationA); } public void SetAnimationB() => SetCustomOnClickButtonAnimation(MyUIButton, MyCustomPunchUIAnimationB); } }

 

UIToggle

The following example shows how one can change an UIAnimation with another one, from the presets database, for a UIToggle component.

using Doozy.Engine.UI; namespace MyNamespace { public class TestScript { /// <summary> Public reference to a target UIToggle </summary> public UIToggle MyUIToggle; /// <summary> Preset Category Name (must exist in the target preset database) </summary> public string PresetCategoryName; /// <summary> Preset Category Name (must exist in the target preset category) </summary> public string PresetName; /// <summary> Loads a preset for the the OnClick animation of a target UIToggle </summary> /// <param name="targetToggle"> Target UIToggle </param> /// <param name="presetCategoryName"> Preset category name (must exist in the target preset database) </param> /// <param name="presetName"> Preset name (must exist in the target preset category) </param> public void LoadPresetAnimation(UIToggle targetToggle, string presetCategoryName, string presetName) { if (targetToggle == null) return; //null check for the button targetToggle.OnClick.LoadPreset(presetCategoryName, presetName); } //------------------------- //---- How-to use examples //------------------------- public void LoadPreset() { LoadPresetAnimation(MyUIToggle, PresetCategoryName, PresetName); //loads the target preset } public void LoadJumpClickOutPreset() { LoadPresetAnimation(MyUIToggle, "Jump", "ClickOut"); //this preset exists in the database (by default) } public void LoadOrganicJellyFastPreset() => LoadPresetAnimation(MyUIToggle, "Organic", "JellyFast"); } }