Giter Site home page Giter Site logo

animetask's Introduction

AnimeTask

Task Animation Library for Unity


Recommend

It has been five years since I published this library.
Many TweenAnimation libraries have appeared.
If you are planning to use this library for a new project,
I recommend PrimeTween, which fits my philosophy and performs better.
KyryloKuzyk/PrimeTween


Read this document in other languages: 日本語

Buy Me A Coffee

gif_animation_001

Sample

-> Example of use

Basic

Move from (-5f, 0f, 0f) to (5f, 0f, 0f) over 2 seconds.

await Easing.Create<Linear>(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), 2f).ToLocalPosition(cube);

PlayTo

Move from the current location to a specified location.

await Easing.Create<Linear>(new Vector3(-5f, 3f, 0f), 2f).ToLocalPosition(cube);

Easing

Use InCubic of Easing to move to a specified position.

await Easing.Create<InCubic>(new Vector3(-5f, 3f, 0f), 2f).ToLocalPosition(cube);

Linear

Move at 1 per second for 2 seconds.

await Moving.Linear(1f, 2f).ToLocalPositionX(cube);

Gravity

const float xRange = 5f;
const float yRangeMin = 5f;
const float yRangeMax = 10f;
await Moving.Gravity(
          new Vector2(Random.Range(-xRange, xRange), Random.Range(yRangeMin, yRangeMax)),
          Vector2.down * 9.8f,
          5f
      ).ToLocalPosition(shape)

AnimationCurve

[SerializeField] private AnimationCurve sample12 = default;

public async UniTask Sample12()
{
    await Moving.AnimationCurve(sample12).ToLocalPositionX(cube);
}

CalcDuration

Move by calculating moving time from distance.

await Easing.Create<OutCubic>(new Vector3(5f, 0f, 0f), x => x / 2f)
    .Concat(Easing.Create<OutCubic>(new Vector3(5f, 2f, 0f), x => x / 2f))
    .Concat(Easing.Create<OutCubic>(new Vector3(-5f, 0f, 0f), x => x / 2f))
    .ToLocalPosition(cubes);

TranslateTo.Action

TranslateTo.Action enables you to use the animated values freely.

Easing.Create<Linear>(0, 100, 2f).ToAction<float>(x => Debug.Log(x))

UnscaledTime

You can create your own scheduler, so you can stop time for specific objects.
The default is to use Time.time, and you can also use UnscaledTimeScheduler, which uses Time.unscaledTime.

Easing.Create<Linear>(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), 2f)
    .ToLocalPosition(shape, default, new UnscaledTimeScheduler());

Update Timing

If an update timing is specified in the scheduler, values can be updated at times other than Update.

public class CustomScheduler : IScheduler
{
    public float DeltaTime => Time.deltaTime;
    public PlayerLoopTiming UpdateTiming => PlayerLoopTiming.PreUpdate;
}

Cancel

var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.Token.Register(() => Debug.Log("Cancel"));
cancellationTokenSource.CancelAfter(500);

await Easing.Create<OutCubic>(new Vector3(5f, 0f, 0f), 2f).ToLocalPosition(cubes[0], cancellationTokenSource.Token);

Convert

Convert a float transition to a circular motion.

await Easing.Create<OutCubic>(0.0f, Mathf.PI * 2.0f, 2f)
    .Convert(x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f) * 3.0f)
    .ToLocalPosition(go);

Concat

It moves from 5f to 0f in 2 seconds, stops for 1 second, and moves to -5f in 2 seconds.

await Easing.Create<OutCubic>(5f, 0f, 2f)
    .Delay(1f)
    .Concat(Easing.Create<OutCubic>(0f, -5f, 2f))
    .ToLocalPositionX(cubes[0]);

IProgress

Supporting IProgress

await Easing.Create<Linear>(2f).ToProgress(Progress.Create<float>(x => Debug.Log(x)));

AnimationCanceller

var canceller = go.GetAnimationCanceller().Cancel();
Easing.Create<Linear>(1.0f, 0.5f).ToLocalPositionX(go, canceller.Token);

// in other class/scope
var canceller = go.GetAnimationCanceller().Cancel();
Easing.Create<Linear>(0.0f, 0.5f).ToLocalPositionX(go, canceller.Token);

Skip

  • Cancel (using CancellationToken) will stop at the position at the moment of Cancel.
  • Skip (using SkipToken) will move to the last position at the moment of Skip.
var skipTokenSource = new SkipTokenSource();
Easing.Create<OutCubic>(new Vector3(5f, 0f, 0f), 5f).ToLocalPosition(cubes[0], default, skipTokenSource.Token).Forget();
await UniTask.Delay(TimeSpan.FromSeconds(1));
skipTokenSource.Skip();

UniRx.Extensions

var score = new ReactiveProperty<int>(0);
score
    .SubscribeTask(async (x, cancellationToken) =>
    {
        scoreCounter.text = $"{x}";
        await Easing.Create<OutBounce>(2f, 1f, 0.5f).ToLocalScale(scoreCounter, cancellationToken);
    });

Instructions

  • Import AnimeTask via Package Manager
    • https://github.com/kyubuns/AnimeTask.git?path=Assets/AnimeTask
  • Import AnimeTask via UnityPackage

Way of thinking

You can pass two arguments to Play and PlayTo.
The first is the Animator and the second is the Translator, which have distinct roles.

Animator

Takes the elapsed time and returns the current value.

Translator

Reflect the value.

Requirements

  • Requires Unity2020.3 or later

License

MIT License (see LICENSE)

Buy me a coffee

Are you enjoying save time?
Buy me a coffee if you love my code!
https://www.buymeacoffee.com/kyubuns

"I used it for this game!"

I'd be happy to receive reports like "I used it for this game!"
Please contact me by email, twitter or any other means.
(This library is MIT licensed, so reporting is NOT mandatory.)
MessageForm

https://kyubuns.dev/

animetask's People

Contributors

kyubuns avatar adarapata avatar c3-hoge-fuga-piyo avatar toddlerer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.