Skip to content

Commit

Permalink
feat: AnimeTaskにGameObject,Componentが渡されていた時点でDestroy済みでも正しくTaskをキャンセルする
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubuns committed Jun 28, 2021
1 parent 13ad34e commit f5ea918
Show file tree
Hide file tree
Showing 11 changed files with 860 additions and 139 deletions.
6 changes: 5 additions & 1 deletion Assets/AnimeTask/Scripts/Translator/ActionTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ namespace AnimeTask
{
public static partial class TranslateTo
{
[MustUseReturnValue] public static UniTask ToAction<T>(this IAnimator<T> animator, Action<T> action, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new ActionTranslator<T>(action), scheduler, cancellationToken, skipToken);
[MustUseReturnValue]
public static UniTask ToAction<T>(this IAnimator<T> animator, Action<T> action, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.Play(animator, new ActionTranslator<T>(action), scheduler, cancellationToken, skipToken);
}
}

public class ActionTranslator<T> : ITranslator<T>
Expand Down
13 changes: 11 additions & 2 deletions Assets/AnimeTask/Scripts/Translator/BindTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ namespace AnimeTask
{
public static partial class TranslateTo
{
[MustUseReturnValue] public static UniTask ToBind<T>(this IAnimator<T> animator, Func<T> getter, Action<T> setter, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new BindTranslator<T>(getter, setter), scheduler, cancellationToken, skipToken);
[MustUseReturnValue] public static UniTask ToBind<T>(this IAnimatorWithStartValue<T> animator, Func<T> getter, Action<T> setter, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new BindTranslator<T>(getter, setter), scheduler, cancellationToken, skipToken);
[MustUseReturnValue]
public static UniTask ToBind<T>(this IAnimator<T> animator, Func<T> getter, Action<T> setter, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.Play(animator, new BindTranslator<T>(getter, setter), scheduler, cancellationToken, skipToken);
}

[MustUseReturnValue]
public static UniTask ToBind<T>(this IAnimatorWithStartValue<T> animator, Func<T> getter, Action<T> setter, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.PlayTo(animator, new BindTranslator<T>(getter, setter), scheduler, cancellationToken, skipToken);
}
}

public class BindTranslator<T> : IValueTranslator<T>
Expand Down
97 changes: 83 additions & 14 deletions Assets/AnimeTask/Scripts/Translator/MaterialTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,89 @@ namespace AnimeTask
{
public static partial class TranslateTo
{
[MustUseReturnValue] public static UniTask ToMaterialPropertyColor(this IAnimator<Color> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new MaterialPropertyColorTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyColor(this IAnimator<Color> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new MaterialPropertyColorTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyColor(this IAnimatorWithStartValue<Color> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new MaterialPropertyColorTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyColor(this IAnimatorWithStartValue<Color> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new MaterialPropertyColorTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);

[MustUseReturnValue] public static UniTask ToMaterialPropertyFloat(this IAnimator<float> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new MaterialPropertyFloatTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyFloat(this IAnimator<float> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new MaterialPropertyFloatTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyFloat(this IAnimatorWithStartValue<float> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new MaterialPropertyFloatTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyFloat(this IAnimatorWithStartValue<float> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new MaterialPropertyFloatTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);

[MustUseReturnValue] public static UniTask ToMaterialPropertyInt(this IAnimator<int> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new MaterialPropertyIntTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyInt(this IAnimator<int> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new MaterialPropertyIntTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyInt(this IAnimatorWithStartValue<int> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new MaterialPropertyIntTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue] public static UniTask ToMaterialPropertyInt(this IAnimatorWithStartValue<int> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new MaterialPropertyIntTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
[MustUseReturnValue]
public static UniTask ToMaterialPropertyColor(this IAnimator<Color> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.Play(animator, new MaterialPropertyColorTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyColor(this IAnimator<Color> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.Play(animator, new MaterialPropertyColorTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyColor(this IAnimatorWithStartValue<Color> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.PlayTo(animator, new MaterialPropertyColorTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyColor(this IAnimatorWithStartValue<Color> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.PlayTo(animator, new MaterialPropertyColorTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyFloat(this IAnimator<float> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.Play(animator, new MaterialPropertyFloatTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyFloat(this IAnimator<float> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.Play(animator, new MaterialPropertyFloatTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyFloat(this IAnimatorWithStartValue<float> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.PlayTo(animator, new MaterialPropertyFloatTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyFloat(this IAnimatorWithStartValue<float> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.PlayTo(animator, new MaterialPropertyFloatTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyInt(this IAnimator<int> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.Play(animator, new MaterialPropertyIntTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyInt(this IAnimator<int> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.Play(animator, new MaterialPropertyIntTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyInt(this IAnimatorWithStartValue<int> animator, Renderer renderer, int nameID, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.PlayTo(animator, new MaterialPropertyIntTranslator(renderer, nameID), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}

[MustUseReturnValue]
public static UniTask ToMaterialPropertyInt(this IAnimatorWithStartValue<int> animator, Renderer renderer, string name, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
CheckAlive(renderer);
return Anime.PlayTo(animator, new MaterialPropertyIntTranslator(renderer, name), scheduler, CancellationTokenSource.CreateLinkedTokenSource(renderer.GetCancellationTokenOnDestroy(), cancellationToken).Token, skipToken);
}
}

public class MaterialPropertyColorTranslator : IValueTranslator<Color>
Expand Down
13 changes: 11 additions & 2 deletions Assets/AnimeTask/Scripts/Translator/NoneTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ namespace AnimeTask
{
public static partial class TranslateTo
{
[MustUseReturnValue] public static UniTask ToNone<T>(this IAnimator<T> animator, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new NoneTranslator<T>(), scheduler, cancellationToken, skipToken);
[MustUseReturnValue] public static UniTask ToNone<T>(this IAnimatorWithStartValue<T> animator, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new NoneTranslator<T>(), scheduler, cancellationToken, skipToken);
[MustUseReturnValue]
public static UniTask ToNone<T>(this IAnimator<T> animator, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.Play(animator, new NoneTranslator<T>(), scheduler, cancellationToken, skipToken);
}

[MustUseReturnValue]
public static UniTask ToNone<T>(this IAnimatorWithStartValue<T> animator, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.PlayTo(animator, new NoneTranslator<T>(), scheduler, cancellationToken, skipToken);
}
}

public class NoneTranslator<T> : IValueTranslator<T>
Expand Down
6 changes: 5 additions & 1 deletion Assets/AnimeTask/Scripts/Translator/ProgressTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ namespace AnimeTask
{
public static partial class TranslateTo
{
[MustUseReturnValue] public static UniTask ToProgress<T>(this IAnimator<T> animator, IProgress<T> progress, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new ProgressTranslator<T>(progress), scheduler, cancellationToken, skipToken);
[MustUseReturnValue]
public static UniTask ToProgress<T>(this IAnimator<T> animator, IProgress<T> progress, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.Play(animator, new ProgressTranslator<T>(progress), scheduler, cancellationToken, skipToken);
}
}

public class ProgressTranslator<T> : ITranslator<T>
Expand Down
13 changes: 11 additions & 2 deletions Assets/AnimeTask/Scripts/Translator/ReactivePropertyTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ namespace AnimeTask
{
public static partial class TranslateTo
{
[MustUseReturnValue] public static UniTask ToReactiveProperty<T>(this IAnimator<T> animator, ReactiveProperty<T> reactiveProperty, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.Play(animator, new ReactivePropertyTranslator<T>(reactiveProperty), scheduler, cancellationToken, skipToken);
[MustUseReturnValue] public static UniTask ToReactiveProperty<T>(this IAnimatorWithStartValue<T> animator, ReactiveProperty<T> reactiveProperty, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default) => Anime.PlayTo(animator, new ReactivePropertyTranslator<T>(reactiveProperty), scheduler, cancellationToken, skipToken);
[MustUseReturnValue]
public static UniTask ToReactiveProperty<T>(this IAnimator<T> animator, ReactiveProperty<T> reactiveProperty, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.Play(animator, new ReactivePropertyTranslator<T>(reactiveProperty), scheduler, cancellationToken, skipToken);
}

[MustUseReturnValue]
public static UniTask ToReactiveProperty<T>(this IAnimatorWithStartValue<T> animator, ReactiveProperty<T> reactiveProperty, CancellationToken cancellationToken = default, SkipToken skipToken = default, IScheduler scheduler = default)
{
return Anime.PlayTo(animator, new ReactivePropertyTranslator<T>(reactiveProperty), scheduler, cancellationToken, skipToken);
}
}

public class ReactivePropertyTranslator<T> : IValueTranslator<T>
Expand Down
Loading

0 comments on commit f5ea918

Please sign in to comment.