using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Reflection; namespace YKMoon.Tween { public abstract class YKTweenValueType : YKTween where T:struct { public T start { get; protected set; } public T end { get; protected set; } public T value { get; protected set; } public System.Action onValueChange; public YKTweenValueType(float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { } public override bool IsValid() { return true; } public override void Finish(bool withCallback) { TweenValue(1); base.Finish(withCallback); } } public class YKTweenFloat : YKTweenValueType { public YKTweenFloat(float start, float end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { this.start = start; this.end = end; } public override void TweenValue(float percent) { value = start + (end - start) * percent; onValueChange?.Invoke(value); } } public class YKTweenVector2 : YKTweenValueType { public YKTweenVector2(Vector2 start, Vector2 end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { this.start = start; this.end = end; } public override void TweenValue(float percent) { value = start + (end - start) * percent; onValueChange?.Invoke(value); } } public class YKTweenVector3 : YKTweenValueType { public YKTweenVector3(Vector3 start, Vector3 end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { this.start = start; this.end = end; } public override void TweenValue(float percent) { value = start + (end - start) * percent; onValueChange?.Invoke(value); } } public class YKTweenVector4 : YKTweenValueType { public YKTweenVector4(Vector4 start, Vector4 end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { this.start = start; this.end = end; } public override void TweenValue(float percent) { value = start + (end - start) * percent; onValueChange?.Invoke(value); } } public class YKTweenColor : YKTweenValueType { public YKTweenColor(Color start, Color end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { this.start = start; this.end = end; } public override void TweenValue(float percent) { value = start + (end - start) * percent; onValueChange?.Invoke(value); } } public class YKTweenCorner4 : YKTweenValueType { public YKTweenCorner4(Corner4 start, Corner4 end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : base(duration, easing, ignoreTimeScale) { this.start = start; this.end = end; } public override void TweenValue(float percent) { value = start + (end - start) * percent; onValueChange?.Invoke(value); } } //public class YKTween : YKTween //{ // public T start { get; private set; } // public T end { get; private set; } // public T value { get; private set; } // public System.Action onValueChange; // public YKTween(T start, T end, float duration, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) : // base(duration, easing, ignoreTimeScale) // { // this.start = start; // this.end = end; // } // public override void TweenValue(float percent) // { // value = (dynamic)start + ((dynamic)end - (dynamic)start) * percent; // onValueChange?.Invoke(value); // } // public override bool IsValid() // { // return true; // } // public override void Finish(bool withCallback) // { // TweenValue(1); // base.Finish(withCallback); // } // /*private static V Plus(V num1, V num2) where V : struct//»áÔÚIL2CPPʱ±¨´í // { // dynamic v1 = num1; // dynamic v2 = num2; // return (V)(v1 + v2); // } // private static V Minus(V num1, V num2) where V : struct // { // dynamic v1 = num1; // dynamic v2 = num2; // return (V)(v1 - v2); // } // private static V Multy(V num, float p) where V : struct // { // dynamic v1 = num; // dynamic v2 = p; // return (V)(num * v2); // } // private bool SupportOperAdd() // { // var c = System.Linq.Expressions.Expression.Constant(default(T), typeof(T)); // try { // System.Linq.Expressions.Expression.Add(c, c); // return true; // } catch { // return false; // } // }*/ //} public partial class YKTweenManager { //public YKTween StartTween(T start, T to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) where T : struct //{ // YKTween tween = new YKTween(start, to, duration, easing, ignoreTimeScale); // tween.onFinish = onFinish; // tween.onValueChange = onValueChange; // StartTween(tween); // return tween; //} public YKTweenFloat StartTween(float start, float to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) { YKTweenFloat tween = new YKTweenFloat(start, to, duration, easing, ignoreTimeScale); tween.onFinish = onFinish; tween.onValueChange = onValueChange; StartTween(tween); return tween; } public YKTweenVector2 StartTween(Vector2 start, Vector2 to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) { YKTweenVector2 tween = new YKTweenVector2(start, to, duration, easing, ignoreTimeScale); tween.onFinish = onFinish; tween.onValueChange = onValueChange; StartTween(tween); return tween; } public YKTweenVector3 StartTween(Vector3 start, Vector3 to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) { YKTweenVector3 tween = new YKTweenVector3(start, to, duration, easing, ignoreTimeScale); tween.onFinish = onFinish; tween.onValueChange = onValueChange; StartTween(tween); return tween; } public YKTweenVector4 StartTween(Vector4 start, Vector4 to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) { YKTweenVector4 tween = new YKTweenVector4(start, to, duration, easing, ignoreTimeScale); tween.onFinish = onFinish; tween.onValueChange = onValueChange; StartTween(tween); return tween; } public YKTweenColor StartTween(Color start, Color to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) { YKTweenColor tween = new YKTweenColor(start, to, duration, easing, ignoreTimeScale); tween.onFinish = onFinish; tween.onValueChange = onValueChange; StartTween(tween); return tween; } public YKTweenCorner4 StartTween(Corner4 start, Corner4 to, float duration, System.Action onValueChange = null, System.Action onFinish = null, TweenEasing easing = TweenEasing.Linear, bool ignoreTimeScale = false) { YKTweenCorner4 tween = new YKTweenCorner4(start, to, duration, easing, ignoreTimeScale); tween.onFinish = onFinish; tween.onValueChange = onValueChange; StartTween(tween); return tween; } } }