All Projects → dubit → duck-tween

dubit / duck-tween

Licence: MIT, Unknown licenses found Licenses found MIT LICENSE Unknown LICENSE.meta
A tween library for unity

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to duck-tween

SwiftTweener
A pure Swift animation engine.
Stars: ✭ 74 (+221.74%)
Mutual labels:  tween, tweening
kinieta
A Fast Animation Engine with an Intuitive API
Stars: ✭ 44 (+91.3%)
Mutual labels:  tween, tweening
ux-animate
A simple but powerful tweening, spring physics, animation library for Rust
Stars: ✭ 19 (-17.39%)
Mutual labels:  tween, tweening
Black
World's fastest HTML5 2D game engine   🛸
Stars: ✭ 174 (+656.52%)
Mutual labels:  tween
Juggle
juggle是一个极简的、组件式的js框架。无依赖,完美闭包,灵活且适合渐进学习,可与任何框架整合。包含(支持冒泡的事件 || Tween || MV框架 || http || websocket || 资源 || 模块)等组件,按需选择组件,不绑架开发者。
Stars: ✭ 208 (+804.35%)
Mutual labels:  tween
FluentTransitions
▶ Smooth UI animations & transitions for .NET
Stars: ✭ 27 (+17.39%)
Mutual labels:  tweening
unity-async-tweens
Tween Extension to Unity-AsyncRoutines
Stars: ✭ 16 (-30.43%)
Mutual labels:  tween
Fat
Web's fastest and most lightweight animation tool.
Stars: ✭ 157 (+582.61%)
Mutual labels:  tween
MintAnimation
一款高效易用的Unity插值动画系统,可以快速制作UI动画
Stars: ✭ 84 (+265.22%)
Mutual labels:  tween
MKTween
Lightweight tween framework in Swift 5.0
Stars: ✭ 14 (-39.13%)
Mutual labels:  tween
Juicer
Juicer is a generic animation / motion library for macOS & iOS & tvOS written in Swift
Stars: ✭ 13 (-43.48%)
Mutual labels:  tween
Urmotion
Flexible motion engine for non time-based animation in Unity.
Stars: ✭ 220 (+856.52%)
Mutual labels:  tween
UnityCore
A collection of essential game systems for Unity 3D. These generic systems can be applied to any Unity project.
Stars: ✭ 105 (+356.52%)
Mutual labels:  tween
Kute.js
KUTE.js is a JavaScript animation engine for modern browsers.
Stars: ✭ 2,270 (+9769.57%)
Mutual labels:  tween
ue4-uitween
Unreal 4 UMG UI tweening plugin in C++
Stars: ✭ 178 (+673.91%)
Mutual labels:  tween
Scrollissimo
Javascript plugin for smooth scroll-controlled animations
Stars: ✭ 160 (+595.65%)
Mutual labels:  tween
godot-action-animation-framework
create animation easy in Godot with GDAction
Stars: ✭ 43 (+86.96%)
Mutual labels:  tween
ezaction
基于cocos creator的2D动画框架。An extension animation framework for cocos creator.
Stars: ✭ 24 (+4.35%)
Mutual labels:  tween
BeauRoutine
Coroutine and tweening framework for Unity3D
Stars: ✭ 88 (+282.61%)
Mutual labels:  tween
interpolations
Lightweight Unity library for smoothing movements and value progressions in code (dragging, easing, tweening).
Stars: ✭ 29 (+26.09%)
Mutual labels:  tweening

unity-tween

What is it?

A simple to use tween library, for moving things with code

What are the requirements?

  • Unity 2018.x +

Contributing

Releasing

  • Use gitflow
  • Create a release branch for the release
  • On that branch, bump version number in package json file, any other business (docs/readme updates)
  • Merge to master via pull request and tag the merge commit on master.
  • Merge back to development.

DUCK

This repo is part of DUCK (dubit unity component kit) DUCK is a series of repos containing reusable component, utils, systems & tools.

DUCK packages can be added to a project as git submodules or by using Unity Package Manager.

How to use it

Creating Tweens

There are a lot of ways to create tweens, the 2 primary ways are

Using Constructors:

// animation position using a MoveAnimation
var animation = new MoveAnimation(targetObject, from, to, duration, easing);

Using extension methods

// This is just shorthand for the above
var animation = myTransform.Move(from, to, duration, easing);

Although there are a lot of these, the function signatures are usually similar

Name Description
target The object that the tween will affect
from the initial state (could be position, rotation, scale, opacity, color etc
to the final state (will be the same type as from
duration The duration in seconds of how long the tween will take to complete, defaults to 1.0f
easing The type of easing to apply, defaults to Linear, please see easing for more info
localSpace (only on some functions), a boolean to control whether or not to use local space, for moving and rotation.

Delegate Animations

Sometimes you don't always know the from parameter at the time you create the tween. You only know that at the time we want to play the tween. Delegate animations are used to acheive this.

A delegate animation takes a function that returns an animation. It won't get called until it is played.

var animation = new DelegateAnimation<MoveAnimation>(() => {
  return new MoveAnimation(target, target.position, finalPosition);
});

This allows you to not worry about the starting state, just care about where it should go to.

Several extensions exist to do this for you. MoveTo, ScaleTo FadeTo etc. all just make a delegate animation so at play time, the from will be the current state it's in.

Easing

The easing paramater defaults to a linear ease, but you can pass any function you want into it with the following signature Func<float, float>. This library comes with several built-in ones; the most common ones found here.

They are all under the ease class with nested classes/functions for each type.

Example: Scale from 0f to 1f, over half a second using back-out easing

transform.Scale(0f, 1f, 0.5f, Ease.Back.Out)

Playing Tweens

Once you have created one, playing a tween is easy

tween.Play();

You can also pass in a callback for when the tween completes

tween.Play(() => { Debug.Log("It's complete"); });

Play(repeatCount)

TweenCollections

There are 2 types of animation collections, a SequencedAnimation for creating a sequence of tweens and ParalleledAnimation for playing tweens in parallel.

Both are types of AnimationCollection.

You can create either of these collections using a fluent interface. There are extension methods for every type of tween. As well as an Add function for adding any Tween.

var sequence = new SequencedAnimation()
    // Use extension methods
    .FadeTo(spriteRenderer, 1f)
    .Scale(transform, 0, 1f, 0.24, Ease.Back.Out)
    // Or use a paralleled within the sequence
    .Parallel(p => p
        // thse are nested within the parallel
        .Move(transform, positionA, positionB)
        .RotateY(transform, 0, 360))
    // or just use add
    .Add(new MoveAnimation(target, from, to, duration)

ParalleledAnimations are created in the same way.

Advanced playback features

Abort()

A tween can be aborted during playback by calling the abort function. The objects will be left in whatever state they are in when the tween is aborted.

FastForward()

A tween can also be fast forwarded to the end. This effectively immediately stops the tween and fires the final update frame, so the objects are left in a state equivelant to how they would be if the tween had completed.

Reverse()

Calling reverse will put the tween in reverse. It can be used prior to or during playback. If reversed it will cause the animation to play in reverse. For sequenced collections, it will play the animations in reverse order

ChangeSpeed(float multiplier)

Change speed will change the animations speed by a multiplier. For example ChangeSpeed(2.0f) will double the speed of the animation. The effects are permanent and therefore cumulative, so calling ChangeSpeed(2.0f) twice will result in the animation now being 4 times as fast as the original.

ScaleTime(float duration)

Scale time allows you to change the duration of an animation. This will end up changing the speed. If this is called during playback the progress is maintained. Example. If you are 60% of the way through a 1s animation (elapsed time = 0.6f), and then call ScaleTime(2f). The animation is now 2 seconds long and the progress will remain at 60%, and elapsed time will change to 1.2f. (60% of 2s). The animation therefore will not jump ot a different point, and will still be smooth.

AnimationDrivers

The updates for tweens are driven by animation drivers.

An animation driver is just an instance of class that implements IAnimationDriver. This interface just requires 2 functions, Add(Func<float> update) and Remove(Func<float> update). This allows tweens to add and remove their update functions as they need. Once added the animation driver will call those update functions every frame, passing in the delta time.

The system uses DefaultAnimationDriver out of the box passing in Time.unscaledDeltaTime.

You can override the default driver like this:

TimedAnimation.DefaultDriver = myCustomAnimationDriver;

Now every new tween created after this assignment will use your driver by default.

You can also override the driver per tween for even more control like this:

var tween = new MoveAnimation(transform, startPos, endPos);
tween.AnimationDriver = myCustomAnimationDriver;

You cannot change the animation driver during playback, it must be assigned before playing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].