static IEnumerator _Animate(PropertyInfo info, object target, object end, float time, Lerper lerper, EaseMode mode) { object start = info.GetValue(target); float t = 0; while (t < 1) { t += Time.deltaTime / time; info.SetValue(target, lerper.Lerp(start, end, Ease(t, mode))); yield return(null); } info.SetValue(target, end); }
static void Animate(PropertyInfo info, Component target, object end, float time, Lerper lerper, EaseMode mode) { if (!target.TryGetComponent(out AnimationCoroutineContainer container)) { container = target.gameObject.AddComponent <AnimationCoroutineContainer>(); } container.StartCoroutine(_Animate(info, target, end, time, lerper, mode)); }
static void Animate <T>(Action <T> setter, Component target, T start, T end, float time, Lerper lerper, EaseMode mode) { if (!target.TryGetComponent(out AnimationCoroutineContainer container)) { container = target.gameObject.AddComponent <AnimationCoroutineContainer>(); } container.StartCoroutine(_Animate(setter, start, end, time, lerper, mode)); }
static IEnumerator _Animate <T>(Action <T> setter, T start, T end, float time, Lerper lerper, EaseMode mode) { setter(start); float t = 0; while (t < 1) { t += Time.deltaTime / time; setter((T)lerper.Lerp(start, end, Ease(t, mode))); yield return(null); } setter(end); }
static void Animate(PropertyInfo info, Component target, object end, float time, Lerper lerper, EaseMode mode) { Animate(o => info.SetValue(target, o), target, info.GetValue(target), end, time, lerper, mode); }