MeatMotion

Unityのtweenを、タイムラインのようにシーク

MeatMotionは、LitMotion互換のAPIでtweenとシーケンスを組むライブラリです。ハンドルの Time を設定すると、すべての子がその時刻の状態へ前後どちらにも移ります。

はじめる

Unity 6.3+ · v0.1.0 · MIT

MSequence2.50 s
x 0x 5
00.51.01.52.02.5
Local X
AppendIntervalAppend
0.00
Alpha
Join
0.20
Scale
Insert
1.00

上のタイムラインは1つのチェーンで組めます

子はどれも普通のtweenです。Appendは前の子の後、Joinは同時、Insertは指定した時刻に置きます。Insertは次のAppendの位置を動かしません。

呼び出し時刻変化
Append0.00–1.00 sローカルX 0 → 5
Join0.00–0.60 sアルファ 0.2 → 1
Insert0.75–1.50 sスケール 1 → 0.4
AppendInterval1.00–1.50 s待機
Append1.50–2.50 sローカルX 5 → 0

シーケンスを組む

var sequence = MSequence.Create()
    .Append(MMotion.Create(0f, 5f, 1f)
        .BindToLocalPositionX(transform))
    .Join(MMotion.Create(0.2f, 1f, 0.6f)
        .BindToColorA(spriteRenderer))
    .Insert(0.75f, MMotion.Create(1f, 0.4f, 0.75f)
        .BindToLocalScaleX(transform))
    .AppendInterval(0.5f)
    .Append(MMotion.Create(5f, 0f, 1f)
        .WithImmediateBind(false)
        .BindToLocalPositionX(transform))
    .Run();

sequence.Time = 1.25;

64,000個のfloatを1フレーム1.86 msで更新

64,000個のfloatを動かしたときのフレーム時間で、3回起動した中央値です。比較した更新31項目すべてで、MeatMotionの中央値が最短でした。

MeatMotion1.855
MyMotion2.099
LitMotion2.175
Unity Tweens6.813
DOTween6.943
LeanTween7.421
PrimeTween9.947
1フレームあたりのミリ秒、短いほど高速
tweenの生成時間(ms)
float 64,000個座標 50,000個
MeatMotion6.0004.617
LitMotion12.90513.821
MyMotion13.86917.386
PrimeTween25.46314.478
DOTween33.27615.857
LeanTween23.31113.142
Unity Tweens45.52331.131

Unity 6000.6.5f1、Windows x64 Mono Player、Ryzen AI 9 HX 370で計測。全項目と計測条件

LitMotionから移行する

LMotion を MMotion に、名前空間を置き換えます。BindToPosition などの拡張メソッドは同じ名前のまま使えます。MeatMotionに移植したLitMotion 2.0.2のテスト149件が通ります。

移行ガイド

-using LitMotion;
-using LitMotion.Extensions;
+using MeatMotion;
+using MeatMotion.Extensions;

-LMotion.Create(0f, 5f, 0.4f).BindToLocalPositionX(transform);
+MMotion.Create(0f, 5f, 0.4f).BindToLocalPositionX(transform);

他ライブラリとの連携

インストール

Package Managerで + → Install package from git URL を選び、次のURLを貼り付けます。

https://github.com/Garume/MeatMotion.git?path=src/MeatMotion/Assets/MeatMotion