public Tween Create(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) { Tween t = new Tween(name, func, callback, time, pingpong, loop, initialDirection); Tweens.Add(t); return t; }
public Tween(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) : this(name, func, callback, time, pingpong, loop) { CurrentDirection = initialDirection; InitialDirection = initialDirection; if (initialDirection == TweenDirection.Reverse) CurrentTime = TargetTime; }
public static TweenFunc<Vector2> WrapVector2 (TweenFunc<float> func) { return (from, to, t) => { return new Vector2( func(from.X, to.X, t), func(from.Y, to.Y, t) ); }; }
public Controller(T start, TweenFunc <T> easing, Action <T> callback, Action <Controller <T> > done = null) { _val = _from = start; _easing = easing; _callback = callback; _done = done; _isDone = true; }
public Tween Create(string name, TweenFunc func, Action <Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) { Tween t = new Tween(name, func, callback, time, pingpong, loop, initialDirection); Tweens.Add(t); return(t); }
public static TweenFunc <Vector2> WrapVector2(TweenFunc <float> func) { return((from, to, t) => { return new Vector2( func(from.X, to.X, t), func(from.Y, to.Y, t) ); }); }
public static TweenFunc<Color> WrapColor (TweenFunc<float> func) { return (from, to, t) => { return Color.FromArgb( (int)func(from.A, to.A, t), (int)func(from.R, to.R, t), (int)func(from.G, to.G, t), (int)func(from.B, to.B, t)); }; }
public Tween(float tStart, float tEnd, float tDur, TweenFunc func) { distance= tEnd-tStart; original= tStart; current= tStart; totalDuration= tDur; tweenFunc= func; totalT= 0; pFinished= false; }
public static TweenFunc <Color> WrapColor(TweenFunc <float> func) { return((from, to, t) => { return Color.FromArgb( (int)func(from.A, to.A, t), (int)func(from.R, to.R, t), (int)func(from.G, to.G, t), (int)func(from.B, to.B, t)); }); }
public Tween(string name, TweenFunc func, Action <Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) : this(name, func, callback, time, pingpong, loop) { CurrentDirection = initialDirection; InitialDirection = initialDirection; if (initialDirection == TweenDirection.Reverse) { CurrentTime = TargetTime; } }
public void To(T from, T to, float duration, Action <Controller <T> > done = null, TweenFunc <T> easing = null) { if (easing != null) { _easing = easing; } _duration = duration; _time = 0f; _from = from; _to = to; _done2 = done; _isDone = false; }
public Transition(T from, T to, float duration, TweenFunc <T> easing, Action <T> callback, Action done = null) { _from = from; _to = to; _time = 0f; _duration = duration; _easing = easing; _callback = callback; _done = done; }
public Tween(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop) { Name = name; _callback = callback; _tweenFunc = func; TargetTime = time; Looping = loop; PingPong = pingpong; CurrentTime = 0; CurrentDirection = TweenDirection.Forward; InitialDirection = TweenDirection.Forward; Value = 0f; if (PingPong) TargetTime /= 2; // If we're pingponging, halve the time so that TargetTime is one complete cycle }
public Tween(string name, TweenFunc func, Action <Tween> callback, double time, bool pingpong, bool loop) { Name = name; _callback = callback; _tweenFunc = func; TargetTime = time; Looping = loop; PingPong = pingpong; CurrentTime = 0; CurrentDirection = TweenDirection.Forward; InitialDirection = TweenDirection.Forward; Value = 0f; if (PingPong) { TargetTime /= 2; // If we're pingponging, halve the time so that TargetTime is one complete cycle } }
public Tween Create(string name, TweenFunc func, Action <Tween> callback, double time, bool pingpong, bool loop) { return(Create(name, func, callback, time, pingpong, loop, TweenDirection.Forward)); }
private static float EaseFunc(float t, TweenFunc f) { switch (f) { case TweenFunc.Smoothstep: return(t * t * (3.0f - 2.0f * t)); case TweenFunc.Cosine: return(0.5f - math.cos(t * 3.1415f) * 0.5f); // almost the exact same as smoothstep case TweenFunc.Hardstep: if (t < .5f) { return(0); } return(1.0f); default: case TweenFunc.Linear: return(t); case TweenFunc.InQuad: return(t * t); case TweenFunc.OutQuad: return(t * (2.0f - t)); case TweenFunc.InOutQuad: return(t < .5f ? 2.0f * t * t : -1.0f + (4.0f - 2.0f * t) * t); case TweenFunc.InCubic: return(t * t * t); case TweenFunc.OutCubic: t -= 1.0f; return(t * t * t + 1.0f); case TweenFunc.InOutCubic: return(t < .5f ? 4.0f * t * t * t : (t - 1.0f) * (2.0f * t - 2.0f) * (2.0f * t - 2.0f) + 1.0f); case TweenFunc.InQuart: return(t * t * t * t); case TweenFunc.OutQuart: t -= 1.0f; return(1.0f - t * t * t * t); case TweenFunc.InOutQuart: if (t < .5f) { return(8.0f * t * t * t * t); } t -= 1.0f; return(1.0f - 8.0f * t * t * t * t); case TweenFunc.InQuint: return(t * t * t * t * t); case TweenFunc.OutQuint: t -= 1.0f; return(1.0f + t * t * t * t * t); case TweenFunc.InOutQuint: if (t < .5f) { return(16.0f * t * t * t * t * t); } t -= 1.0f; return(1.0f + 16.0f * t * t * t * t * t); case TweenFunc.InBack: { const float s = 1.70158f; return(t * t * ((s + 1.0f) * t - s)); } case TweenFunc.OutBack: { const float s = 1.70158f; t -= 1.0f; return(t * t * ((s + 1) * t + s) + 1); } case TweenFunc.InOutBack: { const float s = 1.70158f * 1.525f; if ((t *= 2.0f) < 1.0f) { return(0.5f * (t * t * ((s + 1.0f) * t - s))); } t -= 2.0f; return(0.5f * (t * t * ((s + 1.0f) * t + s) + 2.0f)); } case TweenFunc.InBounce: return(InBounce(t)); case TweenFunc.OutBounce: return(OutBounce(t)); case TweenFunc.InOutBounce: t *= 2.0f; if (t < 1.0f) { return(0.5f * InBounce(t)); } return(0.5f * OutBounce(t - 1.0f) + 0.5f); case TweenFunc.InCircle: return(-(math.sqrt(1.0f - t * t) - 1.0f)); case TweenFunc.OutCircle: t -= 1.0f; return(math.sqrt(1.0f - t * t)); case TweenFunc.InOutCircle: t *= 2.0f; if (t < 1.0f) { return(-.5f * (math.sqrt(1.0f - t * t) - 1.0f)); } t -= 2.0f; return(.5f * (math.sqrt(1.0f - t * t) + 1.0f)); case TweenFunc.InExponential: return(math.exp2(10.0f * (t - 1.0f))); case TweenFunc.OutExponential: return(-math.exp2(-10.0f * t) + 1.0f); case TweenFunc.InOutExponential: t *= 2.0f; if (t < 1.0f) { return(.5f * math.exp2(10.0f * (t - 1.0f))); } t -= 1.0f; return(.5f * (-math.exp2(-10.0f * t) + 2.0f)); } }
static IEnumerator DoTween(float start, float end, float time, Action <float> callback, TweenFunc func, Action after) { float t = 0; do { callback(Mathf.Lerp(start, end, func(t / time))); t += Time.deltaTime; yield return(new WaitForEndOfFrame()); } while (t < time); callback(Mathf.Lerp(start, end, 1)); }
public static void Free(float start, float end, float time, Action <float> callback, TweenFunc func) { GameObject obj = new GameObject(); obj.AddComponent <TweenBehaviour>().StartCoroutine(DoTween(start, end, time, callback, func, () => { GameObject.Destroy(obj); })); }
public Tween Create(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop) { return Create(name, func, callback, time, pingpong, loop, TweenDirection.Forward); }
public void To(T to, float duration, Action <Controller <T> > done = null, TweenFunc <T> easing = null) { this.To(_val, to, duration, done); }