Animation Sequencer

repository·develop·Indexed 23 days ago

https://github.com/brunomikoski/animation-sequencer

A Unity tool for creating and previewing complex sequences of DOTween animations and custom actions directly within the Editor. Version 0.5.5 requires DOTween v1.2.632. It allows users to define animation steps, create custom actions by inheriting from AnimationStepBase or DOTweenActionBase, and visualize sequences using a preview bar to reduce recompilation during tweaking.

Tokens
1.5K
Snippets
4
Records
7
Agent score
29%

What's inside Animation Sequencer

  1. Install Animation Sequencer via GitHub

    develop

    You can add the package directly from GitHub in Unity 2019.4+. Note that this method does not support automatic updates via the Package Manager.

    1. Open the Package Manager.
    2. Click the + button and select Add from Git URL.
    3. Paste https://github.com/brunomikoski/Animation-Sequencer.git.
    4. Click Add.
    https://github.com/brunomikoski/Animation-Sequencer.git
  2. Install Animation Sequencer via OpenUPM

    develop

    The recommended way to install the package is via a scoped registry using OpenUPM.

    1. Open Edit/Project Settings/Package Manager.
    2. Add a new Scoped Registry with the following details:
      • Name: OpenUPM
      • URL: https://package.openupm.com/
      • Scopes: com.brunomikoski and com.demigiant
    3. Click Save.
    4. Open the Package Manager.
    5. Click the + button and select Add from Git URL.
    6. Paste com.brunomikoski.animationsequencer and click Add.
    Name: OpenUPM
    URL:  https://package.openupm.com/
    Scope(s): com.brunomikoski
              com.demigiant
  3. How to use Animation Sequencer in Unity

    develop

    Animation Sequencer allows you to create complex sequences of Tweens and Actions that can be previewed directly in the Editor.

    Prerequisites:

    • You must have DOTween installed in your project.
    • You must have properly created asmdef files for DOTween using the DOTween setup panel.

    Workflow:

    1. Add the AnimationSequencer component to any GameObject.
    2. Under the Animation Steps section, click the + button to add a new step.
    3. Select a <kbd>Tween Target</kbd> step.
    4. Use the <kbd>Add Actions</kbd> interface to add specific tweens (e.g., DOMove, DOScale) to that target.
    5. Use the Preview bar to play and visualize the animation in Editor Time.
    6. To trigger the animation via code, call animationSequencer.Play();.
  4. Configure AnimationSequencer initialization settings

    develop

    The AnimationSequencer component has initialization settings that determine how it behaves during the Awake lifecycle:

    • None: Does nothing during the Awake method.
    • PrepareToPlayOnAwake: Prepares the Tweens to be ready to play at their initial values during Awake.
    • PlayOnAwake: Automatically plays the animation sequence when the object is initialized (Awake).
  5. Troubleshoot DOTween errors in Animation Sequencer

    develop

    If you encounter errors such as error CS1929: 'CanvasGroup' does not contain a definition for 'DOFade', it indicates that the DOTween setup is incomplete.

    Solution: Ensure you have completed the DOTween setup and generated the necessary asmdef files by navigating to: Tools/Demigiant/DOTween Utility Panel.

  6. Create custom DOTween actions

    develop

    If you have custom DOTween extensions, you can add them to the sequencer by extending DOTweenActionBase. This allows you to define a specific TargetComponentType and implement the CreateTween method.

    Note: Tweens are created during the PrepareToPlay method on Awake and are paused to ensure performance.

    [Serializable]
    public sealed class ChangeMaterialStrengthDOTweenAction : DOTweenActionBase
    {
        public override string DisplayName => "Change Material Strength";
            
        public override Type TargetComponentType => typeof(Renderer);
    
        [SerializeField, Range(0,1)]
        private float materialStrength = 1;
    
         public override bool CreateTween(GameObject target, float duration, int loops, LoopType loopType)
         {
            Renderer renderer = target.GetComponent<Renderer>();
            if (renderer == null)
                return false;
    
            TweenerCore<float, float, FloatOptions> materialTween = renderer.sharedMaterial.DOFloat(materialStrength, "Strength", duration);
            
            SetTween(materialTween, loops, loopType);
            return true;
         }
    }
  7. Create custom animation actions

    develop

    To create a custom action that integrates with the sequencer, your class must inherit from AnimationStepBase and be marked as [Serializable] so it appears in the Inspector. You must implement AddTweenToSequence to connect your logic to the DOTween Sequence.

    Example of a custom step that plays a legacy Unity Animation clip:

    [Serializable]
     public class PlayLegacyAnimation : AnimationStepBase
     {
         public override string DisplayName => "Play Legacy Animation";
    
         [SerializeField]
         private Animation animation;
    
         public override void AddTweenToSequence(Sequence animationSequence)
         {
             animationSequence.AppendInterval(Delay);
             animationSequence.AppendCallback(
                 () =>
                 {
                     animation.Play();
                 }
             );
             animationSequence.AppendInterval(animation.clip.length);
         }
     }