Created
September 30, 2018 09:49
-
-
Save kyubuns/090dbbd0cc861171b6d66f27658dd5f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using AnimeTask; | |
using UnityEngine; | |
using Animator = AnimeTask.Animator; | |
public class Hoge : MonoBehaviour | |
{ | |
public async void Start() | |
{ | |
Debug.Log("Move Start"); | |
await Anime.Play( | |
Translate.LocalPosition(transform), | |
new Vector3(-5f, 0f, 0f), | |
new Vector3(5f, 0f, 0f), | |
Animator.Uniform(TimeSpan.FromSeconds(2f)) | |
); | |
Debug.Log("Move End"); | |
} | |
} | |
namespace AnimeTask | |
{ | |
public static class Anime | |
{ | |
public static Task Play<T>(ITranslator<T> translator, T start, T end, IAnimator<T> animator) | |
{ | |
var now = animator.Update(start, end); | |
translator.Update(now); | |
return Task.CompletedTask; | |
} | |
} | |
public interface IAnimator<T> | |
{ | |
T Update(T start, T end); | |
} | |
public static class Animator | |
{ | |
public static IAnimator<Vector3> Uniform(TimeSpan duration) | |
{ | |
return new UniformAnimator(); | |
} | |
public class UniformAnimator : IAnimator<Vector3> | |
{ | |
public Vector3 Update(Vector3 start, Vector3 end) | |
{ | |
return start; | |
} | |
} | |
} | |
public interface ITranslator<in T> | |
{ | |
void Update(T value); | |
} | |
public static class Translate | |
{ | |
public static ITranslator<Vector3> LocalPosition(Transform transform) | |
{ | |
return new PositionTranslator(transform); | |
} | |
public class PositionTranslator : ITranslator<Vector3> | |
{ | |
private readonly Transform transform; | |
public PositionTranslator(Transform transform) | |
{ | |
this.transform = transform; | |
} | |
public void Update(Vector3 value) | |
{ | |
transform.localPosition = value; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment