Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/kyubuns/AnimeTask

Task Animation Library for Unity
https://github.com/kyubuns/AnimeTask

animation tween unity

Last synced: about 2 months ago
JSON representation

Task Animation Library for Unity

Lists

README

        

# AnimeTask

Task Animation Library for Unity

---

> [!WARNING]
> This is also a very old library.
> If you want to use a new one now, I recommend [PrimeTween](https://github.com/KyryloKuzyk/PrimeTween).

---

***Read this document in other languages: [日本語](https://github.com/kyubuns/AnimeTask/blob/main/README_ja.md)***

![gif_animation_001](https://user-images.githubusercontent.com/961165/85940937-8c48d500-b95a-11ea-81b5-fddd17166a96.gif)

## Sample

-> [Example of use](https://github.com/kyubuns/AnimeTask/wiki/Gallery)

### Basic

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

```csharp
await Easing.Create(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), 2f).ToLocalPosition(cube);
```

### `PlayTo`

Move from the current location to a specified location.

```csharp
await Easing.Create(new Vector3(-5f, 3f, 0f), 2f).ToLocalPosition(cube);
```

### Easing

Use [`InCubic`](https://easings.net/#easeInCubic) of [`Easing`](https://easings.net/) to move to a specified position.

```csharp
await Easing.Create(new Vector3(-5f, 3f, 0f), 2f).ToLocalPosition(cube);
```

### Linear

Move at 1 per second for 2 seconds.

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

### `Gravity`

```csharp
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`

```csharp
[SerializeField] private AnimationCurve sample12 = default;

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

### CalcDuration

Move by calculating moving time from distance.

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

### `TranslateTo.Action`

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

```csharp
Easing.Create(0, 100, 2f).ToAction(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`.

```csharp
Easing.Create(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.

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

### `Cancel`

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

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

### `Convert`

Convert a `float` transition to a circular motion.

```csharp
await Easing.Create(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.

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

### `IProgress`

Supporting [IProgress](https://docs.microsoft.com/ja-jp/dotnet/api/system.iprogress-1)

```csharp
await Easing.Create(2f).ToProgress(Progress.Create(x => Debug.Log(x)));
```

### `AnimationCanceller`

```csharp
var canceller = go.GetAnimationCanceller().Cancel();
Easing.Create(1.0f, 0.5f).ToLocalPositionX(go, canceller.Token);

// in other class/scope
var canceller = go.GetAnimationCanceller().Cancel();
Easing.Create(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`.

```csharp
var skipTokenSource = new SkipTokenSource();
Easing.Create(new Vector3(5f, 0f, 0f), 5f).ToLocalPosition(cubes[0], default, skipTokenSource.Token).Forget();
await UniTask.Delay(TimeSpan.FromSeconds(1));
skipTokenSource.Skip();
```

### `UniRx.Extensions`

```csharp
var score = new ReactiveProperty(0);
score
.SubscribeTask(async (x, cancellationToken) =>
{
scoreCounter.text = $"{x}";
await Easing.Create(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
- Import [UniTask](https://github.com/Cysharp/UniTask)
- Import [UnityPackage](https://github.com/kyubuns/AnimeTask/releases)

## 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](LICENSE))