/tween-creator

Create complex tweens and preview them instantly in editor mode

Primary LanguageC#MIT LicenseMIT

Tween Creator

openupm

An add-on to DOTween that allows creating and previewing complex tweens in the editor.

Great for animating UIs.

Note: meant for Unity versions 2021.2 or later, explained here.

Installation

See "Installation" on OpenUPM. Add these scopes:

  • com.thejoun
  • com.solidalloy
  • org.nuget

DOTween integration

Make sure you've got DOTween installed (either the free version or Pro).

Additionally, you'll nee to create an .asmdef file for DoTween modules. Go to Tools > Demigiant > DoTween Utility Panel and then select Create ASMDEF....

Tween Creator references the .asmdef file by GUID, and the created one has a random GUID assigned. To fix the reference, find the meta file (Assets\Plugins\Demigiant\DOTween\Modules\DOTween.Modules.asmdef.meta) and replace the guid value with 4a27d636c21081747a8c6b481cccc046. Then reload your project.

That's the only way I know to make the plugin work with DOTween. As of february 2023 there are ongoing efforts to release DOTween as a package, which would make the whole thing a lot easier (see issue on github).

Features

Tweens defined in components

Component

Intuitive composition of groups and sequences in hierarchy

Hierarchy

Instant preview in editor mode

There are no side effects, which means no changes will be left on any objects when you press RESET, compared to the state before starting PREVIEW.

Some changes may be left on objects if you're using a version of Unity before 2021.2. That's because a certain method is unavailable.

Preview

Quick type switch from context menu

To switch the type of a Tween component, right-click the component's header and choose 'Switch Type'.

Switch

Easy usage

// can assign any type of tween, group or sequence
[SerializeField] private TweenPlayable tween;

private void Test()
{
    // use any of these to play:
    tween.PlayForward();
    tween.PlayBackwards();
    tween.RewindAndPlayForward();
    tween.Rewind();
}

Custom tweens

[TypeCategory(TweenCategory.Basic)]
public class TweenScale : TweenCustomPlayable
{
    [Header("Scale")]
    [SerializeField] private Transform tr;
    [SerializeField] private Vector3 target = Vector3.one;
    [SerializeField] private Vector3 origin = Vector3.one;
        
    private Vector3 m_savedState;

    public override void PlayForward() => PlaySingleTween(tr.DOScale(target, duration));
    public override void PlayBackwards() => PlaySingleTween(tr.DOScale(origin, duration));
     
    public override void SavePreviewState() => m_savedState = tr.localScale;
    public override void RestorePreviewState() => tr.localScale = m_savedState;
        
    public override void Rewind()
    {
        base.Rewind();
            
        tr.localScale = origin;
    }
}

The TypeCategory attribute is used to group certain tweens together in the type switch context menu.

Custom eases as animation curves

Curve

Dependencies