/// <summary> /// Start and add a Quaternion tween /// </summary> /// <param name="obj">Game object</param> /// <param name="start">Start value</param> /// <param name="end">End value</param> /// <param name="duration">Duration in seconds</param> /// <param name="scaleFunc">Scale function</param> /// <param name="progress">Progress handler</param> /// <param name="completion">Completion handler</param> /// <returns>QuaternionTween</returns> public static QuaternionTween Tween(this GameObject obj, object key, Quaternion start, Quaternion end, float duration, Func<float, float> scaleFunc, System.Action<ITween<Quaternion>> progress, System.Action<ITween<Quaternion>> completion = null) { QuaternionTween t = TweenFactory.Tween(key, start, end, duration, scaleFunc, progress, completion); t.GameObject = obj; t.Renderer = obj.GetComponent<Renderer>(); return t; }
private void TweenMove() { Vector3 currentPos = Circle.transform.position; Vector3 startPos = Camera.main.ViewportToWorldPoint(Vector3.zero); Vector3 midPos = Camera.main.ViewportToWorldPoint(Vector3.one); Vector3 endPos = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.5f)); currentPos.z = startPos.z = midPos.z = endPos.z = 0.0f; TweenFactory.Tween("MoveCircle", currentPos, startPos, 1.75f, TweenScaleFunctions.CubicEaseIn, (t) => { // progress Circle.gameObject.transform.position = t.CurrentValue; }, (t) => { // completion Tween.TweenFactory.Tween("MoveCircle", startPos, midPos, 1.75f, TweenScaleFunctions.Linear, (t2) => { // progress Circle.gameObject.transform.position = t2.CurrentValue; }, (t2) => { // completion Tween.TweenFactory.Tween("MoveCircle", midPos, endPos, 1.75f, TweenScaleFunctions.CubicEaseOut, (t3) => { // progress Circle.gameObject.transform.position = t3.CurrentValue; }, (t3) => { // completion - nothing more to do! }); }); }); }
/// <summary> /// Stops the tween. /// </summary> /// <param name="stopBehavior">The behavior to use to handle the stop.</param> public void Stop(TweenStopBehavior stopBehavior) { if (state != TweenState.Stopped) { state = TweenState.Stopped; if (stopBehavior == TweenStopBehavior.Complete) { currentTime = duration; UpdateValue(); if (completionCallback != null) { completionCallback.Invoke(this); completionCallback = null; } if (continueWith != null) { continueWith.Start(); #if IS_UNITY TweenFactory.AddTween(continueWith); #else // TODO: Implement your own continueWith handling #endif continueWith = null; } } } }
/// <summary> /// Start and add a Color tween /// </summary> /// <param name="obj">Game object</param> /// <param name="start">Start value</param> /// <param name="end">End value</param> /// <param name="duration">Duration in seconds</param> /// <param name="scaleFunc">Scale function</param> /// <param name="progress">Progress handler</param> /// <param name="completion">Completion handler</param> /// <returns>ColorTween</returns> public static ColorTween Tween(this GameObject obj, object key, Color start, Color end, float duration, Func <float, float> scaleFunc, System.Action <ITween <Color> > progress, System.Action <ITween <Color> > completion = null) { ColorTween t = TweenFactory.Tween(key, start, end, duration, scaleFunc, progress, completion); t.GameObject = obj; t.Renderer = obj.GetComponent <Renderer>(); return(t); }
/// <summary> /// Start and add a Vector4 tween /// </summary> /// <param name="obj">Game object</param> /// <param name="key">Key</param> /// <param name="start">Start value</param> /// <param name="end">End value</param> /// <param name="duration">Duration in seconds</param> /// <param name="scaleFunc">Scale function</param> /// <param name="progress">Progress handler</param> /// <param name="completion">Completion handler</param> /// <returns>Vector4Tween</returns> public static Vector4Tween Tween(this GameObject obj, object key, Vector4 start, Vector4 end, float duration, Func <float, float> scaleFunc, Action <ITween <Vector4> > progress, Action <ITween <Vector4> > completion) { Vector4Tween t = TweenFactory.Tween(key, start, end, duration, scaleFunc, progress, completion); t.GameObject = obj; t.Renderer = obj.GetComponent <Renderer>(); return(t); }
private void TweenColor() { Color endColor = UnityEngine.Random.ColorHSV(0.0f, 1.0f, 0.0f, 1.0f, 0.5f, 1.0f, 1.0f, 1.0f); TweenFactory.Tween("ColorCircle", spriteRenderer.color, endColor, 1.0f, TweenScaleFunctions.QuadraticEaseOut, (t) => { // progress spriteRenderer.color = t.CurrentValue; }, (t) => { // completion }); }
private void TweenRotate() { float startAngle = Circle.transform.rotation.eulerAngles.z; float endAngle = startAngle + 720.0f; TweenFactory.Tween("RotateCircle", startAngle, endAngle, 2.0f, TweenScaleFunctions.CubicEaseInOut, (t) => { // progress Circle.transform.rotation = Quaternion.identity; Circle.transform.Rotate(Camera.main.transform.forward, t.CurrentValue); }, (t) => { // completion }); }
/// <summary> /// Stops the tween. /// </summary> /// <param name="stopBehavior">The behavior to use to handle the stop.</param> public void Stop(TweenStopBehavior stopBehavior) { if (state != TweenState.Stopped) { state = TweenState.Stopped; if (stopBehavior == TweenStopBehavior.Complete) { currentTime = duration; UpdateValue(); if (completionCallback != null) { completionCallback.Invoke(this); completionCallback = null; } if (continueWith != null) { continueWith.Start(); TweenFactory.AddTween(continueWith); continueWith = null; } } } }