├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── other.md
├── .gitignore
├── AnimeTask.sln.DotSettings
├── Assets
├── AnimeTask.meta
├── AnimeTask
│ ├── AnimeTask.asmdef
│ ├── AnimeTask.asmdef.meta
│ ├── LICENSE.md
│ ├── LICENSE.md.meta
│ ├── README.md
│ ├── README.md.meta
│ ├── Scripts.meta
│ ├── Scripts
│ │ ├── Animator.meta
│ │ ├── Animator
│ │ │ ├── ConcatAnimator.cs
│ │ │ ├── ConcatAnimator.cs.meta
│ │ │ ├── ConvertAnimator.cs
│ │ │ ├── ConvertAnimator.cs.meta
│ │ │ ├── DebugLogAnimator.cs
│ │ │ ├── DebugLogAnimator.cs.meta
│ │ │ ├── DelayAnimator.cs
│ │ │ └── DelayAnimator.cs.meta
│ │ ├── Anime.cs
│ │ ├── Anime.cs.meta
│ │ ├── Easing.meta
│ │ ├── Easing
│ │ │ ├── Easing.cs
│ │ │ ├── Easing.cs.meta
│ │ │ ├── EasingAnimator.cs
│ │ │ ├── EasingAnimator.cs.meta
│ │ │ ├── IEasing.cs
│ │ │ └── IEasing.cs.meta
│ │ ├── Extension.cs
│ │ ├── Extension.cs.meta
│ │ ├── Extensions.meta
│ │ ├── Extensions
│ │ │ ├── AnimeTask.Extensions.asmdef
│ │ │ ├── AnimeTask.Extensions.asmdef.meta
│ │ │ ├── UniRxExtensions.cs
│ │ │ └── UniRxExtensions.cs.meta
│ │ ├── IAnimator.cs
│ │ ├── IAnimator.cs.meta
│ │ ├── IScheduler.cs
│ │ ├── IScheduler.cs.meta
│ │ ├── ITranslator.cs
│ │ ├── ITranslator.cs.meta
│ │ ├── Moving.meta
│ │ ├── Moving
│ │ │ ├── AnimationCurveAnimator.cs
│ │ │ ├── AnimationCurveAnimator.cs.meta
│ │ │ ├── GravityAnimator.cs
│ │ │ ├── GravityAnimator.cs.meta
│ │ │ ├── LinearAnimator.cs
│ │ │ └── LinearAnimator.cs.meta
│ │ ├── Scheduler.meta
│ │ ├── Scheduler
│ │ │ ├── TimeScheduler.cs
│ │ │ ├── TimeScheduler.cs.meta
│ │ │ ├── UnscaledTimeScheduler.cs
│ │ │ └── UnscaledTimeScheduler.cs.meta
│ │ ├── Translator.meta
│ │ └── Translator
│ │ │ ├── ActionTranslator.cs
│ │ │ ├── ActionTranslator.cs.meta
│ │ │ ├── BindTranslator.cs
│ │ │ ├── BindTranslator.cs.meta
│ │ │ ├── MaterialTranslator.cs
│ │ │ ├── MaterialTranslator.cs.meta
│ │ │ ├── NoneTranslator.cs
│ │ │ ├── NoneTranslator.cs.meta
│ │ │ ├── ProgressTranslator.cs
│ │ │ ├── ProgressTranslator.cs.meta
│ │ │ ├── ReactivePropertyTranslator.cs
│ │ │ ├── ReactivePropertyTranslator.cs.meta
│ │ │ ├── RectTransformTranslator.cs
│ │ │ ├── RectTransformTranslator.cs.meta
│ │ │ ├── TransformTranslator.cs
│ │ │ ├── TransformTranslator.cs.meta
│ │ │ ├── Translator.cs
│ │ │ ├── Translator.cs.meta
│ │ │ ├── UGuiTranslator.cs
│ │ │ └── UGuiTranslator.cs.meta
│ ├── package.json
│ └── package.json.meta
├── Editor.meta
├── Editor
│ ├── PackageExporter.cs
│ └── PackageExporter.cs.meta
├── Sample.meta
└── Sample
│ ├── Sample.cs
│ ├── Sample.cs.meta
│ ├── Sample.unity
│ ├── Sample.unity.meta
│ ├── SampleMenu.cs
│ ├── SampleMenu.cs.meta
│ ├── SampleUtil.cs
│ └── SampleUtil.cs.meta
├── LICENSE
├── Packages
├── manifest.json
└── packages-lock.json
├── ProjectSettings
├── AudioManager.asset
├── ClusterInputManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshAreas.asset
├── NetworkManager.asset
├── PackageManagerSettings.asset
├── Physics2DSettings.asset
├── PresetManager.asset
├── ProjectSettings.asset
├── ProjectVersion.txt
├── QualitySettings.asset
├── TagManager.asset
├── TimeManager.asset
├── UnityConnectSettings.asset
├── VFXManager.asset
├── VersionControlSettings.asset
└── XRSettings.asset
├── README.md
└── README_ja.md
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [kyubuns]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ['https://www.buymeacoffee.com/kyubuns']
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: kyubuns
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Environment**
24 | Version: x.x.x or hash
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/other.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Other
3 | about: If you want to write something other than Bug Report, please go to Discussion
4 | page.
5 | title: ''
6 | labels: ''
7 | assignees: ''
8 |
9 | ---
10 |
11 | If you want to write something other than Bug Report, please go to Discussion page.
12 | https://github.com/kyubuns/AnimeTask/discussions
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 | [Bb]uild/
5 | [Bb]uilds/
6 | [Ll]ogs/
7 | [Uu]ser[Ss]ettings/
8 | Assets/AssetStoreTools*
9 |
10 | # Visual Studio cache directory
11 | .vs/
12 |
13 | # Autogenerated VS/MD/Consulo solution and project files
14 | ExportedObj/
15 | .consulo/
16 | *.csproj
17 | *.unityproj
18 | *.sln
19 | *.suo
20 | *.tmp
21 | *.user
22 | *.userprefs
23 | *.pidb
24 | *.booproj
25 | *.svd
26 | *.pdb
27 | *.opendb
28 |
29 | # Unity3D generated meta files
30 | *.pidb.meta
31 | *.pdb.meta
32 |
33 | # Unity3D Generated File On Crash Reports
34 | sysinfo.txt
35 |
36 | # Builds
37 | *.apk
38 | *.unitypackage
39 |
40 | Recordings
41 | .idea
42 |
--------------------------------------------------------------------------------
/AnimeTask.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
--------------------------------------------------------------------------------
/Assets/AnimeTask.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 18deef837e78c416ba579b2dc62c0585
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/AnimeTask.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "AnimeTask",
3 | "references": [
4 | "GUID:f51ebe6a0ceec4240a699833d6309b23",
5 | "GUID:560b04d1a97f54a4e82edc0cbbb69285"
6 | ],
7 | "includePlatforms": [],
8 | "excludePlatforms": [],
9 | "allowUnsafeCode": false,
10 | "overrideReferences": false,
11 | "precompiledReferences": [],
12 | "autoReferenced": true,
13 | "defineConstraints": [],
14 | "versionDefines": [
15 | {
16 | "name": "com.neuecc.unirx",
17 | "expression": "",
18 | "define": "ANIMETASK_UNIRX_SUPPORT"
19 | },
20 | {
21 | "name": "com.unity.ugui",
22 | "expression": "",
23 | "define": "ANIMETASK_UGUI_SUPPORT"
24 | }
25 | ],
26 | "noEngineReferences": false
27 | }
--------------------------------------------------------------------------------
/Assets/AnimeTask/AnimeTask.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1a4cffb770ce347a39cea41a326324ec
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 kyubuns
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/LICENSE.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b8c3f7af9f72541fe8136bf93587594a
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/README.md:
--------------------------------------------------------------------------------
1 | # AnimeTask
2 |
3 | ## How to use
4 |
5 | Please see github page.
6 | https://github.com/kyubuns/AnimeTask/blob/main/README.md
7 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9c12ba228894d4d3882ba92976854af8
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e45691338fdcd422da169b7d5221e714
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ff32789e8eeb44e9a807d96aa9524352
3 | timeCreated: 1593318798
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/ConcatAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace AnimeTask
5 | {
6 | public static partial class Animator
7 | {
8 | public static ConcatAnimator Concat(this IAnimator animator1, params IConcatableAnimator[] animator2)
9 | {
10 | return new ConcatAnimator(animator1, animator2);
11 | }
12 |
13 | public static ConcatAnimatorWithStartValue Concat(this IAnimatorWithStartValue animator1, params IConcatableAnimator[] animator2)
14 | {
15 | return new ConcatAnimatorWithStartValue(animator1, animator2);
16 | }
17 | }
18 |
19 | public class ConcatAnimator : IAnimator
20 | {
21 | private readonly List> animators;
22 | private T currentValue;
23 | private IAnimator currentAnimator;
24 | private float usedTime;
25 |
26 | public ConcatAnimator(IAnimator animator1, IEnumerable> animator2)
27 | {
28 | animators = new List>(animator2);
29 |
30 | currentAnimator = animator1;
31 | }
32 |
33 | public (T, float) Update(float time)
34 | {
35 | while (true)
36 | {
37 | var f = time - usedTime;
38 | if (currentAnimator == null) return (currentValue, usedTime);
39 | var (v, used) = currentAnimator.Update(f);
40 |
41 | if (used < f)
42 | {
43 | currentValue = v;
44 | usedTime += used;
45 | GetNext();
46 | continue;
47 | }
48 |
49 | return (v, time);
50 | }
51 | }
52 |
53 | private void GetNext()
54 | {
55 | if (animators.Count == 0)
56 | {
57 | currentAnimator = null;
58 | return;
59 | }
60 | var n = animators[0];
61 | animators.RemoveAt(0);
62 |
63 | if (n is IAnimator animator) currentAnimator = animator;
64 | else if (n is IAnimatorWithStartValue animatorWithStartValue) currentAnimator = animatorWithStartValue.Start(currentValue);
65 | else throw new NotSupportedException($"{n} is not supported");
66 | }
67 | }
68 |
69 | public class ConcatAnimatorWithStartValue : IAnimatorWithStartValue
70 | {
71 | private readonly IAnimatorWithStartValue animator1;
72 | private readonly IConcatableAnimator[] animator2;
73 | private IAnimator playingAnimator;
74 |
75 | public ConcatAnimatorWithStartValue(IAnimatorWithStartValue animator1, IConcatableAnimator[] animator2)
76 | {
77 | this.animator1 = animator1;
78 | this.animator2 = animator2;
79 | }
80 |
81 | public IAnimator Start(T startValue)
82 | {
83 | return new ConcatAnimator(animator1.Start(startValue), animator2);
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/ConcatAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3741fb3235194be3b4804682f8a441ab
3 | timeCreated: 1609898368
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/ConvertAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AnimeTask
4 | {
5 | public static partial class Animator
6 | {
7 | public static ConvertAnimator Convert(this IAnimator animator, Func func)
8 | {
9 | return new ConvertAnimator(animator, func);
10 | }
11 |
12 | public static ConvertAnimatorWithStartValue Convert(this IAnimatorWithStartValue animator, Func func)
13 | {
14 | return new ConvertAnimatorWithStartValue(animator, func);
15 | }
16 | }
17 |
18 | public class ConvertAnimator : IAnimator
19 | {
20 | private readonly IAnimator animator;
21 | private readonly Func func;
22 |
23 | public ConvertAnimator(IAnimator animator, Func func)
24 | {
25 | this.animator = animator;
26 | this.func = func;
27 | }
28 |
29 | public (T2, float) Update(float time)
30 | {
31 | var (item1, item2) = animator.Update(time);
32 | return (func(item1), item2);
33 | }
34 | }
35 |
36 | public class ConvertAnimatorWithStartValue : IAnimatorWithStartValue
37 | {
38 | private readonly IAnimatorWithStartValue animator;
39 | private readonly Func func;
40 |
41 | public ConvertAnimatorWithStartValue(IAnimatorWithStartValue animator, Func func)
42 | {
43 | this.animator = animator;
44 | this.func = func;
45 | }
46 |
47 | public IAnimator Start(T startValue)
48 | {
49 | return new ConvertAnimator(animator.Start(startValue), func);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/ConvertAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6b519fa83ec64ca39726907c92182587
3 | timeCreated: 1593327249
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/DebugLogAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public static partial class Animator
7 | {
8 | public static DebugLogAnimator DebugLog(this IAnimator animator)
9 | {
10 | return new DebugLogAnimator(animator);
11 | }
12 |
13 | public static DebugLogAnimatorWithStartValue DebugLog(this IAnimatorWithStartValue animator)
14 | {
15 | return new DebugLogAnimatorWithStartValue(animator);
16 | }
17 | }
18 |
19 | public class DebugLogAnimator : IAnimator
20 | {
21 | private readonly IAnimator animator;
22 |
23 | public DebugLogAnimator(IAnimator animator)
24 | {
25 | this.animator = animator;
26 | }
27 |
28 | public (T, float) Update(float time)
29 | {
30 | var v = animator.Update(time);
31 | Debug.Log($"{time:0.00}: {v.Item1}");
32 | return v;
33 | }
34 | }
35 |
36 | public class DebugLogAnimatorWithStartValue : IAnimatorWithStartValue
37 | {
38 | private readonly IAnimatorWithStartValue animator;
39 |
40 | public DebugLogAnimatorWithStartValue(IAnimatorWithStartValue animator)
41 | {
42 | this.animator = animator;
43 | }
44 |
45 | public IAnimator Start(T startValue)
46 | {
47 | return new DebugLogAnimator(animator.Start(startValue));
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/DebugLogAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a723e44d42234834ae96b93feec58a18
3 | timeCreated: 1609901387
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/DelayAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public static partial class Animator
7 | {
8 | public static DelayAnimator Delay(T startValue, float duration) => new DelayAnimator(startValue, duration);
9 | public static DelayAnimatorWithStartValue Delay(float duration) => new DelayAnimatorWithStartValue(duration);
10 |
11 | public static ConcatAnimator Delay(this IAnimator animator, float duration) => Concat(animator, Delay(duration));
12 | public static ConcatAnimatorWithStartValue Delay(this IAnimatorWithStartValue animator, float duration) => Concat(animator, Delay(duration));
13 |
14 | public static RelativeDelayAnimatorWithStartValue RelativeDelay(this IAnimator baseAnimator, float duration) => new RelativeDelayAnimatorWithStartValue(baseAnimator, duration);
15 | public static RelativeDelayAnimator RelativeDelay(this IAnimator baseAnimator, T1 startValue, float duration) => new RelativeDelayAnimator(startValue, baseAnimator, duration);
16 | public static RelativeDelayAnimatorWithStartValue RelativeDelay(this IAnimatorWithStartValue baseAnimator, float duration) => new RelativeDelayAnimatorWithStartValue(baseAnimator, duration);
17 | }
18 |
19 | public class DelayAnimator : IAnimator
20 | {
21 | private readonly T start;
22 | private readonly float duration;
23 |
24 | public DelayAnimator(T start, float duration)
25 | {
26 | this.start = start;
27 | this.duration = duration;
28 | }
29 |
30 | public (T, float) Update(float time)
31 | {
32 | return (start, Mathf.Min(time, duration));
33 | }
34 | }
35 |
36 | public class DelayAnimatorWithStartValue : IAnimatorWithStartValue
37 | {
38 | private readonly float duration;
39 |
40 | public DelayAnimatorWithStartValue(float duration)
41 | {
42 | this.duration = duration;
43 | }
44 |
45 | public IAnimator Start(T startValue)
46 | {
47 | return new DelayAnimator(startValue, duration);
48 | }
49 | }
50 |
51 | public class RelativeDelayAnimator : IAnimator
52 | {
53 | private readonly T1 start;
54 | private readonly IAnimator baseAnimator;
55 | private readonly float duration;
56 |
57 | public RelativeDelayAnimator(T1 start, IAnimator baseAnimator, float duration)
58 | {
59 | this.start = start;
60 | this.baseAnimator = baseAnimator;
61 | this.duration = duration;
62 | }
63 |
64 | public (T1, float) Update(float time)
65 | {
66 | var f = time - duration;
67 | var (_, used) = baseAnimator.Update(f);
68 | if (used < f)
69 | {
70 | return (start, time - (f - used));
71 | }
72 |
73 | return (start, time);
74 | }
75 | }
76 |
77 | public class RelativeDelayAnimatorWithStartValue : IAnimatorWithStartValue
78 | {
79 | private readonly IAnimator baseAnimator;
80 | private readonly float duration;
81 |
82 | public RelativeDelayAnimatorWithStartValue(IAnimator baseAnimator, float duration)
83 | {
84 | this.baseAnimator = baseAnimator;
85 | this.duration = duration;
86 | }
87 |
88 | public RelativeDelayAnimatorWithStartValue(IAnimatorWithStartValue baseAnimator, float duration)
89 | {
90 | this.baseAnimator = baseAnimator.Start(default);
91 | this.duration = duration;
92 | }
93 |
94 | public IAnimator Start(T1 startValue)
95 | {
96 | return new RelativeDelayAnimator(startValue, baseAnimator, duration);
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Animator/DelayAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4acb9a0cbf2d45758af69dd21e00fb53
3 | timeCreated: 1593318808
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Anime.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using Cysharp.Threading.Tasks;
4 | using JetBrains.Annotations;
5 | using UnityEngine;
6 |
7 | namespace AnimeTask
8 | {
9 | public static class Anime
10 | {
11 | public static IScheduler DefaultScheduler { get; set; } = new TimeScheduler();
12 |
13 | [MustUseReturnValue]
14 | public static UniTask Play(IAnimator animator, ITranslator translator, IScheduler scheduler = default, CancellationToken cancellationToken = default, SkipToken skipToken = default)
15 | {
16 | return PlayInternal(animator, translator, scheduler, cancellationToken, skipToken);
17 | }
18 |
19 | [MustUseReturnValue]
20 | public static UniTask PlayTo(IAnimatorWithStartValue animatorWithStartValue, IValueTranslator translator, IScheduler scheduler = default, CancellationToken cancellationToken = default, SkipToken skipToken = default)
21 | {
22 | var animator = animatorWithStartValue.Start(translator.Current);
23 | return PlayInternal(animator, translator, scheduler, cancellationToken, skipToken);
24 | }
25 |
26 | private static async UniTask PlayInternal(IAnimator animator, ITranslator translator, IScheduler scheduler, CancellationToken cancellationToken, SkipToken skipToken)
27 | {
28 | if (scheduler == default) scheduler = DefaultScheduler;
29 |
30 | var time = 0f;
31 | var playState = Application.isPlaying;
32 | while (!cancellationToken.IsCancellationRequested && !skipToken.IsSkipRequested && translator.Alive && playState == Application.isPlaying)
33 | {
34 | var (t, used) = animator.Update(time);
35 | translator.Update(t);
36 | if (used < time) break;
37 | await UniTask.NextFrame(scheduler.UpdateTiming, cancellationToken);
38 | time += scheduler.DeltaTime;
39 | }
40 |
41 | if (!translator.Alive) throw new OperationCanceledException("!translator.Alive");
42 | cancellationToken.ThrowIfCancellationRequested();
43 |
44 | if (skipToken.IsSkipRequested)
45 | {
46 | var (t, _) = animator.Update(float.MaxValue);
47 | translator.Update(t);
48 | }
49 | }
50 |
51 | [MustUseReturnValue]
52 | public static UniTask Delay(float duration, IScheduler scheduler = default, CancellationToken cancellationToken = default, SkipToken skipToken = default)
53 | {
54 | return DelayInternal(duration, scheduler, cancellationToken, skipToken);
55 | }
56 |
57 | private static async UniTask DelayInternal(float duration, IScheduler scheduler, CancellationToken cancellationToken, SkipToken skipToken)
58 | {
59 | if (scheduler == default) scheduler = DefaultScheduler;
60 |
61 | var time = 0f;
62 | var playState = Application.isPlaying;
63 | while (!cancellationToken.IsCancellationRequested && !skipToken.IsSkipRequested && playState == Application.isPlaying)
64 | {
65 | if (duration < time) break;
66 | await UniTask.NextFrame(scheduler.UpdateTiming, cancellationToken);
67 | time += scheduler.DeltaTime;
68 | }
69 | cancellationToken.ThrowIfCancellationRequested();
70 | }
71 | }
72 |
73 | public struct SkipToken
74 | {
75 | private readonly SkipTokenSource source;
76 | private readonly bool skipped;
77 |
78 | public SkipToken(bool skipped)
79 | {
80 | source = null;
81 | this.skipped = skipped;
82 | }
83 |
84 | public SkipToken(SkipTokenSource source)
85 | {
86 | this.source = source;
87 | skipped = false;
88 | }
89 |
90 | public bool IsSkipRequested => source?.IsSkipRequested ?? skipped;
91 |
92 | public static SkipToken None => new SkipToken(false);
93 | }
94 |
95 | public class SkipTokenSource : IDisposable
96 | {
97 | public SkipTokenSource()
98 | {
99 | IsSkipRequested = false;
100 | Token = new SkipToken(this);
101 | }
102 |
103 | public void Skip()
104 | {
105 | IsSkipRequested = true;
106 | }
107 |
108 | public bool IsSkipRequested { get; set; }
109 |
110 | public SkipToken Token { get; }
111 |
112 | public void Dispose()
113 | {
114 | Skip();
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Anime.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f7653bda3087f43e38ce285b6f45a2e1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b0969bb4a46e460a8aae3f3c7d2be768
3 | timeCreated: 1538308425
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing/Easing.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace AnimeTask
4 | {
5 | public class Linear : IEasing
6 | {
7 | public float Function(float v)
8 | {
9 | return Calc(v);
10 | }
11 |
12 | public static float Calc(float v)
13 | {
14 | return v;
15 | }
16 | }
17 |
18 | public class InBack : IEasing
19 | {
20 | public float Function(float v)
21 | {
22 | return Calc(v);
23 | }
24 |
25 | public static float Calc(float v)
26 | {
27 | return 2.70158f * v * v * v - 1.70158f * v * v;
28 | }
29 | }
30 |
31 | public class OutBack : IEasing
32 | {
33 | public float Function(float v)
34 | {
35 | return Calc(v);
36 | }
37 |
38 | public static float Calc(float v)
39 | {
40 | return 1f + 2.70158f * Mathf.Pow(v - 1f, 3f) + 1.70158f * Mathf.Pow(v - 1f, 2f);
41 | }
42 | }
43 |
44 | public class InOutBack : IEasing
45 | {
46 | public float Function(float v)
47 | {
48 | return Calc(v);
49 | }
50 |
51 | public static float Calc(float v)
52 | {
53 | const float c1 = 1.70158f;
54 | const float c2 = c1 * 1.525f;
55 |
56 | if (v < 0.5f)
57 | {
58 | return (Mathf.Pow(2f * v, 2f) * ((c2 + 1f) * 2f * v - c2)) / 2f;
59 | }
60 | else
61 | {
62 | return (Mathf.Pow(2f * v - 2f, 2f) * ((c2 + 1f) * (v * 2f - 2f) + c2) + 2f) / 2f;
63 | }
64 | }
65 | }
66 |
67 | public class InBounce : IEasing
68 | {
69 | public float Function(float v)
70 | {
71 | return Calc(v);
72 | }
73 |
74 | public static float Calc(float v)
75 | {
76 | return Bounce(v);
77 | }
78 |
79 | public static float Bounce(float v)
80 | {
81 | return 1 - OutBounce.Bounce(1 - v);
82 | }
83 | }
84 |
85 | public class OutBounce : IEasing
86 | {
87 | public float Function(float v)
88 | {
89 | return Calc(v);
90 | }
91 |
92 | public static float Calc(float v)
93 | {
94 | return Bounce(v);
95 | }
96 |
97 | public static float Bounce(float v)
98 | {
99 | if (v < 1 / 2.75f)
100 | {
101 | return 7.5625f * v * v;
102 | }
103 | else if (v < 2 / 2.75f)
104 | {
105 | var f = v - 0.54545f;
106 | return 7.5625f * f * f + 0.75f;
107 | }
108 | else if (v < 2.5 / 2.75f)
109 | {
110 | var f = v - 0.81818f;
111 | return 7.5625f * f * f + 0.9375f;
112 | }
113 | else
114 | {
115 | var f = v - 0.95454f;
116 | return 7.5625f * f * f + 0.984375f;
117 | }
118 | }
119 | }
120 |
121 | public class InOutBounce : IEasing
122 | {
123 | public float Function(float v)
124 | {
125 | return Calc(v);
126 | }
127 |
128 | public static float Calc(float v)
129 | {
130 | if (v < 0.5f)
131 | {
132 | return 0.5f * InBounce.Bounce(v * 2f);
133 | }
134 | else
135 | {
136 | return 0.5f * OutBounce.Bounce(v * 2f - 1f) + 0.5f;
137 | }
138 | }
139 | }
140 |
141 | public class InCirc : IEasing
142 | {
143 | public float Function(float v)
144 | {
145 | return Calc(v);
146 | }
147 |
148 | public static float Calc(float v)
149 | {
150 | return 1f - Mathf.Sqrt(1f - (v * v));
151 | }
152 | }
153 |
154 | public class OutCirc : IEasing
155 | {
156 | public float Function(float v)
157 | {
158 | return Calc(v);
159 | }
160 |
161 | public static float Calc(float v)
162 | {
163 | return Mathf.Sqrt((2f - v) * v);
164 | }
165 | }
166 |
167 | public class InOutCirc : IEasing
168 | {
169 | public float Function(float v)
170 | {
171 | return Calc(v);
172 | }
173 |
174 | public static float Calc(float v)
175 | {
176 | if (v < 0.5f)
177 | {
178 | return 0.5f * (1 - Mathf.Sqrt(1f - 4f * (v * v)));
179 | }
180 | else
181 | {
182 | return 0.5f * (Mathf.Sqrt(-((2f * v) - 3f) * ((2f * v) - 1f)) + 1f);
183 | }
184 | }
185 | }
186 |
187 | public class InCubic : IEasing
188 | {
189 | public float Function(float v)
190 | {
191 | return Calc(v);
192 | }
193 |
194 | public static float Calc(float v)
195 | {
196 | return v * v * v;
197 | }
198 | }
199 |
200 | public class OutCubic : IEasing
201 | {
202 | public float Function(float v)
203 | {
204 | return Calc(v);
205 | }
206 |
207 | public static float Calc(float v)
208 | {
209 | var f = (v - 1f);
210 | return f * f * f + 1f;
211 | }
212 | }
213 |
214 | public class InOutCubic : IEasing
215 | {
216 | public float Function(float v)
217 | {
218 | return Calc(v);
219 | }
220 |
221 | public static float Calc(float v)
222 | {
223 | if (v < 0.5f)
224 | {
225 | return 4f * v * v * v;
226 | }
227 | else
228 | {
229 | var f = ((2f * v) - 2f);
230 | return 0.5f * f * f * f + 1f;
231 | }
232 | }
233 | }
234 |
235 | public class InElastic : IEasing
236 | {
237 | public float Function(float v)
238 | {
239 | return Calc(v);
240 | }
241 |
242 | public static float Calc(float v)
243 | {
244 | if (Mathf.Approximately(0.0f, v) || Mathf.Approximately(1.0f, v)) return v;
245 | return Mathf.Sin((v * 10f - 10.75f) * (2f * Mathf.PI / 3f)) * -Mathf.Pow(2f, 10f * (v - 1f));
246 | }
247 | }
248 |
249 | public class OutElastic : IEasing
250 | {
251 | public float Function(float v)
252 | {
253 | return Calc(v);
254 | }
255 |
256 | public static float Calc(float v)
257 | {
258 | if (Mathf.Approximately(0.0f, v) || Mathf.Approximately(1.0f, v)) return v;
259 | return Mathf.Sin((v * 10f - 0.75f) * (2f * Mathf.PI / 3f)) * Mathf.Pow(2f, -10f * v) + 1f;
260 | }
261 | }
262 |
263 | public class InOutElastic : IEasing
264 | {
265 | public float Function(float v)
266 | {
267 | return Calc(v);
268 | }
269 |
270 | public static float Calc(float v)
271 | {
272 | if (Mathf.Approximately(0.0f, v) || Mathf.Approximately(1.0f, v)) return v;
273 |
274 | if (v < 0.5f)
275 | {
276 | return -Mathf.Pow(2f, 20f * v - 10f) * Mathf.Sin((20f * v - 11.125f) * (2f * Mathf.PI) / 4.5f) / 2f;
277 | }
278 | else
279 | {
280 | return Mathf.Pow(2f, -20f * v + 10f) * Mathf.Sin((20f * v - 11.125f) * (2f * Mathf.PI) / 4.5f) / 2f + 1f;
281 | }
282 | }
283 | }
284 |
285 | public class InExpo : IEasing
286 | {
287 | public float Function(float v)
288 | {
289 | return Calc(v);
290 | }
291 |
292 | public static float Calc(float v)
293 | {
294 | return Mathf.Approximately(0.0f, v) ? v : Mathf.Pow(2f, 10f * (v - 1f));
295 | }
296 | }
297 |
298 | public class OutExpo : IEasing
299 | {
300 | public float Function(float v)
301 | {
302 | return Calc(v);
303 | }
304 |
305 | public static float Calc(float v)
306 | {
307 | return Mathf.Approximately(1.0f, v) ? v : 1f - Mathf.Pow(2f, -10f * v);
308 | }
309 | }
310 |
311 | public class InOutExpo : IEasing
312 | {
313 | public float Function(float v)
314 | {
315 | return Calc(v);
316 | }
317 |
318 | public static float Calc(float v)
319 | {
320 | if (Mathf.Approximately(0.0f, v) || Mathf.Approximately(1.0f, v)) return v;
321 |
322 | if (v < 0.5f)
323 | {
324 | return 0.5f * Mathf.Pow(2f, (20f * v) - 10f);
325 | }
326 | else
327 | {
328 | return -0.5f * Mathf.Pow(2f, (-20f * v) + 10f) + 1f;
329 | }
330 | }
331 | }
332 |
333 | public class InQuad : IEasing
334 | {
335 | public float Function(float v)
336 | {
337 | return Calc(v);
338 | }
339 |
340 | public static float Calc(float v)
341 | {
342 | return v * v;
343 | }
344 | }
345 |
346 | public class OutQuad : IEasing
347 | {
348 | public float Function(float v)
349 | {
350 | return Calc(v);
351 | }
352 |
353 | public static float Calc(float v)
354 | {
355 | return -(v * (v - 2f));
356 | }
357 | }
358 |
359 | public class InOutQuad : IEasing
360 | {
361 | public float Function(float v)
362 | {
363 | return Calc(v);
364 | }
365 |
366 | public static float Calc(float v)
367 | {
368 | if (v < 0.5f)
369 | {
370 | return 2f * v * v;
371 | }
372 | else
373 | {
374 | return -2f * v * v + 4f * v - 1f;
375 | }
376 | }
377 | }
378 |
379 | public class InQuart : IEasing
380 | {
381 | public float Function(float v)
382 | {
383 | return Calc(v);
384 | }
385 |
386 | public static float Calc(float v)
387 | {
388 | return v * v * v * v;
389 | }
390 | }
391 |
392 | public class OutQuart : IEasing
393 | {
394 | public float Function(float v)
395 | {
396 | return Calc(v);
397 | }
398 |
399 | public static float Calc(float v)
400 | {
401 | var f = (v - 1f);
402 | return f * f * f * (1f - v) + 1f;
403 | }
404 | }
405 |
406 | public class InOutQuart : IEasing
407 | {
408 | public float Function(float v)
409 | {
410 | return Calc(v);
411 | }
412 |
413 | public static float Calc(float v)
414 | {
415 | if (v < 0.5f)
416 | {
417 | return 8f * v * v * v * v;
418 | }
419 | else
420 | {
421 | var f = (v - 1f);
422 | return 1f - 8f * f * f * f * f;
423 | }
424 | }
425 | }
426 |
427 | public class InQuint : IEasing
428 | {
429 | public float Function(float v)
430 | {
431 | return Calc(v);
432 | }
433 |
434 | public static float Calc(float v)
435 | {
436 | return v * v * v * v * v;
437 | }
438 | }
439 |
440 | public class OutQuint : IEasing
441 | {
442 | public float Function(float v)
443 | {
444 | return Calc(v);
445 | }
446 |
447 | public static float Calc(float v)
448 | {
449 | var f = (v - 1f);
450 | return f * f * f * f * f + 1f;
451 | }
452 | }
453 |
454 | public class InOutQuint : IEasing
455 | {
456 | public float Function(float v)
457 | {
458 | return Calc(v);
459 | }
460 |
461 | public static float Calc(float v)
462 | {
463 | if (v < 0.5f)
464 | {
465 | return 16f * v * v * v * v * v;
466 | }
467 | else
468 | {
469 | var f = ((2f * v) - 2f);
470 | return 0.5f * f * f * f * f * f + 1f;
471 | }
472 | }
473 | }
474 |
475 | public class InSine : IEasing
476 | {
477 | public float Function(float v)
478 | {
479 | return Calc(v);
480 | }
481 |
482 | public static float Calc(float v)
483 | {
484 | return Mathf.Sin((v - 1f) * (Mathf.PI / 2f)) + 1f;
485 | }
486 | }
487 |
488 | public class OutSine : IEasing
489 | {
490 | public float Function(float v)
491 | {
492 | return Calc(v);
493 | }
494 |
495 | public static float Calc(float v)
496 | {
497 | return Mathf.Sin(v * (Mathf.PI / 2f));
498 | }
499 | }
500 |
501 | public class InOutSine : IEasing
502 | {
503 | public float Function(float v)
504 | {
505 | return Calc(v);
506 | }
507 |
508 | public static float Calc(float v)
509 | {
510 | return 0.5f * (1f - Mathf.Cos(v * Mathf.PI));
511 | }
512 | }
513 | }
514 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing/Easing.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8b7c6977777948ee957f6e1e5995de21
3 | timeCreated: 1538308455
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing/EasingAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public static class Easing
7 | {
8 | public static Vector1EasingAnimator Create(float duration) where T : IEasing, new()
9 | {
10 | return new Vector1EasingAnimator(new T(), 0f, 1f, duration);
11 | }
12 |
13 | public static Vector1EasingAnimator Create(float start, float end, float duration) where T : IEasing, new()
14 | {
15 | return new Vector1EasingAnimator(new T(), start, end, duration);
16 | }
17 |
18 | public static Vector1EasingAnimator Create(float start, float end, Func duration) where T : IEasing, new()
19 | {
20 | return new Vector1EasingAnimator(new T(), start, end, duration);
21 | }
22 |
23 | public static Vector1EasingAnimatorTo Create(float to, float duration) where T : IEasing, new()
24 | {
25 | return new Vector1EasingAnimatorTo(new T(), to, duration);
26 | }
27 |
28 | public static Vector1EasingAnimatorToCalcDuration Create(float to, Func duration) where T : IEasing, new()
29 | {
30 | return new Vector1EasingAnimatorToCalcDuration(new T(), to, duration);
31 | }
32 |
33 | public static Vector2EasingAnimator Create(Vector2 start, Vector2 end, float duration) where T : IEasing, new()
34 | {
35 | return new Vector2EasingAnimator(new T(), start, end, duration);
36 | }
37 |
38 | public static Vector2EasingAnimator Create(Vector2 start, Vector2 end, Func duration) where T : IEasing, new()
39 | {
40 | return new Vector2EasingAnimator(new T(), start, end, duration);
41 | }
42 |
43 | public static Vector2EasingAnimatorTo Create(Vector2 to, float duration) where T : IEasing, new()
44 | {
45 | return new Vector2EasingAnimatorTo(new T(), to, duration);
46 | }
47 |
48 | public static Vector2EasingAnimatorToCalcDuration Create(Vector2 to, Func duration) where T : IEasing, new()
49 | {
50 | return new Vector2EasingAnimatorToCalcDuration(new T(), to, duration);
51 | }
52 |
53 | public static Vector3EasingAnimator Create(Vector3 start, Vector3 end, float duration) where T : IEasing, new()
54 | {
55 | return new Vector3EasingAnimator(new T(), start, end, duration);
56 | }
57 |
58 | public static Vector3EasingAnimator Create(Vector3 start, Vector3 end, Func duration) where T : IEasing, new()
59 | {
60 | return new Vector3EasingAnimator(new T(), start, end, duration);
61 | }
62 |
63 | public static Vector3EasingAnimatorTo Create(Vector3 to, float duration) where T : IEasing, new()
64 | {
65 | return new Vector3EasingAnimatorTo(new T(), to, duration);
66 | }
67 |
68 | public static Vector3EasingAnimatorToCalcDuration Create(Vector3 to, Func duration) where T : IEasing, new()
69 | {
70 | return new Vector3EasingAnimatorToCalcDuration(new T(), to, duration);
71 | }
72 |
73 | public static Vector4EasingAnimator Create(Vector4 start, Vector4 end, float duration) where T : IEasing, new()
74 | {
75 | return new Vector4EasingAnimator(new T(), start, end, duration);
76 | }
77 |
78 | public static Vector4EasingAnimator Create(Vector4 start, Vector4 end, Func duration) where T : IEasing, new()
79 | {
80 | return new Vector4EasingAnimator(new T(), start, end, duration);
81 | }
82 |
83 | public static Vector4EasingAnimatorTo Create(Vector4 to, float duration) where T : IEasing, new()
84 | {
85 | return new Vector4EasingAnimatorTo(new T(), to, duration);
86 | }
87 |
88 | public static Vector4EasingAnimatorToCalcDuration Create(Vector4 to, Func duration) where T : IEasing, new()
89 | {
90 | return new Vector4EasingAnimatorToCalcDuration(new T(), to, duration);
91 | }
92 |
93 | public static QuaternionEasingAnimator Create(Quaternion start, Quaternion end, float duration) where T : IEasing, new()
94 | {
95 | return new QuaternionEasingAnimator(new T(), start, end, duration);
96 | }
97 |
98 | public static QuaternionEasingAnimator Create(Quaternion start, Quaternion end, Func duration) where T : IEasing, new()
99 | {
100 | return new QuaternionEasingAnimator(new T(), start, end, duration);
101 | }
102 |
103 | public static QuaternionEasingAnimatorTo Create(Quaternion to, float duration) where T : IEasing, new()
104 | {
105 | return new QuaternionEasingAnimatorTo(new T(), to, duration);
106 | }
107 |
108 | public static QuaternionEasingAnimatorToCalcDuration Create(Quaternion to, Func duration) where T : IEasing, new()
109 | {
110 | return new QuaternionEasingAnimatorToCalcDuration(new T(), to, duration);
111 | }
112 |
113 | public static ColorEasingAnimator Create(Color start, Color end, float duration) where T : IEasing, new()
114 | {
115 | return new ColorEasingAnimator(new T(), start, end, duration);
116 | }
117 |
118 | public static ColorEasingAnimator Create(Color start, Color end, Func duration) where T : IEasing, new()
119 | {
120 | return new ColorEasingAnimator(new T(), start, end, duration);
121 | }
122 |
123 | public static ColorEasingAnimatorTo Create(Color to, float duration) where T : IEasing, new()
124 | {
125 | return new ColorEasingAnimatorTo(new T(), to, duration);
126 | }
127 |
128 | public static ColorEasingAnimatorToCalcDuration Create(Color to, Func duration) where T : IEasing, new()
129 | {
130 | return new ColorEasingAnimatorToCalcDuration(new T(), to, duration);
131 | }
132 | }
133 |
134 | public class Vector1EasingAnimator : IAnimator
135 | {
136 | private readonly IEasing easing;
137 | private readonly float start;
138 | private readonly float end;
139 | private readonly float duration;
140 |
141 | public Vector1EasingAnimator(IEasing easing, float start, float end, float duration)
142 | {
143 | this.easing = easing;
144 | this.start = start;
145 | this.end = end;
146 | this.duration = duration;
147 | }
148 |
149 | public Vector1EasingAnimator(IEasing easing, float start, float end, Func duration)
150 | {
151 | this.easing = easing;
152 | this.start = start;
153 | this.end = end;
154 | this.duration = duration.Invoke(Mathf.Abs(start - end));
155 | }
156 |
157 | public (float, float) Update(float time)
158 | {
159 | var value = Mathf.LerpUnclamped(start, end, easing.Function(Mathf.Min(time / duration, 1.0f)));
160 | return (value, Mathf.Min(time, duration));
161 | }
162 | }
163 |
164 | public class Vector1EasingAnimatorTo : IAnimatorWithStartValue
165 | {
166 | private readonly IEasing easing;
167 | private readonly float to;
168 | private readonly float duration;
169 |
170 | public Vector1EasingAnimatorTo(IEasing easing, float to, float duration)
171 | {
172 | this.easing = easing;
173 | this.to = to;
174 | this.duration = duration;
175 | }
176 |
177 | public IAnimator Start(float startValue)
178 | {
179 | return new Vector1EasingAnimator(easing, startValue, to, duration);
180 | }
181 | }
182 |
183 | public class Vector1EasingAnimatorToCalcDuration : IAnimatorWithStartValue
184 | {
185 | private readonly IEasing easing;
186 | private readonly float to;
187 | private readonly Func duration;
188 |
189 | public Vector1EasingAnimatorToCalcDuration(IEasing easing, float to, Func duration)
190 | {
191 | this.easing = easing;
192 | this.to = to;
193 | this.duration = duration;
194 | }
195 |
196 | public IAnimator Start(float startValue)
197 | {
198 | return new Vector1EasingAnimator(easing, startValue, to, duration);
199 | }
200 | }
201 |
202 | public class Vector2EasingAnimator : IAnimator
203 | {
204 | private readonly IEasing easing;
205 | private readonly Vector2 start;
206 | private readonly Vector2 end;
207 | private readonly float duration;
208 |
209 | public Vector2EasingAnimator(IEasing easing, Vector2 start, Vector2 end, float duration)
210 | {
211 | this.easing = easing;
212 | this.start = start;
213 | this.end = end;
214 | this.duration = duration;
215 | }
216 |
217 | public Vector2EasingAnimator(IEasing easing, Vector2 start, Vector2 end, Func duration)
218 | {
219 | this.easing = easing;
220 | this.start = start;
221 | this.end = end;
222 | this.duration = duration.Invoke(Vector2.Distance(start, end));
223 | }
224 |
225 | public (Vector2, float) Update(float time)
226 | {
227 | var value = Vector2.LerpUnclamped(start, end, easing.Function(Mathf.Min(time / duration, 1.0f)));
228 | return (value, Mathf.Min(time, duration));
229 | }
230 | }
231 |
232 | public class Vector2EasingAnimatorTo : IAnimatorWithStartValue
233 | {
234 | private readonly IEasing easing;
235 | private readonly Vector2 to;
236 | private readonly float duration;
237 |
238 | public Vector2EasingAnimatorTo(IEasing easing, Vector2 to, float duration)
239 | {
240 | this.easing = easing;
241 | this.to = to;
242 | this.duration = duration;
243 | }
244 |
245 | public IAnimator Start(Vector2 startValue)
246 | {
247 | return new Vector2EasingAnimator(easing, startValue, to, duration);
248 | }
249 | }
250 |
251 | public class Vector2EasingAnimatorToCalcDuration : IAnimatorWithStartValue
252 | {
253 | private readonly IEasing easing;
254 | private readonly Vector2 to;
255 | private readonly Func duration;
256 |
257 | public Vector2EasingAnimatorToCalcDuration(IEasing easing, Vector2 to, Func duration)
258 | {
259 | this.easing = easing;
260 | this.to = to;
261 | this.duration = duration;
262 | }
263 |
264 | public IAnimator Start(Vector2 startValue)
265 | {
266 | return new Vector2EasingAnimator(easing, startValue, to, duration);
267 | }
268 | }
269 |
270 | public class Vector3EasingAnimator : IAnimator
271 | {
272 | private readonly IEasing easing;
273 | private readonly Vector3 start;
274 | private readonly Vector3 end;
275 | private readonly float duration;
276 |
277 | public Vector3EasingAnimator(IEasing easing, Vector3 start, Vector3 end, float duration)
278 | {
279 | this.easing = easing;
280 | this.start = start;
281 | this.end = end;
282 | this.duration = duration;
283 | }
284 |
285 | public Vector3EasingAnimator(IEasing easing, Vector3 start, Vector3 end, Func duration)
286 | {
287 | this.easing = easing;
288 | this.start = start;
289 | this.end = end;
290 | this.duration = duration.Invoke(Vector3.Distance(start, end));
291 | }
292 |
293 | public (Vector3, float) Update(float time)
294 | {
295 | var value = Vector3.LerpUnclamped(start, end, easing.Function(Mathf.Min(time / duration, 1.0f)));
296 | return (value, Mathf.Min(time, duration));
297 | }
298 | }
299 |
300 | public class Vector3EasingAnimatorTo : IAnimatorWithStartValue
301 | {
302 | private readonly IEasing easing;
303 | private readonly Vector3 to;
304 | private readonly float duration;
305 |
306 | public Vector3EasingAnimatorTo(IEasing easing, Vector3 to, float duration)
307 | {
308 | this.easing = easing;
309 | this.to = to;
310 | this.duration = duration;
311 | }
312 |
313 | public IAnimator Start(Vector3 startValue)
314 | {
315 | return new Vector3EasingAnimator(easing, startValue, to, duration);
316 | }
317 | }
318 |
319 | public class Vector3EasingAnimatorToCalcDuration : IAnimatorWithStartValue
320 | {
321 | private readonly IEasing easing;
322 | private readonly Vector3 to;
323 | private readonly Func duration;
324 |
325 | public Vector3EasingAnimatorToCalcDuration(IEasing easing, Vector3 to, Func duration)
326 | {
327 | this.easing = easing;
328 | this.to = to;
329 | this.duration = duration;
330 | }
331 |
332 | public IAnimator Start(Vector3 startValue)
333 | {
334 | return new Vector3EasingAnimator(easing, startValue, to, duration);
335 | }
336 | }
337 |
338 | public class Vector4EasingAnimator : IAnimator
339 | {
340 | private readonly IEasing easing;
341 | private readonly Vector4 start;
342 | private readonly Vector4 end;
343 | private readonly float duration;
344 |
345 | public Vector4EasingAnimator(IEasing easing, Vector4 start, Vector4 end, float duration)
346 | {
347 | this.easing = easing;
348 | this.start = start;
349 | this.end = end;
350 | this.duration = duration;
351 | }
352 |
353 | public Vector4EasingAnimator(IEasing easing, Vector4 start, Vector4 end, Func duration)
354 | {
355 | this.easing = easing;
356 | this.start = start;
357 | this.end = end;
358 | this.duration = duration.Invoke(Vector4.Distance(start, end));
359 | }
360 |
361 | public (Vector4, float) Update(float time)
362 | {
363 | var value = Vector4.LerpUnclamped(start, end, easing.Function(Mathf.Min(time / duration, 1.0f)));
364 | return (value, Mathf.Min(time, duration));
365 | }
366 | }
367 |
368 | public class Vector4EasingAnimatorTo : IAnimatorWithStartValue
369 | {
370 | private readonly IEasing easing;
371 | private readonly Vector4 to;
372 | private readonly float duration;
373 |
374 | public Vector4EasingAnimatorTo(IEasing easing, Vector4 to, float duration)
375 | {
376 | this.easing = easing;
377 | this.to = to;
378 | this.duration = duration;
379 | }
380 |
381 | public IAnimator Start(Vector4 startValue)
382 | {
383 | return new Vector4EasingAnimator(easing, startValue, to, duration);
384 | }
385 | }
386 |
387 | public class Vector4EasingAnimatorToCalcDuration : IAnimatorWithStartValue
388 | {
389 | private readonly IEasing easing;
390 | private readonly Vector4 to;
391 | private readonly Func duration;
392 |
393 | public Vector4EasingAnimatorToCalcDuration(IEasing easing, Vector4 to, Func duration)
394 | {
395 | this.easing = easing;
396 | this.to = to;
397 | this.duration = duration;
398 | }
399 |
400 | public IAnimator Start(Vector4 startValue)
401 | {
402 | return new Vector4EasingAnimator(easing, startValue, to, duration);
403 | }
404 | }
405 |
406 | public class QuaternionEasingAnimator : IAnimator
407 | {
408 | private readonly IEasing easing;
409 | private readonly Quaternion start;
410 | private readonly Quaternion end;
411 | private readonly float duration;
412 |
413 | public QuaternionEasingAnimator(IEasing easing, Quaternion start, Quaternion end, float duration)
414 | {
415 | this.easing = easing;
416 | this.start = start;
417 | this.end = end;
418 | this.duration = duration;
419 | }
420 |
421 | public QuaternionEasingAnimator(IEasing easing, Quaternion start, Quaternion end, Func duration)
422 | {
423 | this.easing = easing;
424 | this.start = start;
425 | this.end = end;
426 | this.duration = duration.Invoke(Quaternion.Angle(start, end));
427 | }
428 |
429 | public (Quaternion, float) Update(float time)
430 | {
431 | var value = Quaternion.LerpUnclamped(start, end, easing.Function(Mathf.Min(time / duration, 1.0f)));
432 | return (value, Mathf.Min(time, duration));
433 | }
434 | }
435 |
436 | public class QuaternionEasingAnimatorTo : IAnimatorWithStartValue
437 | {
438 | private readonly IEasing easing;
439 | private readonly Quaternion to;
440 | private readonly float duration;
441 |
442 | public QuaternionEasingAnimatorTo(IEasing easing, Quaternion to, float duration)
443 | {
444 | this.easing = easing;
445 | this.to = to;
446 | this.duration = duration;
447 | }
448 |
449 | public IAnimator Start(Quaternion startValue)
450 | {
451 | return new QuaternionEasingAnimator(easing, startValue, to, duration);
452 | }
453 | }
454 |
455 | public class QuaternionEasingAnimatorToCalcDuration : IAnimatorWithStartValue
456 | {
457 | private readonly IEasing easing;
458 | private readonly Quaternion to;
459 | private readonly Func duration;
460 |
461 | public QuaternionEasingAnimatorToCalcDuration(IEasing easing, Quaternion to, Func duration)
462 | {
463 | this.easing = easing;
464 | this.to = to;
465 | this.duration = duration;
466 | }
467 |
468 | public IAnimator Start(Quaternion startValue)
469 | {
470 | return new QuaternionEasingAnimator(easing, startValue, to, duration);
471 | }
472 | }
473 |
474 | public class ColorEasingAnimator : IAnimator
475 | {
476 | private readonly IEasing easing;
477 | private readonly Color start;
478 | private readonly Color end;
479 | private readonly float duration;
480 |
481 | public ColorEasingAnimator(IEasing easing, Color start, Color end, float duration)
482 | {
483 | this.easing = easing;
484 | this.start = start;
485 | this.end = end;
486 | this.duration = duration;
487 | }
488 |
489 | public ColorEasingAnimator(IEasing easing, Color start, Color end, Func duration)
490 | {
491 | this.easing = easing;
492 | this.start = start;
493 | this.end = end;
494 | this.duration = duration.Invoke(Vector4.Distance(start, end));
495 | }
496 |
497 | public (Color, float) Update(float time)
498 | {
499 | var value = Color.LerpUnclamped(start, end, easing.Function(Mathf.Min(time / duration, 1.0f)));
500 | return (value, Mathf.Min(time, duration));
501 | }
502 | }
503 |
504 | public class ColorEasingAnimatorTo : IAnimatorWithStartValue
505 | {
506 | private readonly IEasing easing;
507 | private readonly Color to;
508 | private readonly float duration;
509 |
510 | public ColorEasingAnimatorTo(IEasing easing, Color to, float duration)
511 | {
512 | this.easing = easing;
513 | this.to = to;
514 | this.duration = duration;
515 | }
516 |
517 | public IAnimator Start(Color startValue)
518 | {
519 | return new ColorEasingAnimator(easing, startValue, to, duration);
520 | }
521 | }
522 |
523 | public class ColorEasingAnimatorToCalcDuration : IAnimatorWithStartValue
524 | {
525 | private readonly IEasing easing;
526 | private readonly Color to;
527 | private readonly Func duration;
528 |
529 | public ColorEasingAnimatorToCalcDuration(IEasing easing, Color to, Func duration)
530 | {
531 | this.easing = easing;
532 | this.to = to;
533 | this.duration = duration;
534 | }
535 |
536 | public IAnimator Start(Color startValue)
537 | {
538 | return new ColorEasingAnimator(easing, startValue, to, duration);
539 | }
540 | }
541 | }
542 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing/EasingAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 080cdd09ef0243beadecd415b417aacc
3 | timeCreated: 1538308436
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing/IEasing.cs:
--------------------------------------------------------------------------------
1 | namespace AnimeTask
2 | {
3 | public interface IEasing
4 | {
5 | float Function(float v);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Easing/IEasing.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 068edb0442bb43559f008701b4bc75ea
3 | timeCreated: 1538308788
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extension.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public static class Extension
7 | {
8 | public static AnimationCanceller GetAnimationCanceller(this GameObject self)
9 | {
10 | var holder = self.GetComponent();
11 | if (holder == null) holder = self.AddComponent();
12 | return holder;
13 | }
14 |
15 | public static AnimationCanceller GetAnimationCanceller(this Component self)
16 | {
17 | return self.gameObject.GetAnimationCanceller();
18 | }
19 | }
20 |
21 | public class AnimationCanceller : MonoBehaviour
22 | {
23 | private CancellationTokenSource cancellationTokenSource;
24 |
25 | public void OnDestroy()
26 | {
27 | Cancel();
28 | }
29 |
30 | public AnimationCanceller Cancel()
31 | {
32 | cancellationTokenSource?.Cancel();
33 | cancellationTokenSource = null;
34 | return this;
35 | }
36 |
37 | public CancellationTokenSource TokenSource
38 | {
39 | get
40 | {
41 | if (cancellationTokenSource == null)
42 | {
43 | cancellationTokenSource = new CancellationTokenSource();
44 | }
45 | return cancellationTokenSource;
46 | }
47 | }
48 |
49 | public CancellationToken Token => TokenSource.Token;
50 | }
51 | }
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 337d6840dfd6437c9ffd74d941a8de48
3 | timeCreated: 1615685409
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extensions.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e8057ab2011fc44a793f868d6cebc017
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extensions/AnimeTask.Extensions.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "AnimeTask.Extensions",
3 | "references": [
4 | "GUID:f51ebe6a0ceec4240a699833d6309b23",
5 | "GUID:1a4cffb770ce347a39cea41a326324ec",
6 | "GUID:560b04d1a97f54a4e82edc0cbbb69285"
7 | ],
8 | "includePlatforms": [],
9 | "excludePlatforms": [],
10 | "allowUnsafeCode": false,
11 | "overrideReferences": false,
12 | "precompiledReferences": [],
13 | "autoReferenced": true,
14 | "defineConstraints": [],
15 | "versionDefines": [
16 | {
17 | "name": "com.neuecc.unirx",
18 | "expression": "",
19 | "define": "ANIMETASK_UNIRX_SUPPORT"
20 | }
21 | ],
22 | "noEngineReferences": false
23 | }
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extensions/AnimeTask.Extensions.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 22c229c920c2e4e128336d5767e12217
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extensions/UniRxExtensions.cs:
--------------------------------------------------------------------------------
1 | #if ANIMETASK_UNIRX_SUPPORT
2 | using System;
3 | using System.Threading;
4 | using Cysharp.Threading.Tasks;
5 | using UniRx;
6 |
7 | namespace AnimeTask.Extensions
8 | {
9 | public static class UniRxExtensions
10 | {
11 | public static IDisposable SubscribeTask(this IObservable source, Func taskFunc)
12 | {
13 | var cancellationTokenSource = new CancellationTokenSource();
14 | return source
15 | .DoOnCancel(() =>
16 | {
17 | cancellationTokenSource.Cancel();
18 | })
19 | .Subscribe(x =>
20 | {
21 | cancellationTokenSource.Cancel();
22 | cancellationTokenSource = new CancellationTokenSource();
23 | taskFunc(x, cancellationTokenSource.Token).Forget();
24 | });
25 | }
26 | }
27 | }
28 | #endif
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Extensions/UniRxExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 58214ab873c14421fbf97c15c2e94e15
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/IAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AnimeTask
4 | {
5 | public interface IConcatableAnimator
6 | {
7 | }
8 |
9 | public interface IAnimator : IConcatableAnimator
10 | {
11 | (T, float) Update(float time);
12 | }
13 |
14 | public interface IAnimatorWithStartValue : IConcatableAnimator
15 | {
16 | IAnimator Start(T startValue);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/IAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f44ffe8ff9cc4a6da1da15d53340cad2
3 | timeCreated: 1538306293
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/IScheduler.cs:
--------------------------------------------------------------------------------
1 | using Cysharp.Threading.Tasks;
2 |
3 | namespace AnimeTask
4 | {
5 | public interface IScheduler
6 | {
7 | float DeltaTime { get; }
8 | PlayerLoopTiming UpdateTiming { get; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/IScheduler.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7c092a298415423caeb02dd348e1d07b
3 | timeCreated: 1538838737
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/ITranslator.cs:
--------------------------------------------------------------------------------
1 | namespace AnimeTask
2 | {
3 | public interface ITranslator
4 | {
5 | bool Alive { get; }
6 | void Update(T value);
7 | }
8 |
9 | public interface IValueTranslator : ITranslator
10 | {
11 | T Current { get; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/ITranslator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5161bbc83f164876a43bd7a98e965de6
3 | timeCreated: 1538306307
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 79dc0ef45b9a4ed1ab5180a6a25078e7
3 | timeCreated: 1593310408
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving/AnimationCurveAnimator.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace AnimeTask
4 | {
5 | public static partial class Moving
6 | {
7 | public static AnimationCurveAnimator AnimationCurve(AnimationCurve animationCurve, float playSpeed = 1.0f)
8 | {
9 | return new AnimationCurveAnimator(animationCurve, playSpeed);
10 | }
11 | }
12 |
13 | public class AnimationCurveAnimator : IAnimator
14 | {
15 | private readonly AnimationCurve animationCurve;
16 | private readonly float playSpeed;
17 | private readonly float duration;
18 |
19 | public AnimationCurveAnimator(AnimationCurve animationCurve, float playSpeed)
20 | {
21 | this.animationCurve = animationCurve;
22 | this.playSpeed = playSpeed;
23 | duration = animationCurve.keys[animationCurve.keys.Length - 1].time / playSpeed;
24 | }
25 |
26 | public (float, float) Update(float time)
27 | {
28 | var value = animationCurve.Evaluate(time * playSpeed);
29 | return (value, Mathf.Min(time, duration));
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving/AnimationCurveAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0c2781c2396a43b3aba21850a31e630e
3 | timeCreated: 1618362364
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving/GravityAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public static partial class Moving
7 | {
8 | public static Vector1GravityMovingAnimator Gravity(float start, float velocity, float acceleration, float duration)
9 | {
10 | return new Vector1GravityMovingAnimator(start, velocity, acceleration, duration);
11 | }
12 |
13 | public static Vector1GravityMovingAnimatorWithStartValue Gravity(float velocity, float acceleration, float duration)
14 | {
15 | return new Vector1GravityMovingAnimatorWithStartValue(velocity, acceleration, duration);
16 | }
17 |
18 | public static Vector2GravityMovingAnimator Gravity(Vector2 start, Vector2 velocity, Vector2 acceleration, float duration)
19 | {
20 | return new Vector2GravityMovingAnimator(start, velocity, acceleration, duration);
21 | }
22 |
23 | public static Vector2GravityMovingAnimatorWithStartValue Gravity(Vector2 velocity, Vector2 acceleration, float duration)
24 | {
25 | return new Vector2GravityMovingAnimatorWithStartValue(velocity, acceleration, duration);
26 | }
27 |
28 | public static Vector3GravityMovingAnimator Gravity(Vector3 start, Vector3 velocity, Vector3 acceleration, float duration)
29 | {
30 | return new Vector3GravityMovingAnimator(start, velocity, acceleration, duration);
31 | }
32 |
33 | public static Vector3GravityMovingAnimatorWithStartValue Gravity(Vector3 velocity, Vector3 acceleration, float duration)
34 | {
35 | return new Vector3GravityMovingAnimatorWithStartValue(velocity, acceleration, duration);
36 | }
37 | }
38 |
39 | public class Vector1GravityMovingAnimator : IAnimator
40 | {
41 | private readonly float start;
42 | private readonly float velocity;
43 | private readonly float acceleration;
44 | private readonly float duration;
45 |
46 | public Vector1GravityMovingAnimator(float start, float velocity, float acceleration, float duration)
47 | {
48 | this.start = start;
49 | this.velocity = velocity;
50 | this.acceleration = acceleration;
51 | this.duration = duration;
52 | }
53 |
54 | public (float, float) Update(float time)
55 | {
56 | var t = Mathf.Min(time, duration);
57 | var value = start + velocity * t + acceleration * (0.5f * t * t);
58 | return (value, Mathf.Min(time, duration));
59 | }
60 | }
61 |
62 | public class Vector1GravityMovingAnimatorWithStartValue : IAnimatorWithStartValue
63 | {
64 | private readonly float velocity;
65 | private readonly float acceleration;
66 | private readonly float duration;
67 |
68 | public Vector1GravityMovingAnimatorWithStartValue(float velocity, float acceleration, float duration)
69 | {
70 | this.velocity = velocity;
71 | this.acceleration = acceleration;
72 | this.duration = duration;
73 | }
74 |
75 | public IAnimator Start(float startValue)
76 | {
77 | return new Vector1GravityMovingAnimator(startValue, velocity, acceleration, duration);
78 | }
79 | }
80 |
81 | public class Vector2GravityMovingAnimator : IAnimator
82 | {
83 | private readonly Vector2 start;
84 | private readonly Vector2 velocity;
85 | private readonly Vector2 acceleration;
86 | private readonly float duration;
87 |
88 | public Vector2GravityMovingAnimator(Vector2 start, Vector2 velocity, Vector2 acceleration, float duration)
89 | {
90 | this.start = start;
91 | this.velocity = velocity;
92 | this.acceleration = acceleration;
93 | this.duration = duration;
94 | }
95 |
96 | public (Vector2, float) Update(float time)
97 | {
98 | var t = Mathf.Min(time, duration);
99 | var value = start + velocity * t + acceleration * (0.5f * t * t);
100 | return (value, Mathf.Min(time, duration));
101 | }
102 | }
103 |
104 | public class Vector2GravityMovingAnimatorWithStartValue : IAnimatorWithStartValue
105 | {
106 | private readonly Vector2 velocity;
107 | private readonly Vector2 acceleration;
108 | private readonly float duration;
109 |
110 | public Vector2GravityMovingAnimatorWithStartValue(Vector2 velocity, Vector2 acceleration, float duration)
111 | {
112 | this.velocity = velocity;
113 | this.acceleration = acceleration;
114 | this.duration = duration;
115 | }
116 |
117 | public IAnimator Start(Vector2 startValue)
118 | {
119 | return new Vector2GravityMovingAnimator(startValue, velocity, acceleration, duration);
120 | }
121 | }
122 |
123 | public class Vector3GravityMovingAnimator : IAnimator
124 | {
125 | private readonly Vector3 start;
126 | private readonly Vector3 velocity;
127 | private readonly Vector3 acceleration;
128 | private readonly float duration;
129 |
130 | public Vector3GravityMovingAnimator(Vector3 start, Vector3 velocity, Vector3 acceleration, float duration)
131 | {
132 | this.start = start;
133 | this.velocity = velocity;
134 | this.acceleration = acceleration;
135 | this.duration = duration;
136 | }
137 |
138 | public (Vector3, float) Update(float time)
139 | {
140 | var t = Mathf.Min(time, duration);
141 | var value = start + velocity * t + acceleration * (0.5f * t * t);
142 | return (value, Mathf.Min(time, duration));
143 | }
144 | }
145 |
146 | public class Vector3GravityMovingAnimatorWithStartValue : IAnimatorWithStartValue
147 | {
148 | private readonly Vector3 velocity;
149 | private readonly Vector3 acceleration;
150 | private readonly float duration;
151 |
152 | public Vector3GravityMovingAnimatorWithStartValue(Vector3 velocity, Vector3 acceleration, float duration)
153 | {
154 | this.velocity = velocity;
155 | this.acceleration = acceleration;
156 | this.duration = duration;
157 | }
158 |
159 | public IAnimator Start(Vector3 startValue)
160 | {
161 | return new Vector3GravityMovingAnimator(startValue, velocity, acceleration, duration);
162 | }
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving/GravityAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f2c9b792fb474848b7a0f0fe74b092e2
3 | timeCreated: 1593311087
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving/LinearAnimator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public static partial class Moving
7 | {
8 | public static Vector1LinearMovingAnimator Linear(float start, float velocity, float duration)
9 | {
10 | return new Vector1LinearMovingAnimator(start, velocity, duration);
11 | }
12 |
13 | public static Vector1LinearMovingAnimatorWithStartValue Linear(float velocity, float duration)
14 | {
15 | return new Vector1LinearMovingAnimatorWithStartValue(velocity, duration);
16 | }
17 |
18 | public static Vector2LinearMovingAnimator Linear(Vector2 start, Vector2 velocity, float duration)
19 | {
20 | return new Vector2LinearMovingAnimator(start, velocity, duration);
21 | }
22 |
23 | public static Vector2LinearMovingAnimatorWithStartValue Linear(Vector2 velocity, float duration)
24 | {
25 | return new Vector2LinearMovingAnimatorWithStartValue(velocity, duration);
26 | }
27 |
28 | public static Vector3LinearMovingAnimator Linear(Vector3 start, Vector3 velocity, float duration)
29 | {
30 | return new Vector3LinearMovingAnimator(start, velocity, duration);
31 | }
32 |
33 | public static Vector3LinearMovingAnimatorWithStartValue Linear(Vector3 velocity, float duration)
34 | {
35 | return new Vector3LinearMovingAnimatorWithStartValue(velocity, duration);
36 | }
37 | }
38 |
39 | public class Vector1LinearMovingAnimator : IAnimator
40 | {
41 | private readonly float start;
42 | private readonly float velocity;
43 | private readonly float duration;
44 |
45 | public Vector1LinearMovingAnimator(float start, float velocity, float duration)
46 | {
47 | this.start = start;
48 | this.velocity = velocity;
49 | this.duration = duration;
50 | }
51 |
52 | public (float, float) Update(float time)
53 | {
54 | var value = start + velocity * Mathf.Min(time, duration);
55 | return (value, Mathf.Min(time, duration));
56 | }
57 | }
58 |
59 | public class Vector1LinearMovingAnimatorWithStartValue : IAnimatorWithStartValue
60 | {
61 | private readonly float velocity;
62 | private readonly float duration;
63 |
64 | public Vector1LinearMovingAnimatorWithStartValue(float velocity, float duration)
65 | {
66 | this.velocity = velocity;
67 | this.duration = duration;
68 | }
69 |
70 | public IAnimator Start(float startValue)
71 | {
72 | return new Vector1LinearMovingAnimator(startValue, velocity, duration);
73 | }
74 | }
75 |
76 | public class Vector2LinearMovingAnimator : IAnimator
77 | {
78 | private readonly Vector2 start;
79 | private readonly Vector2 velocity;
80 | private readonly float duration;
81 |
82 | public Vector2LinearMovingAnimator(Vector2 start, Vector2 velocity, float duration)
83 | {
84 | this.start = start;
85 | this.velocity = velocity;
86 | this.duration = duration;
87 | }
88 |
89 | public (Vector2, float) Update(float time)
90 | {
91 | var value = start + velocity * Mathf.Min(time, duration);
92 | return (value, Mathf.Min(time, duration));
93 | }
94 | }
95 |
96 | public class Vector2LinearMovingAnimatorWithStartValue : IAnimatorWithStartValue
97 | {
98 | private readonly Vector2 velocity;
99 | private readonly float duration;
100 |
101 | public Vector2LinearMovingAnimatorWithStartValue(Vector2 velocity, float duration)
102 | {
103 | this.velocity = velocity;
104 | this.duration = duration;
105 | }
106 |
107 | public IAnimator Start(Vector2 startValue)
108 | {
109 | return new Vector2LinearMovingAnimator(startValue, velocity, duration);
110 | }
111 | }
112 |
113 | public class Vector3LinearMovingAnimator : IAnimator
114 | {
115 | private readonly Vector3 start;
116 | private readonly Vector3 velocity;
117 | private readonly float duration;
118 |
119 | public Vector3LinearMovingAnimator(Vector3 start, Vector3 velocity, float duration)
120 | {
121 | this.start = start;
122 | this.velocity = velocity;
123 | this.duration = duration;
124 | }
125 |
126 | public (Vector3, float) Update(float time)
127 | {
128 | var value = start + velocity * Mathf.Min(time, duration);
129 | return (value, Mathf.Min(time, duration));
130 | }
131 | }
132 |
133 | public class Vector3LinearMovingAnimatorWithStartValue : IAnimatorWithStartValue
134 | {
135 | private readonly Vector3 velocity;
136 | private readonly float duration;
137 |
138 | public Vector3LinearMovingAnimatorWithStartValue(Vector3 velocity, float duration)
139 | {
140 | this.velocity = velocity;
141 | this.duration = duration;
142 | }
143 |
144 | public IAnimator Start(Vector3 startValue)
145 | {
146 | return new Vector3LinearMovingAnimator(startValue, velocity, duration);
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Moving/LinearAnimator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c9b873be82504796849cf5ba1ba1a051
3 | timeCreated: 1593310415
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Scheduler.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7449372804554557b9c5f7c29873e8c4
3 | timeCreated: 1538838813
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Scheduler/TimeScheduler.cs:
--------------------------------------------------------------------------------
1 | using Cysharp.Threading.Tasks;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public class TimeScheduler : IScheduler
7 | {
8 | public float DeltaTime => Time.deltaTime;
9 | public PlayerLoopTiming UpdateTiming => PlayerLoopTiming.Update;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Scheduler/TimeScheduler.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f0437061e48649dfb6ff636e44e5a22f
3 | timeCreated: 1538838820
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Scheduler/UnscaledTimeScheduler.cs:
--------------------------------------------------------------------------------
1 | using Cysharp.Threading.Tasks;
2 | using UnityEngine;
3 |
4 | namespace AnimeTask
5 | {
6 | public class UnscaledTimeScheduler : IScheduler
7 | {
8 | public float DeltaTime => Time.unscaledDeltaTime;
9 | public PlayerLoopTiming UpdateTiming => PlayerLoopTiming.Update;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Scheduler/UnscaledTimeScheduler.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0a815dc30e9146f6a63cf0a26d73f32e
3 | timeCreated: 1538838870
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Translator.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3566147fb13f433aa422e0941de88e2c
3 | timeCreated: 1538308771
--------------------------------------------------------------------------------
/Assets/AnimeTask/Scripts/Translator/ActionTranslator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using Cysharp.Threading.Tasks;
4 | using JetBrains.Annotations;
5 | using Object = UnityEngine.Object;
6 |
7 | namespace AnimeTask
8 | {
9 | public static partial class TranslateTo
10 | {
11 | [MustUseReturnValue]
12 | public static UniTask ToAction(this IAnimator animator, Action action, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
13 | {
14 | return Anime.Play(animator, new ActionTranslator(action), scheduler, cancellationToken, skipToken);
15 | }
16 |
17 | [MustUseReturnValue]
18 | public static UniTask ToAction(this IAnimator animator, Action action, Object unityObject, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
19 | {
20 | return Anime.Play(animator, new ActionTranslatorWithObject(action, unityObject), scheduler, cancellationToken, skipToken);
21 | }
22 | }
23 |
24 | public class ActionTranslator : ITranslator
25 | {
26 | public bool Alive => true;
27 |
28 | private readonly Action action;
29 |
30 | public ActionTranslator(Action action)
31 | {
32 | this.action = action;
33 | }
34 |
35 | public void Update(T value)
36 | {
37 | action(value);
38 | }
39 | }
40 |
41 | public class ActionTranslatorWithObject : ITranslator
42 | {
43 | public bool Alive => unityObject != null;
44 |
45 | private readonly Action