• Stars
    star
    200
  • Rank 195,325 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rx Tween Animation Library for Unity

AnimeRx - Rx Tween Animation Library for Unity

  • IObservable<T> Anime.Play(T from, T to, IAnimator animator)

Recommend

This is a library from the days when Task was not yet available in Unity.
I recommend using the Task version.
kyubuns/AnimeTask

Buy Me A Coffee

Instructions

  • Import UniTask
  • Import AnimeRx
    • Package Manager https://github.com/kyubuns/AnimeRx.git?path=Assets/Plugins/AnimeRx
    • UnityPackage

Examples

Basic

sample1

(-5,0,0)から(5,0,0)へ、秒速4mで移動。

Anime.Play(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), Motion.Uniform(4f))
    .Subscribe(x => cube.transform.position = x);
    //.SubscribeToPosition(cube);

Method Chain

sample2

(-5,0,0)から(5,0,0)へ移動した後、(0,3,0)に等速で移動。
この方法を用いた場合、1つ目の移動と2つ目の移動で1フレームの間、値の変化が停止します。
スムーズに移動させるには下記のPathの方法を使用してください。

var animator = Motion.Uniform(5f);
Anime.Play(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), animator)
    .Play(new Vector3(0f, 3f, 0f), animator)
    .SubscribeToPosition(cube);

Easing

sample3

EaseOutQuadで2秒かけて移動。

Anime.Play(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), Easing.OutQuad(2f))
    .SubscribeToPosition(cube);

Sleep

sample10

移動した後、1秒まって再度動き出す。

Anime.Play(new Vector3(-5f, 0f, 0f), new Vector3(0f, 0f, 0f), Easing.OutExpo(2f))
    .Sleep(1f)
    .Play(new Vector3(5f, 0f, 0f), Easing.OutExpo(2f))
    .SubscribeToPosition(cube);

Path

sample4

指定したpositionに順番に移動。

var positions = new[]
{
    new Vector3(-5f, 0f, 0f),
    new Vector3(0f, 3f, 0f),
    new Vector3(5f, 0f, 0f),
    new Vector3(0f, -3f, 0f),
    new Vector3(-5f, 0f, 0f),
};

Anime.Play(positions, Easing.InOutSine(6f))
    .SubscribeToPosition(cube);

Combine

sample5

x, y, zの各座標を別々にアニメーションさせて合成。

var x = Anime.Play(-5f, 5f, Easing.InOutSine(3f));

var y = Anime.Play(0f, 3f, Easing.InOutSine(1.5f))
    .Play(0f, Easing.InOutSine(1.5f));

var z = Anime.Stay(0f);

Observable.CombineLatest(x, y, z)
    .SubscribeToPosition(cube);

AnimationCurve

sample11

UnityEngine.AnimationCurveを利用して移動。

Anime.Play(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), Motion.From(curve, 3f))
    .SubscribeToPosition(cube);

Extensions

sample6

cube.transform.positionから(3,3,0)へ移動。

cube.transform.position
    .Play(new Vector3(3f, 3f, 0f), Easing.OutBack(2f))
    .SubscribeToPosition(cube);

Circle

sample8

IObservbleを円運動に変換。

Anime.Play(0f, Mathf.PI * 2f, Easing.OutCubic(3f))
    .Select(x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f))
    .Select(x => x * 3f)
    .SubscribeToPosition(cube);

Range / Lerp

sample17

途中まで一緒についていく。
特定の範囲だけついていく。

var flow = Anime.Play(Easing.InOutExpo(2.5f))
    .Stop(0.5f)
    .Play(1.0f, 0.0f, Easing.InOutExpo(2.5f));

flow
    .Range(0.0f, 0.5f)
    .Lerp(new Vector3(-5f, 0f, 0f), new Vector3(0f, 0f, 0f))
    .SubscribeToPosition(cube2);

flow
    .Lerp(new Vector3(-5f, -1f, 0f), new Vector3(5f, -1f, 0f))
    .SubscribeToPosition(cube);

PlayIn/PlayOut/PlayInOut

sample24

Animationから等速運動に繋げる。

Anime.PlayIn(-5f, 0f, 5f, Easing.InCubic(1.0f))
    .SubscribeToPositionX(cube);

Delay

sample18

Observable.Delay in UniRx

var circle = Anime.Play(0f, Mathf.PI * 2f, Easing.OutCubic(3f))
    .Select(x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f))
    .Select(x => x * 3f);

circle
    .SubscribeToPosition(cube);

circle
    .Delay(0.3f)
    .SubscribeToPosition(cube2);

circle
    .Delay(0.55f)
    .SubscribeToPosition(cube3);

Blend

sample20

2つの移動を足し合わせる。

var circle = Anime
    .Play(Mathf.PI, Mathf.PI * 2f * 3f, Easing.InOutSine(3f))
    .Select(x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0f));

var straight = Anime
    .Play(-3f, 3f, Easing.InOutSine(3f))
    .Select(x => new Vector3(0f, x, 0f));

Observable.CombineLatest(circle, straight)
    .Sum()
    .SubscribeToPosition(cube);

WhenAll

sample9

WhenAllを使ってアニメーションのタイミングを合わせる。

var leftCube1 = Anime
    .Play(new Vector3(-5f, 0f, 0f), new Vector3(-0.5f, 0f, 0f), Easing.Linear(2.5f))
    .DoToPosition(cube);

var rightCube1 = Anime
    .Play(new Vector3(5f, 0f, 0f), new Vector3(0.5f, 0f, 0f), Easing.OutCubic(1f))
    .DoToPosition(cube2);

var leftCube2 = Anime
    .Play(new Vector3(-0.5f, 0f, 0f), new Vector3(-0.5f, 3f, 0f), Easing.OutCubic(1f))
    .DoToPosition(cube);

var rightCube2 = Anime
    .Play(new Vector3(0.5f, 0f, 0f), new Vector3(0.5f, 3f, 0f), Easing.OutCubic(1f))
    .DoToPosition(cube2);

Observable.WhenAll(leftCube1, rightCube1)
    .ContinueWith(Observable.WhenAll(leftCube2, rightCube2))
    .Subscribe();

Loop, Repeat

var disposable = Anime.Play(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), Motion.Uniform(5f))
    .Repeat() // infinite loop
    .SubscribeToPosition(cube1);

Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(_ =>
{
    Debug.Log("Stop!");
    disposable.Dispose();
});

Create your self!

自由に拡張できるインターフェイスが準備されています。

private class ShuffleAnimator : IAnimator
{
    private readonly float duration;

    public ShuffleAnimator(float duration)
    {
        this.duration = duration;
    }

    public float CalcFinishTime(float distance)
    {
        return duration;
    }

    public float CalcPosition(float time, float distance)
    {
        return Random.Range(0f, 1f);
    }
}

private void Shuffle()
{
    var shuffleX = Anime.Play(-1f, 1f, new ShuffleAnimator(3f));
    var shuffleY = Anime.Play(-1f, 1f, new ShuffleAnimator(3f));

    Observable.CombineLatest(shuffleX, shuffleY)
        .Select(x => new Vector3(x[0], x[1]))
        .SubscribeToPosition(cube);
}

Selecting Card

var selectingCard = new ReactiveProperty<Image>(null);
foreach (var card in cards)
{
    var cardRectTransform = card.GetComponent<RectTransform>();
    card.OnPointerClickAsObservable().Subscribe(x => selectingCard.Value = card).AddTo(card);

    var gauge = new ReactiveProperty<float>(0f);
    selectingCard
        .Select(x =>
        {
            var isSelecting = x == card;
            var target = isSelecting ? 1.0f : 0.0f;
            var speed = isSelecting ? 1.0f : 2.0f; // 戻る時は2倍速
            card.color = isSelecting ? Color.yellow : Color.white;
            return Anime.Play(gauge.Value, target, Motion.Uniform(speed));
        })
        .Switch()
        .Subscribe(x => gauge.Value = x);

    gauge
        .Subscribe(x =>
        {
            var p = cardRectTransform.localPosition;
            p.y = OutCirc.Calc(x) * SelectingY;
            cardRectTransform.localPosition = p;
        })
        .AddTo(card);
}

Requirements

  • Unity 2017.1 or later.
    • checked by 2019
  • Support .net3.5 and .net4.6

Special thanks

License

MIT License (see LICENSE)

More Repositories

1

AkyuiUnity

Adobe XD to Akyui to Unity UI
C#
373
star
2

AnimeTask

Task Animation Library for Unity
C#
318
star
3

Baum2

Psd to Unity UI(uGUI)
C#
280
star
4

Auto9Slicer

Auto 9 slice sprite generator on Unity
C#
152
star
5

AppIconChangerUnity

Change the app icon dynamically in Unity (iOS only)
C#
122
star
6

AnKuchen

Control UI Prefab from Script Library
C#
99
star
7

BasicShapeSprite

BasicShapeSprite is a drawing beautiful squares and circles as sprite for unity.
C#
42
star
8

onion_ring

auto 9 sliced sprite (9 patch) generator
Ruby
40
star
9

AbcConsole

Mobile-friendly debug console
C#
38
star
10

prefab_in_prefab

[deprecated]
C#
38
star
11

AssetBookmarks

An editor extension that allows you to register and display commonly use assets
C#
37
star
12

UnityRemoveDevWatermark

C#
37
star
13

Kuchen

Pub/Sub for Unity
C#
32
star
14

ApureEasing

Easing library for Unity Visual Scripting
C#
26
star
15

Akyui

File format for define game UI
17
star
16

UniClipboard

Clipboard for Unity ( support PC/Mac/iOS )
C#
16
star
17

js_ruby_chat

javascript <-> ( msgpack -> websocket -> msgpack ) <-> server
Ruby
15
star
18

ObjectWeightScale

Display a list of assets that a GameObject refers to and check their sizes.
C#
14
star
19

BridgeJsCoreUnity

The fast JavaScript executor for Unity iOS, macOS by using JavaScriptCore
C#
13
star
20

UniClipboard20xx

Clipboard for Unity2017(Support: Editor, Windows, Mac, iOS)
C#
12
star
21

Adobe-Japan1-List

Adobe-Japan1の文字一覧です。
C#
12
star
22

PostProcessingPaletteSwap

Color palette swap for Unity PostProcessingStack
C#
11
star
23

Aprot

Accelerated Prototyping Framework for Unity
10
star
24

DataBinderForNGUI

NGUIのWidgetに勝手に値いれてくれるやつ
C#
8
star
25

misterioso

枠Work
Ruby
6
star
26

illustrator_replace

イラレデータ内のテキストアイテムをtsvに従って置換してくれるスクリプト
JavaScript
6
star
27

HaxeUnityBenchmark

Haxeで書いたコードをUnity上で動かすにあたり、どんな方法が良いか検討するための実験コード
C#
6
star
28

XdParser

Adobe XD file parser for C#
C#
5
star
29

mini_unity_chan_on_unity

ミニゆにてぃちゃん on Unity
C#
4
star
30

rpg_maker_test

GitHub Pagesでそのままゲームを遊べるようにしてみる。
JavaScript
4
star
31

ReflectBall

Unity 1週間ゲームジャム - お題「当てる」
C#
4
star
32

wakutuke

枠を付ける
Shell
4
star
33

haxe-socketio-chat

haxe + socket.io de chat => WakuRPCのsample_chatに移動しました
Haxe
4
star
34

yogurt

PhotoshopPlugin: レイヤー毎に素早くファイルで保存する
JavaScript
3
star
35

WakuTest

C#
3
star
36

QuizGameSample

AdobeXDを用いたUnityゲーム開発フローのサンプルプロジェクト
ShaderLab
3
star
37

StringSerializableEnum

By serializing Enums as Strings instead of Int, you can add or remove values from the Enum without causing issues.
C#
3
star
38

MMOM

MMOもどき
JavaScript
2
star
39

AutomaticOperationTest

C#
2
star
40

AnimeSandbox

AnimeRx & AnimeTask Sandbox
C#
2
star
41

wakusocket

C++
2
star
42

VariableMonitor

C#
2
star
43

warabi

PhotoshopPlugin: レイヤー毎に重ならないようにいい感じに並べてくれる
JavaScript
2
star
44

StreamingAssetsDemo

Qiitaの記事用
C#
2
star
45

codevs

C++
1
star
46

TilemapBugreport

C#
1
star
47

hubot_tokusub

hubotが今日の得サブを教えてくれる
CoffeeScript
1
star
48

DiceCountGame

サイコロ数えるゲームを作ろうとして飽きたやつ
C#
1
star
49

UniRxSandbox

C#
1
star
50

Sample1030918

Unityへのバグ報告用
1
star
51

illustrator_csv_importer

イラレデータにcsvからテキストを流し込むやつ
JavaScript
1
star
52

GIT_SAFE_RESET

git reset --hard HEADで泣いたことがある人向け
1
star
53

BugReportConditionalWeakTable

Unityへのバグ報告用
C#
1
star
54

githooks

core.hooksPath = ~/.githooks
Shell
1
star
55

MsgPackTest

バグ報告用
C#
1
star
56

favme

Flask+jinja2を使用したwebサイト制作時に簡単にXSS対策を出来るようにする便利クラス
Python
1
star
57

prism-theme-gist

GitHub Gist theme for prism.js
HTML
1
star
58

shaved_ice

PhotoshopPlugin: 全部のレイヤーをそれぞれラスタライズする
JavaScript
1
star
59

CheeseCake

C#のコードを綺麗にするやつ
C#
1
star
60

kyubuns

1
star