Skip to content

About

Single-file tween helper for Unity built on UniRx — 6 easing curves, unscaled time, no MonoBehaviour required

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

UniRxForTween

Unity UniRx License

English | 한국어

A single-file tweening helper for Unity, built on top of UniRx.

SimpleTweener drives a value over time through Observable.FromCoroutine, handing you the interpolated float every frame via an onNext callback and signalling the end with onCompleted. No tween library, no component to attach, no scene setup — one class, one file.

SimpleTweener.EaseOut(0.25f, value => canvasGroup.alpha = value, () => Debug.Log("Done!"));

Features

  • Single file — drop SimpleTweener.cs into your project and you are done.
  • 6 easing curves — Linear, Ease In, Ease Out, Ease In-Out, Bounce In, Bounce Out.
  • Value-driven, not property-driven — you get a float, so you decide what it animates: position, scale, alpha, Image.fillAmount, a score counter, an audio volume fade, anything.
  • Unscaled time — driven by Time.unscaledDeltaTime, so tweens keep running while Time.timeScale == 0. Ideal for pause menus and UI.
  • No MonoBehaviour required — a plain C# class; the coroutine is hosted by UniRx's MainThreadDispatcher, so it works from anywhere, including non-MonoBehaviour code.

Requirements

Unity 5.5 or later (any version supported by UniRx)
Dependency UniRx

Installation

  1. Install UniRx — via UPM, OpenUPM, or the Asset Store package.
  2. Copy SimpleTweener.cs anywhere under your Assets/ folder.

That's the whole install. SimpleTweener lives in the global namespace, so no using is needed beyond UniRx's own.

Usage

Basic

A tween starts the moment you create it.

void DoTween()
{
    // Interpolates 0 -> 1 over 0.25 seconds.
    SimpleTweener.EaseIn(0.25f, OnNext, OnCompleted);
}

void OnNext(float value)
{
    transform.localScale = Vector3.one * value;
}

void OnCompleted()
{
    // Done!
}

Custom range

// Counts 0 -> 100 over 0.25 seconds with an ease in-out curve.
SimpleTweener.EaseInOut(0f, 100f, 0.25f, value => label.text = ((int)value).ToString(), OnCompleted);

Callback-only or value-only

Every curve exposes an overload for each shape, so you can skip the callback you don't need.

SimpleTweener.BounceOut(0.4f, OnNext);       // value only
SimpleTweener.BounceOut(0.4f, OnCompleted);  // completion only

Lambdas and lerping

Vector3 from = transform.position;
Vector3 to = target.position;

SimpleTweener.EaseOut(0.5f, t => transform.position = Vector3.Lerp(from, to, t));

Delay

EaseOut and the constructor accept a delay, applied before the curve starts.

// Waits 1 second, then fades 1 -> 0 over 0.3 seconds.
SimpleTweener.EaseOut(1f, 0f, 1f, 0.3f, value => canvasGroup.alpha = value, OnCompleted);

Chaining

Start the next tween from onCompleted.

SimpleTweener.EaseOut(0.2f, t => Scale(t), () =>
{
    SimpleTweener.BounceOut(0.3f, t => Bounce(t));
});

Linear

Linear has no static factory — use the constructor directly.

new SimpleTweener(SimpleTweener.Method.Linear, 0f, 1f, 0f, 0.25f, OnNext, OnCompleted);

API

Static factories

Available for EaseIn, EaseOut, EaseInOut, BounceIn and BounceOut:

Signature Range Delay
(float duration, Action<float> onNext) 0 → 1 none
(float duration, Action onCompleted) 0 → 1 none
(float duration, Action<float> onNext, Action onCompleted) 0 → 1 none
(float from, float to, float duration, Action<float> onNext, Action onCompleted) from → to none

EaseOut is the exception to the last row — it takes a delay as well:

Signature Range Delay
EaseOut(float from, float to, float delay, float duration, Action<float> onNext, Action onCompleted) from → to delay

Constructor

The full surface, and the only way to reach Method.Linear:

public SimpleTweener(
    SimpleTweener.Method method,
    float from,
    float to,
    float delay,
    float duration,
    System.Action<float> onNext,
    System.Action onCompleted)
Parameter Description
method Easing curve — see SimpleTweener.Method.
from Start value.
to End value.
delay Seconds to wait before the curve starts, in unscaled time.
duration Length of the tween in seconds. 0 completes in a single frame.
onNext Called every frame with the interpolated value. May be null.
onCompleted Called once when the tween reaches to. May be null.

SimpleTweener.Method

Method Curve Notes
Linear t Constant speed. Constructor only.
EaseIn 1 - sin(π/2 · (1 - t)) Slow start, fast finish.
EaseOut sin(π/2 · t) Fast start, slow finish.
EaseInOut t - sin(2πt) / 2π Slow at both ends.
BounceIn bounce Bounces at the start.
BounceOut bounce Bounces at the end (overshoot settle).

Notes and limitations

  • A tween starts immediately. Constructing a SimpleTweener — through a factory or the constructor — subscribes right away. There is no separate Play().
  • There is no stop or cancel API. The internal IDisposable is not exposed, so a tween always runs to completion. If the object you are animating can be destroyed mid-tween, null-check inside your onNext:
    SimpleTweener.EaseOut(0.3f, t => { if (this != null) canvasGroup.alpha = t; });
  • The first emitted value is always 0f, sent before the delay begins — not from. With a descending range such as from: 100, to: 0, expect a 0f on the first frame. Set the initial state yourself before starting the tween if that matters.
  • Linear has no static factory. Use the constructor.
  • EaseOut's ranged overload takes a delay, unlike the other curves' ranged overloads. Watch the argument order.
  • Unscaled time is not optional. Every curve uses Time.unscaledDeltaTime, so tweens ignore Time.timeScale — including slow-motion effects.

License

Distributed under the MIT License. See LICENSE for more information.

About

Single-file tween helper for Unity built on UniRx — 6 easing curves, unscaled time, no MonoBehaviour required

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages