diff --git a/Assets/Fungus/Thirdparty/LeanTween.meta b/Assets/Fungus/Thirdparty/LeanTween.meta index ce2c33d4..0bc313d3 100644 --- a/Assets/Fungus/Thirdparty/LeanTween.meta +++ b/Assets/Fungus/Thirdparty/LeanTween.meta @@ -1,5 +1,2 @@ fileFormatVersion: 2 guid: 5e6a0fa47acf54892bbdae89028eaec3 -folderAsset: yes -DefaultImporter: - userData: diff --git a/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs b/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs index b1f05b10..7a6478a7 100644 --- a/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs +++ b/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs @@ -1,6 +1,6 @@ -// Copyright (c) 2014 Russell Savage - Dented Pixel +// Copyright (c) 2015 Russell Savage - Dented Pixel // -// LeanTween version 2.21 - http://dentedpixel.com/developer-diary/ +// LeanTween version 2.30 - http://dentedpixel.com/developer-diary/ // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -139,188 +139,180 @@ using UnityEngine; using System.Collections; using System; using System.Runtime.InteropServices; +using System.Collections.Generic; -public class LeanTest : object { - public static int expected = 0; - private static int tests = 0; - private static int passes = 0; - - public static void debug( string name, bool didPass, string failExplaination = null){ - float len = printOutLength(name); - int paddingLen = 40-(int)(len*1.05f); - #if UNITY_FLASH - string padding = padRight(paddingLen); - #else - string padding = "".PadRight(paddingLen,"_"[0]); - #endif - string logName = formatB(name) +" " + padding + " [ "+ (didPass ? formatC("pass","green") : formatC("fail","red")) +" ]"; - if(didPass==false && failExplaination!=null) - logName += " - " + failExplaination; - Debug.Log(logName); - if(didPass) - passes++; - tests++; - - if(tests==expected){ - Debug.Log(formatB("Final Report:")+" _____________________ PASSED: "+formatBC(""+passes,"green")+" FAILED: "+formatBC(""+(tests-passes),"red")+" "); - }else if(tests>expected){ - Debug.Log(formatB("Too many tests for a final report!") + " set LeanTest.expected = "+tests); - } - } - - public static string padRight(int len){ - string str = ""; - for(int i = 0; i < len; i++){ - str += "_"; - } - return str; - } - - public static float printOutLength( string str ){ - float len = 0.0f; - for(int i = 0; i < str.Length; i++){ - if(str[i]=="I"[0]){ - len += 0.5f; - }else if(str[i]=="J"[0]){ - len += 0.85f; - }else{ - len += 1.0f; - } - } - return len; - } - - public static string formatBC( string str, string color ){ - return formatC(formatB(str),color); - } - - public static string formatB( string str ){ - #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 - return str; - #else - return ""+ str + ""; - #endif - } - - public static string formatC( string str, string color ){ - #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 - return str; - #else - return ""+ str + ""; - #endif - } - - public static void overview(){ +public enum TweenAction{ + MOVE_X, + MOVE_Y, + MOVE_Z, + MOVE_LOCAL_X, + MOVE_LOCAL_Y, + MOVE_LOCAL_Z, + MOVE_CURVED, + MOVE_CURVED_LOCAL, + MOVE_SPLINE, + MOVE_SPLINE_LOCAL, + SCALE_X, + SCALE_Y, + SCALE_Z, + ROTATE_X, + ROTATE_Y, + ROTATE_Z, + ROTATE_AROUND, + ROTATE_AROUND_LOCAL, + CANVAS_ROTATEAROUND, + CANVAS_ROTATEAROUND_LOCAL, + CANVAS_PLAYSPRITE, + ALPHA, + TEXT_ALPHA, + CANVAS_ALPHA, + ALPHA_VERTEX, + COLOR, + CALLBACK_COLOR, + TEXT_COLOR, + CANVAS_COLOR, + CANVAS_MOVE_X, + CANVAS_MOVE_Y, + CANVAS_MOVE_Z, + CALLBACK, + MOVE, + MOVE_LOCAL, + ROTATE, + ROTATE_LOCAL, + SCALE, + VALUE3, + GUI_MOVE, + GUI_MOVE_MARGIN, + GUI_SCALE, + GUI_ALPHA, + GUI_ROTATE, + DELAYED_SOUND, + CANVAS_MOVE, + CANVAS_SCALE, +} - } +public enum LeanTweenType{ + notUsed, linear, easeOutQuad, easeInQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, + easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, + easeInBounce, easeOutBounce, easeInOutBounce, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeSpring, easeShake, punch, once, clamp, pingPong, animationCurve } /** -* Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method

-* Example Javascript:
var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
-* LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );
-* function OnGUI(){
-*   if(GUI.Button(bRect.rect, "Scale")){ }
-* }
+* Internal Representation of a Tween
*
-* Example C#:
-* LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
-* LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f );
-* void OnGUI(){
-*   if(GUI.Button(bRect.rect, "Scale")){ }
-* }
-* -* @class LTRect +* This class represents all of the optional parameters you can pass to a method (it also represents the internal representation of the tween).

+* Optional Parameters are passed at the end of every method:
+*
+*   Example:
+*   LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
+*
+* You can pass the optional parameters in any order, and chain on as many as you wish.
+* You can also pass parameters at a later time by saving a reference to what is returned.
+*
+* Retrieve a unique id for the tween by using the "id" property. You can pass this to LeanTween.pause, LeanTween.resume, LeanTween.cancel, LeanTween.isTweening methods
+*
+*   

Example:

+*   int id = LeanTween.moveX(gameObject, 1f, 3f).id;
+*
  // pause a specific tween
+*   LeanTween.pause(id);
+*
  // resume later
+*   LeanTween.resume(id);
+*
  // check if it is tweening before kicking of a new tween
+*   if( LeanTween.isTweening( id ) ){
+*       LeanTween.cancel( id );
+*       LeanTween.moveZ(gameObject, 10f, 3f);
+*   }
+* @class LTDescr * @constructor -* @param {float} x:float X location -* @param {float} y:float Y location -* @param {float} width:float Width -* @param {float} height:float Height -* @param {float} alpha:float (Optional) initial alpha amount (0-1) -* @param {float} rotation:float (Optional) initial rotation in degrees (0-360) */ -[System.Serializable] -public class LTRect : System.Object{ - /** - * Pass this value to the GUI Methods - * - * @property rect - * @type {Rect} rect:Rect Rect object that controls the positioning and size - */ - public Rect _rect; - public float alpha = 1f; - public float rotation; - public Vector2 pivot; - public Vector2 margin; - public Rect relativeRect = new Rect(0f,0f,float.PositiveInfinity,float.PositiveInfinity); - - public bool rotateEnabled; - [HideInInspector] - public bool rotateFinished; - public bool alphaEnabled; - public string labelStr; - public LTGUI.Element_Type type; - public GUIStyle style; - public bool useColor = false; - public Color color = Color.white; - public bool fontScaleToFit; - public bool useSimpleScale; - public bool sizeByHeight; - - public Texture texture; - - private int _id = -1; - [HideInInspector] - public int counter; +public class LTDescr { + public bool toggle; + public bool useEstimatedTime; + public bool useFrames; + public bool useManualTime; + public bool hasInitiliazed; + public bool hasPhysics; + public bool onCompleteOnRepeat; + public bool onCompleteOnStart; + public float passed; + public float delay; + public float time; + public float lastVal; + private uint _id; + public int loopCount; + public uint counter; + public float direction; + public float directionLast; + public float overshoot; + public float period; + public bool destroyOnComplete; + public Transform trans; + public LTRect ltRect; + public Vector3 from; + public Vector3 to; + public Vector3 diff; + public Vector3 point; + public Vector3 axis; + public Quaternion origRotation; + public LTBezierPath path; + public LTSpline spline; + public TweenAction type; + public LeanTweenType tweenType; + public AnimationCurve animationCurve; + public LeanTweenType loopType; + public bool hasUpdateCallback; + public Action onUpdateFloat; + public Action onUpdateFloatRatio; + public Action onUpdateFloatObject; + public Action onUpdateVector2; + public Action onUpdateVector3; + public Action onUpdateVector3Object; + public Action onUpdateColor; + public Action onComplete; + public Action onCompleteObject; + public object onCompleteParam; + public object onUpdateParam; + public Action onStart; - public static bool colorTouched; + #if LEANTWEEN_1 + public Hashtable optional; + #endif + #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 + public RectTransform rectTransform; + public UnityEngine.UI.Text uiText; + public UnityEngine.UI.Image uiImage; + public UnityEngine.Sprite[] sprites; + #endif - public LTRect(){ - reset(); - this.rotateEnabled = this.alphaEnabled = true; - _rect = new Rect(0f,0f,1f,1f); - } + private static uint global_counter = 0; - public LTRect(Rect rect){ - _rect = rect; - reset(); + public override string ToString(){ + return (trans!=null ? "gameObject:"+trans.gameObject : "gameObject:null")+" toggle:"+toggle+" passed:"+passed+" time:"+time+" delay:"+delay+" direction:"+direction+" from:"+from+" to:"+to+" type:"+type+" ease:"+tweenType+" useEstimatedTime:"+useEstimatedTime+" id:"+id+" hasInitiliazed:"+hasInitiliazed; } - public LTRect(float x, float y, float width, float height){ - _rect = new Rect(x,y,width,height); - this.alpha = 1.0f; - this.rotation = 0.0f; - this.rotateEnabled = this.alphaEnabled = false; - } + public LTDescr(){ - public LTRect(float x, float y, float width, float height, float alpha){ - _rect = new Rect(x,y,width,height); - this.alpha = alpha; - this.rotation = 0.0f; - this.rotateEnabled = this.alphaEnabled = false; } - public LTRect(float x, float y, float width, float height, float alpha, float rotation){ - _rect = new Rect(x,y,width,height); - this.alpha = alpha; - this.rotation = rotation; - this.rotateEnabled = this.alphaEnabled = false; - if(rotation!=0.0f){ - this.rotateEnabled = true; - resetForRotation(); - } + [System.Obsolete("Use 'LeanTween.cancel( id )' instead")] + public LTDescr cancel( GameObject gameObject ){ + // Debug.Log("canceling id:"+this._id+" this.uniqueId:"+this.uniqueId+" go:"+this.trans.gameObject); + if(gameObject==this.trans.gameObject) + LeanTween.removeTween((int)this._id, this.uniqueId); + return this; } - public bool hasInitiliazed{ - get{ - return _id!=-1; - } - } + /*[System.Obsolete("Use 'LeanTween.cancel( id )' instead")] + public LTDescr cancel(){ + // Debug.Log("canceling id:"+this._id+" this.uniqueId:"+this.uniqueId+" go:"+this.trans.gameObject); + LeanTween.removeTween((int)this._id); + return this; + }*/ - public int id{ + public int uniqueId{ get{ - int toId = _id | counter << 16; + uint toId = _id | counter << 16; /*uint backId = toId & 0xFFFF; uint backCounter = toId >> 16; @@ -328,1471 +320,990 @@ public class LTRect : System.Object{ Debug.LogError("BAD CONVERSION toId:"+_id); }*/ - return toId; + return (int)toId; } - } - - public void setId( int id, int counter){ - this._id = id; - this.counter = counter; } - public void reset(){ - this.alpha = 1.0f; - this.rotation = 0.0f; - this.rotateEnabled = this.alphaEnabled = false; - this.margin = Vector2.zero; - this.sizeByHeight = false; - this.useColor = false; + public int id{ + get{ + return uniqueId; + } } - public void resetForRotation(){ - Vector3 scale = new Vector3(GUI.matrix[0,0], GUI.matrix[1,1], GUI.matrix[2,2]); - if(pivot==Vector2.zero){ - pivot = new Vector2((_rect.x+((_rect.width)*0.5f )) * scale.x + GUI.matrix[0,3], (_rect.y+((_rect.height)*0.5f )) * scale.y + GUI.matrix[1,3]); - } - } - - public float x{ - get{ return _rect.x; } - set{ _rect.x = value; } - } - - public float y{ - get{ return _rect.y; } - set{ _rect.y = value; } + public void reset(){ + this.toggle = true; + #if LEANTWEEN_1 + this.optional = null; + #endif + this.trans = null; + this.passed = this.delay = this.lastVal = 0.0f; + this.hasUpdateCallback = this.useEstimatedTime = this.useFrames = this.hasInitiliazed = this.onCompleteOnRepeat = this.destroyOnComplete = this.onCompleteOnStart = this.useManualTime = false; + this.animationCurve = null; + this.tweenType = LeanTweenType.linear; + this.loopType = LeanTweenType.once; + this.loopCount = 0; + this.direction = this.directionLast = this.overshoot = 1.0f; + this.period = 0.3f; + this.point = Vector3.zero; + cleanup(); + + global_counter++; + if(global_counter>0x8000) + global_counter = 0; } - public float width{ - get{ return _rect.width; } - set{ _rect.width = value; } + public void cleanup(){ + this.onUpdateFloat = null; + this.onUpdateFloatRatio = null; + this.onUpdateVector2 = null; + this.onUpdateVector3 = null; + this.onUpdateFloatObject = null; + this.onUpdateVector3Object = null; + this.onUpdateColor = null; + this.onComplete = null; + this.onCompleteObject = null; + this.onCompleteParam = null; + this.onStart = null; + + #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 + this.rectTransform = null; + this.uiText = null; + this.uiImage = null; + this.sprites = null; + #endif } - public float height{ - get{ return _rect.height; } - set{ _rect.height = value; } - } + // This method is only for internal use + public void init(){ + this.hasInitiliazed = true; - public Rect rect{ + if (this.onStart != null){ + this.onStart(); + } - get{ - if(colorTouched){ - colorTouched = false; - GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,1.0f); - } - if(rotateEnabled){ - if(rotateFinished){ - rotateFinished = false; - rotateEnabled = false; - //this.rotation = 0.0f; - pivot = Vector2.zero; - }else{ - GUIUtility.RotateAroundPivot(rotation, pivot); - } - } - if(alphaEnabled){ - GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,alpha); - colorTouched = true; - } - if(fontScaleToFit){ - if(this.useSimpleScale){ - style.fontSize = (int)(_rect.height*this.relativeRect.height); - }else{ - style.fontSize = (int)_rect.height; + // Initialize From Values + switch(this.type){ + case TweenAction.MOVE: + this.from = trans.position; break; + case TweenAction.MOVE_X: + this.from.x = trans.position.x; break; + case TweenAction.MOVE_Y: + this.from.x = trans.position.y; break; + case TweenAction.MOVE_Z: + this.from.x = trans.position.z; break; + case TweenAction.MOVE_LOCAL_X: + this.from.x = trans.localPosition.x; break; + case TweenAction.MOVE_LOCAL_Y: + this.from.x = trans.localPosition.y; break; + case TweenAction.MOVE_LOCAL_Z: + this.from.x = trans.localPosition.z; break; + case TweenAction.SCALE_X: + this.from.x = trans.localScale.x; break; + case TweenAction.SCALE_Y: + this.from.x = trans.localScale.y; break; + case TweenAction.SCALE_Z: + this.from.x = trans.localScale.z; break; + case TweenAction.ALPHA: + #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 + if(trans.gameObject.renderer){ + this.from.x = trans.gameObject.renderer.material.color.a; + }else if(trans.childCount>0){ + foreach (Transform child in trans) { + if(child.gameObject.renderer!=null){ + Color col = child.gameObject.renderer.material.color; + this.from.x = col.a; + break; + } + } + } + break; + #else + SpriteRenderer ren = trans.gameObject.GetComponent(); + if(ren!=null){ + this.from.x = ren.color.a; + }else{ + if(trans.gameObject.GetComponent()!=null && trans.gameObject.GetComponent().material.HasProperty("_Color")){ + this.from.x = trans.gameObject.GetComponent().material.color.a; + }else if(trans.gameObject.GetComponent()!=null && trans.gameObject.GetComponent().material.HasProperty("_TintColor")){ + Color col = trans.gameObject.GetComponent().material.GetColor("_TintColor"); + this.from.x = col.a; + }else if(trans.childCount>0){ + foreach (Transform child in trans) { + if(child.gameObject.GetComponent()!=null){ + Color col = child.gameObject.GetComponent().material.color; + this.from.x = col.a; + break; + } + } + } + } + break; + #endif + case TweenAction.MOVE_LOCAL: + this.from = trans.localPosition; break; + case TweenAction.MOVE_CURVED: + case TweenAction.MOVE_CURVED_LOCAL: + case TweenAction.MOVE_SPLINE: + case TweenAction.MOVE_SPLINE_LOCAL: + this.from.x = 0; break; + case TweenAction.ROTATE: + this.from = trans.eulerAngles; + this.to = new Vector3(LeanTween.closestRot( this.from.x, this.to.x), LeanTween.closestRot( this.from.y, this.to.y), LeanTween.closestRot( this.from.z, this.to.z)); + break; + case TweenAction.ROTATE_X: + this.from.x = trans.eulerAngles.x; + this.to.x = LeanTween.closestRot( this.from.x, this.to.x); + break; + case TweenAction.ROTATE_Y: + this.from.x = trans.eulerAngles.y; + this.to.x = LeanTween.closestRot( this.from.x, this.to.x); + break; + case TweenAction.ROTATE_Z: + this.from.x = trans.eulerAngles.z; + this.to.x = LeanTween.closestRot( this.from.x, this.to.x); + break; + case TweenAction.ROTATE_AROUND: + this.lastVal = 0.0f; // optional["last"] + this.from.x = 0.0f; + this.origRotation = trans.rotation; // optional["origRotation" + break; + case TweenAction.ROTATE_AROUND_LOCAL: + this.lastVal = 0.0f; // optional["last"] + this.from.x = 0.0f; + this.origRotation = trans.localRotation; // optional["origRotation" + break; + case TweenAction.ROTATE_LOCAL: + this.from = trans.localEulerAngles; + this.to = new Vector3(LeanTween.closestRot( this.from.x, this.to.x), LeanTween.closestRot( this.from.y, this.to.y), LeanTween.closestRot( this.from.z, this.to.z)); + break; + case TweenAction.SCALE: + this.from = trans.localScale; break; + case TweenAction.GUI_MOVE: + this.from = new Vector3(this.ltRect.rect.x, this.ltRect.rect.y, 0); break; + case TweenAction.GUI_MOVE_MARGIN: + this.from = new Vector2(this.ltRect.margin.x, this.ltRect.margin.y); break; + case TweenAction.GUI_SCALE: + this.from = new Vector3(this.ltRect.rect.width, this.ltRect.rect.height, 0); break; + case TweenAction.GUI_ALPHA: + this.from.x = this.ltRect.alpha; break; + case TweenAction.GUI_ROTATE: + if(this.ltRect.rotateEnabled==false){ + this.ltRect.rotateEnabled = true; + this.ltRect.resetForRotation(); } + + this.from.x = this.ltRect.rotation; break; + case TweenAction.ALPHA_VERTEX: + this.from.x = trans.GetComponent().mesh.colors32[0].a; + break; + case TweenAction.CALLBACK: + break; + case TweenAction.CALLBACK_COLOR: + this.diff = new Vector3(1.0f,0.0f,0.0f); + break; + case TweenAction.COLOR: + #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 + if(trans.gameObject.renderer){ + Color col = trans.gameObject.renderer.material.color; + this.setFromColor( col ); + }else if(trans.childCount>0){ + foreach (Transform child in trans) { + if(child.gameObject.renderer!=null){ + Color col = child.gameObject.renderer.material.color; + this.setFromColor( col ); + break; + } + } + } + #else + SpriteRenderer renColor = trans.gameObject.GetComponent(); + if(renColor!=null){ + Color col = renColor.color; + this.setFromColor( col ); + }else{ + if(trans.gameObject.GetComponent()!=null && trans.gameObject.GetComponent().material.HasProperty("_Color")){ + Color col = trans.gameObject.GetComponent().material.color; + this.setFromColor( col ); + }else if(trans.gameObject.GetComponent()!=null && trans.gameObject.GetComponent().material.HasProperty("_TintColor")){ + Color col = trans.gameObject.GetComponent().material.GetColor ("_TintColor"); + this.setFromColor( col ); + }else if(trans.childCount>0){ + foreach (Transform child in trans) { + if(child.gameObject.GetComponent()!=null){ + Color col = child.gameObject.GetComponent().material.color; + this.setFromColor( col ); + break; + } + } + } + } + #endif + break; + #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 + case TweenAction.CANVAS_ALPHA: + this.uiImage = trans.gameObject.GetComponent(); + if(this.uiImage != null) + this.from.x = this.uiImage.color.a; + break; + case TweenAction.CANVAS_COLOR: + this.uiImage = trans.gameObject.GetComponent(); + if(this.uiImage != null) + this.setFromColor( this.uiImage.color ); + break; + case TweenAction.TEXT_ALPHA: + this.uiText = trans.gameObject.GetComponent(); + if (this.uiText != null) + this.from.x = this.uiText.color.a; + break; + case TweenAction.TEXT_COLOR: + this.uiText = trans.gameObject.GetComponent(); + if (this.uiText != null) + this.setFromColor( this.uiText.color ); + break; + case TweenAction.CANVAS_MOVE: + this.from = this.rectTransform.anchoredPosition3D; break; + case TweenAction.CANVAS_MOVE_X: + this.from.x = this.rectTransform.anchoredPosition3D.x; break; + case TweenAction.CANVAS_MOVE_Y: + this.from.x = this.rectTransform.anchoredPosition3D.y; break; + case TweenAction.CANVAS_MOVE_Z: + this.from.x = this.rectTransform.anchoredPosition3D.z; break; + case TweenAction.CANVAS_ROTATEAROUND: + case TweenAction.CANVAS_ROTATEAROUND_LOCAL: + this.lastVal = 0.0f; + this.from.x = 0.0f; + this.origRotation = this.rectTransform.rotation; + break; + case TweenAction.CANVAS_SCALE: + this.from = this.rectTransform.localScale; break; + case TweenAction.CANVAS_PLAYSPRITE: + this.uiImage = trans.gameObject.GetComponent(); + this.from.x = 0f; + break; + #endif + } + if(this.type!=TweenAction.CALLBACK_COLOR && this.type!=TweenAction.COLOR && this.type!=TweenAction.TEXT_COLOR && this.type!=TweenAction.CANVAS_COLOR) + this.diff = this.to - this.from; + if(this.onCompleteOnStart){ + if(this.onComplete!=null){ + this.onComplete(); + }else if(this.onCompleteObject!=null){ + this.onCompleteObject(this.onCompleteParam); } - return _rect; } - - set{ - _rect = value; - } } - public LTRect setStyle( GUIStyle style ){ - this.style = style; + public LTDescr setFromColor( Color col ){ + this.from = new Vector3(0.0f, col.a, 0.0f); + this.diff = new Vector3(1.0f,0.0f,0.0f); + this.axis = new Vector3( col.r, col.g, col.b ); return this; } - public LTRect setFontScaleToFit( bool fontScaleToFit ){ - this.fontScaleToFit = fontScaleToFit; - return this; + /** + * Pause a tween + * + * @method pause + * @return {LTDescr} LTDescr an object that distinguishes the tween + */ + public LTDescr pause(){ + if(this.direction != 0.0f){ // check if tween is already paused + this.directionLast = this.direction; + this.direction = 0.0f; + } + + return this; } - public LTRect setColor( Color color ){ - this.color = color; - this.useColor = true; + /** + * Resume a paused tween + * + * @method resume + * @return {LTDescr} LTDescr an object that distinguishes the tween + */ + public LTDescr resume(){ + this.direction = this.directionLast; return this; } - public LTRect setAlpha( float alpha ){ - this.alpha = alpha; + public LTDescr setAxis( Vector3 axis ){ + this.axis = axis; return this; } - - public LTRect setLabel( String str ){ - this.labelStr = str; + + /** + * Delay the start of a tween + * + * @method setDelay + * @param {float} float time The time to complete the tween in + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setDelay( 1.5f ); + */ + public LTDescr setDelay( float delay ){ + if(this.useEstimatedTime){ + this.delay = delay; + }else{ + this.delay = delay;//*Time.timeScale; + } + return this; } - public LTRect setUseSimpleScale( bool useSimpleScale, Rect relativeRect){ - this.useSimpleScale = useSimpleScale; - this.relativeRect = relativeRect; + /** + * Set the type of easing used for the tween.
+ * + * + * @method setEase + * @param {LeanTweenType} easeType:LeanTweenType the easing type to use + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce ); + */ + public LTDescr setEase( LeanTweenType easeType ){ + this.tweenType = easeType; return this; } - public LTRect setUseSimpleScale( bool useSimpleScale){ - this.useSimpleScale = useSimpleScale; - this.relativeRect = new Rect(0f,0f,Screen.width,Screen.height); + /** + * Set how far past a tween will overshoot for certain ease types (compatible: easeInBack, easeInOutBack, easeOutBack, easeOutElastic, easeInElastic, easeInOutElastic).
+ * @method setOvershoot + * @param {float} overshoot:float how far past the destination it will go before settling in + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutBack ).setOvershoot(2f); + */ + public LTDescr setOvershoot( float overshoot ){ + this.overshoot = overshoot; return this; } - public LTRect setSizeByHeight( bool sizeByHeight){ - this.sizeByHeight = sizeByHeight; + /** + * Set how short the iterations are for certain ease types (compatible: easeOutElastic, easeInElastic, easeInOutElastic).
+ * @method setPeriod + * @param {float} period:float how short the iterations are that the tween will animate at (default 0.3f) + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutElastic ).setPeriod(0.3f); + */ + public LTDescr setPeriod( float period ){ + this.period = period; return this; } - public override string ToString(){ - return "x:"+_rect.x+" y:"+_rect.y+" width:"+_rect.width+" height:"+_rect.height; + /** + * Set the type of easing used for the tween with a custom curve.
+ * @method setEase (AnimationCurve) + * @param {AnimationCurve} easeDefinition:AnimationCurve an AnimationCure that describes the type of easing you want, this is great for when you want a unique type of movement + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce ); + */ + public LTDescr setEase( AnimationCurve easeCurve ){ + this.animationCurve = easeCurve; + return this; } -} - -public class LTBezier{ - public float length; - - private Vector3 a; - private Vector3 aa; - private Vector3 bb; - private Vector3 cc; - private float len; - private float[] arcLengths; - - public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision){ - this.a = a; - aa = (-a + 3*(b-c) + d); - bb = 3*(a+c) - 6*b; - cc = 3*(b-a); - - this.len = 1.0f / precision; - arcLengths = new float[(int)this.len + (int)1]; - arcLengths[0] = 0; - Vector3 ov = a; - Vector3 v; - float clen = 0.0f; - for(int i = 1; i <= this.len; i++) { - v = bezierPoint(i * precision); - clen += (ov - v).magnitude; - this.arcLengths[i] = clen; - ov = v; - } - this.length = clen; + /** + * Set the end that the GameObject is tweening towards + * @method setTo + * @param {Vector3} to:Vector3 point at which you want the tween to reach + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setEase( LeanTweenType.easeInOutBounce );
+ * // Later your want to change your destination or your destiation is constantly moving
+ * descr.setTo( new Vector3(5f,10f,3f); );
+ */ + public LTDescr setTo( Vector3 to ){ + if(this.hasInitiliazed){ + this.to = to; + this.diff = to - this.from; + }else{ + this.to = to; + } + + return this; } - private float map(float u) { - float targetLength = u * this.arcLengths[(int)this.len]; - int low = 0; - int high = (int)this.len; - int index = 0; - while (low < high) { - index = low + ((int)((high - low) / 2.0f) | 0); - if (this.arcLengths[index] < targetLength) { - low = index + 1; - } else { - high = index; - } - } - if(this.arcLengths[index] > targetLength) - index--; - if(index<0) - index = 0; - - return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len; - } - - private Vector3 bezierPoint(float t){ - return ((aa* t + (bb))* t + cc)* t + a; + public LTDescr setFrom( Vector3 from ){ + if(this.trans) + this.init(); + this.from = from; + // this.hasInitiliazed = true; // this is set, so that the "from" value isn't overwritten later on when the tween starts + this.diff = this.to - this.from; + return this; } - public Vector3 point(float t){ - return bezierPoint( map(t) ); - } -} - -/** -* Manually animate along a bezier path with this class -* @class LTBezierPath -* @constructor -* @param {Vector3 Array} pts A set of points that define one or many bezier paths (the paths should be passed in multiples of 4, which correspond to each individual bezier curve) -* @example -* LTBezierPath ltPath = new LTBezierPath( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(1f,0f,0f), new Vector3(1f,0f,0f), new Vector3(1f,1f,0f)} );

-* LeanTween.move(lt, ltPath.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
-* Vector3 pt = ltPath.point( 0.6f ); // retrieve a point along the path -*/ -public class LTBezierPath{ - public Vector3[] pts; - public float length; - public bool orientToPath; - public bool orientToPath2d; - - private LTBezier[] beziers; - private float[] lengthRatio; + public LTDescr setFrom( float from ){ + return setFrom( new Vector3(from, 0f, 0f) ); + } - public LTBezierPath(){ } - public LTBezierPath( Vector3[] pts_ ){ - setPoints( pts_ ); + public LTDescr setDiff( Vector3 diff ){ + this.diff = diff; + return this; } - public void setPoints( Vector3[] pts_ ){ - if(pts_.Length<4) - LeanTween.logError( "LeanTween - When passing values for a vector path, you must pass four or more values!" ); - if(pts_.Length%4!=0) - LeanTween.logError( "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..." ); + public LTDescr setHasInitialized( bool has ){ + this.hasInitiliazed = has; + return this; + } - pts = pts_; - - int k = 0; - beziers = new LTBezier[ pts.Length / 4 ]; - lengthRatio = new float[ beziers.Length ]; - int i; - length = 0; - for(i = 0; i < pts.Length; i+=4){ - beziers[k] = new LTBezier(pts[i+0],pts[i+2],pts[i+1],pts[i+3],0.05f); - length += beziers[k].length; - k++; - } - // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers); - for(i = 0; i < beziers.Length; i++){ - lengthRatio[i] = beziers[i].length / length; - } + public LTDescr setId( uint id ){ + this._id = id; + this.counter = global_counter; + // Debug.Log("Global counter:"+global_counter); + return this; } /** - * Retrieve a point along a path - * - * @method point - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) - * @return {Vector3} Vector3 position of the point along the path + * Set the finish time of the tween + * @method setTime + * @param {float} finishTime:float the length of time in seconds you wish the tween to complete in + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * transform.position = ltPath.point( 0.6f ); + * int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;
+ * // Later
+ * LTDescr descr = description( tweenId );
+ * descr.setTime( 1f );
*/ - public Vector3 point( float ratio ){ - float added = 0.0f; - for(int i = 0; i < lengthRatio.Length; i++){ - added += lengthRatio[i]; - if(added >= ratio) - return beziers[i].point( (ratio-(added-lengthRatio[i])) / lengthRatio[i] ); - } - return beziers[lengthRatio.Length-1].point( 1.0f ); + public LTDescr setTime( float time ){ + this.time = time; + return this; } - public void place2d( Transform transform, float ratio ){ - transform.position = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f){ - float angle = Vector3.Angle(transform.position, point( ratio ) - transform.position ); - transform.rotation = Quaternion.identity; - transform.RotateAround(transform.position, Vector3.up, 90.0f); - transform.RotateAround(transform.position, Vector3.right, angle); + /** + * Set the tween to repeat a number of times. + * @method setRepeat + * @param {int} repeatNum:int the number of times to repeat the tween. -1 to repeat infinite times + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 10 ).setLoopPingPong(); + */ + public LTDescr setRepeat( int repeat ){ + this.loopCount = repeat; + if((repeat>1 && this.loopType == LeanTweenType.once) || (repeat < 0 && this.loopType == LeanTweenType.once)){ + this.loopType = LeanTweenType.clamp; } + if(this.type==TweenAction.CALLBACK || this.type==TweenAction.CALLBACK_COLOR){ + this.setOnCompleteOnRepeat(true); + } + return this; } - public void placeLocal2d( Transform transform, float ratio ){ - transform.localPosition = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f){ - float angle = Vector3.Angle(transform.localPosition, transform.parent.TransformPoint( point( ratio ) ) - transform.localPosition ); - transform.rotation = Quaternion.identity; - transform.RotateAround(transform.position, Vector3.up, 90.0f); - transform.RotateAround(transform.position, Vector3.right, angle); - } + public LTDescr setLoopType( LeanTweenType loopType ){ + this.loopType = loopType; + return this; } - /** - * Place an object along a certain point on the path (facing the direction perpendicular to the path) - * - * @method place - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + public LTDescr setUseEstimatedTime( bool useEstimatedTime ){ + this.useEstimatedTime = useEstimatedTime; + return this; + } + + /** + * Set ignore time scale when tweening an object when you want the animation to be time-scale independent (ignores the Time.timeScale value). Great for pause screens, when you want all other action to be stopped (or slowed down) + * @method setIgnoreTimeScale + * @param {bool} useUnScaledTime:bool whether to use the unscaled time or not + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.place( transform, 0.6f ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setIgnoreTimeScale( true ); */ - public void place( Transform transform, float ratio ){ - place( transform, ratio, Vector3.up ); + public LTDescr setIgnoreTimeScale( bool useUnScaledTime ){ + this.useEstimatedTime = useUnScaledTime; + return this; } /** - * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - * - * @method place - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) - * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * Use frames when tweening an object, when you don't want the animation to be time-frame independent... + * @method setUseFrames + * @param {bool} useFrames:bool whether to use estimated time or not + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.place( transform, 0.6f, Vector3.left ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseFrames( true ); */ - public void place( Transform transform, float ratio, Vector3 worldUp ){ - transform.position = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f) - transform.LookAt( point( ratio ), worldUp ); + public LTDescr setUseFrames( bool useFrames ){ + this.useFrames = useFrames; + return this; + } + + public LTDescr setUseManualTime( bool useManualTime ){ + this.useManualTime = useManualTime; + return this; + } + + public LTDescr setLoopCount( int loopCount ){ + this.loopCount = loopCount; + return this; } /** - * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space - * - * @method placeLocal - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * No looping involved, just run once (the default) + * @method setLoopOnce + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.placeLocal( transform, 0.6f ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopOnce(); */ - public void placeLocal( Transform transform, float ratio ){ - placeLocal( transform, ratio, Vector3.up ); - } + public LTDescr setLoopOnce(){ this.loopType = LeanTweenType.once; return this; } /** - * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space - * - * @method placeLocal - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) - * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * When the animation gets to the end it starts back at where it began + * @method setLoopClamp + * @param {int} loops:int (defaults to -1) how many times you want the loop to happen (-1 for an infinite number of times) + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.placeLocal( transform, 0.6f, Vector3.left ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopClamp( 2 ); */ - public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){ - transform.localPosition = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f) - transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp ); - } -} - -/** -* Animate along a set of points that need to be in the format: controlPoint, point1, point2.... pointLast, endControlPoint -* @class LTSpline -* @constructor -* @param {Vector3 Array} pts A set of points that define the points the path will pass through (starting with starting control point, and ending with a control point) -* @example -* LTSpline ltSpline = new LTSpline( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(0f,0f,0f), new Vector3(0f,0.5f,0f), new Vector3(1f,1f,0f), new Vector3(1f,1f,0f)} );

-* LeanTween.moveSpline(lt, ltSpline.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
-* Vector3 pt = ltSpline.point( 0.6f ); // retrieve a point along the path -*/ -[System.Serializable] -public class LTSpline { - public Vector3[] pts; - public bool orientToPath; - public bool orientToPath2d; - private float[] lengthRatio; - private float[] lengths; - private int numSections; - private int currPt; - private float totalLength; - - public LTSpline(params Vector3[] pts) { - this.pts = new Vector3[pts.Length]; - System.Array.Copy(pts, this.pts, pts.Length); - - numSections = pts.Length - 3; - int precision = 20; - lengthRatio = new float[precision]; - lengths = new float[precision]; - - Vector3 lastPoint = new Vector3(Mathf.Infinity,0,0); - - totalLength = 0f; - for(int i = 0; i < precision; i++){ - //Debug.Log("i:"+i); - float fract = (i*1f) / precision; - Vector3 point = interp( fract ); - - if(i>=1){ - lengths[ i ] = (point - lastPoint).magnitude; - // Debug.Log("fract:"+fract+" mag:"+lengths[ i ] + " i:"+i); - } - totalLength += lengths[ i ]; - - lastPoint = point; - } - - float ratioTotal = 0f; - for(int i = 0; i < lengths.Length; i++){ - float t = i *1f / (lengths.Length-1); - currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1); - - float ratioLength = lengths[i] / totalLength; - ratioTotal += ratioLength; - lengthRatio[i] = ratioTotal; - - //Debug.Log("lengthRatio["+i+"]:"+lengthRatio[i]+" lengths["+i+"]:"+lengths[i] + " t:"+t); - } - } - - public float map( float t ){ - //Debug.Log("map t:"+t); - for(int i = 0; i < lengthRatio.Length; i++){ - if(lengthRatio[i] >= t){ - // Debug.Log("map lengthRatio["+i+"]:"+lengthRatio[i]); - return lengthRatio[i]+(t-lengthRatio[i]); - } - } - return 1f; + public LTDescr setLoopClamp(){ + this.loopType = LeanTweenType.clamp; + if(this.loopCount==0) + this.loopCount = -1; + return this; } - - public Vector3 interp(float t) { - // The adjustments done to numSections, I am not sure why I needed to add them - /*int numSections = this.numSections+1; - if(numSections>=3) - numSections += 1;*/ - currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1); - float u = t * (float) numSections - (float) currPt; - - // Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length ); - Vector3 a = pts[currPt]; - Vector3 b = pts[currPt + 1]; - Vector3 c = pts[currPt + 2]; - Vector3 d = pts[currPt + 3]; - - return .5f * ( - (-a + 3f * b - 3f * c + d) * (u * u * u) - + (2f * a - 5f * b + 4f * c - d) * (u * u) - + (-a + c) * u - + 2f * b - ); + public LTDescr setLoopClamp( int loops ){ + this.loopCount = loops; + return this; } /** - * Retrieve a point along a path - * - * @method point - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) - * @return {Vector3} Vector3 position of the point along the path + * When the animation gets to the end it then tweens back to where it started (and on, and on) + * @method setLoopPingPong + * @param {int} loops:int (defaults to -1) how many times you want the loop to happen in both directions (-1 for an infinite number of times). Passing a value of 1 will cause the object to go towards and back from it's destination once. + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * transform.position = ltSpline.point( 0.6f ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopPingPong( 2 ); */ - public Vector3 point( float ratio ){ - float t = map( ratio ); - //Debug.Log("t:"+t+" ratio:"+ratio); - //float t = ratio; - return interp( t ); - } - - public void place2d( Transform transform, float ratio ){ - transform.position = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f){ - Vector3 v3Dir = point( ratio ) - transform.position; - float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg; - transform.eulerAngles = new Vector3(0, 0, angle-90); - } + public LTDescr setLoopPingPong(){ + this.loopType = LeanTweenType.pingPong; + if(this.loopCount==0) + this.loopCount = -1; + return this; } - - public void placeLocal2d( Transform transform, float ratio ){ - transform.localPosition = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f){ - Vector3 v3Dir = transform.parent.TransformPoint( point( ratio ) ) - transform.localPosition; - float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg; - transform.eulerAngles = new Vector3(0, 0, angle-90); - } + public LTDescr setLoopPingPong( int loops ) { + this.loopType = LeanTweenType.pingPong; + this.loopCount = loops == -1 ? loops : loops * 2; + return this; } - /** - * Place an object along a certain point on the path (facing the direction perpendicular to the path) - * - * @method place - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * Have a method called when the tween finishes + * @method setOnComplete + * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished(){ } + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.place( transform, 0.6f ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); */ - public void place( Transform transform, float ratio ){ - place(transform, ratio, Vector3.up); + public LTDescr setOnComplete( Action onComplete ){ + this.onComplete = onComplete; + return this; } /** - * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - * - * @method place - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) - * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * Have a method called when the tween finishes + * @method setOnComplete (object) + * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished( object myObj ){ } + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.place( transform, 0.6f, Vector3.left ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); */ - public void place( Transform transform, float ratio, Vector3 worldUp ){ - transform.position = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f) - transform.LookAt( point( ratio ), worldUp ); + public LTDescr setOnComplete( Action onComplete ){ + this.onCompleteObject = onComplete; + return this; + } + public LTDescr setOnComplete( Action onComplete, object onCompleteParam ){ + this.onCompleteObject = onComplete; + if(onCompleteParam!=null) + this.onCompleteParam = onCompleteParam; + return this; } /** - * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space - * - * @method placeLocal - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * Pass an object to along with the onComplete Function + * @method setOnCompleteParam + * @param {object} onComplete:object an object that + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.placeLocal( transform, 0.6f ); + * LeanTween.delayedCall(1.5f, enterMiniGameStart).setOnCompleteParam( new object[]{""+5} );

+ * void enterMiniGameStart( object val ){
+ *  object[] arr = (object [])val;
+ *  int lvl = int.Parse((string)arr[0]);
+ * }
*/ - public void placeLocal( Transform transform, float ratio ){ - placeLocal( transform, ratio, Vector3.up ); + public LTDescr setOnCompleteParam( object onCompleteParam ){ + this.onCompleteParam = onCompleteParam; + return this; } + /** - * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space - * - * @method placeLocal - * @param {Transform} transform:Transform the transform of the object you wish to place along the path - * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) - * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * Have a method called on each frame that the tween is being animated (passes a float value) + * @method setOnUpdate + * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object + * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * ltPath.placeLocal( transform, 0.6f, Vector3.left ); + * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );
+ *
+ * void tweenMoved( float val ){ }
*/ - public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){ - transform.localPosition = point( ratio ); - ratio += 0.001f; - if(ratio<=1.0f) - transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp ); + public LTDescr setOnUpdate( Action onUpdate ){ + this.onUpdateFloat = onUpdate; + this.hasUpdateCallback = true; + return this; } - - public void gizmoDraw(float t = -1.0f) { - if(lengthRatio!=null && lengthRatio.Length>0){ - Vector3 prevPt = point(0); - - for (int i = 1; i <= 120; i++) { - float pm = (float) i / 120f; - Vector3 currPt = point(pm); - Gizmos.DrawLine(currPt, prevPt); - prevPt = currPt; - } - } + public LTDescr setOnUpdateRatio(Action onUpdate) + { + this.onUpdateFloatRatio = onUpdate; + this.hasUpdateCallback = true; + return this; + } + + public LTDescr setOnUpdateObject( Action onUpdate ){ + this.onUpdateFloatObject = onUpdate; + this.hasUpdateCallback = true; + return this; } - - public Vector3 Velocity(float t) { - t = map( t ); - - int numSections = pts.Length - 3; - int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1); - float u = t * (float) numSections - (float) currPt; - - Vector3 a = pts[currPt]; - Vector3 b = pts[currPt + 1]; - Vector3 c = pts[currPt + 2]; - Vector3 d = pts[currPt + 3]; - - return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u) - + (2f * a -5f * b + 4f * c - d) * u - + .5f * c - .5f * a; + public LTDescr setOnUpdateVector2( Action onUpdate ){ + this.onUpdateVector2 = onUpdate; + this.hasUpdateCallback = true; + return this; } -} - -public enum TweenAction{ - MOVE_X, - MOVE_Y, - MOVE_Z, - MOVE_LOCAL_X, - MOVE_LOCAL_Y, - MOVE_LOCAL_Z, - MOVE_CURVED, - MOVE_CURVED_LOCAL, - MOVE_SPLINE, - MOVE_SPLINE_LOCAL, - SCALE_X, - SCALE_Y, - SCALE_Z, - ROTATE_X, - ROTATE_Y, - ROTATE_Z, - ROTATE_AROUND, - ROTATE_AROUND_LOCAL, - CANVAS_ROTATEAROUND, - ALPHA, - TEXT_ALPHA, - CANVAS_ALPHA, - ALPHA_VERTEX, - COLOR, - CALLBACK_COLOR, - TEXT_COLOR, - CANVAS_COLOR, - CALLBACK, - MOVE, - MOVE_LOCAL, - ROTATE, - ROTATE_LOCAL, - SCALE, - VALUE3, - GUI_MOVE, - GUI_MOVE_MARGIN, - GUI_SCALE, - GUI_ALPHA, - GUI_ROTATE, - DELAYED_SOUND, - CANVAS_MOVE, - CANVAS_SCALE, -} - -public enum LeanTweenType{ - notUsed, linear, easeOutQuad, easeInQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, - easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, - easeInBounce, easeOutBounce, easeInOutBounce, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeSpring, easeShake, punch, once, clamp, pingPong, animationCurve -} - -/** -* Internal Representation of a Tween
-*
-* This class represents all of the optional parameters you can pass to a method (it also represents the internal representation of the tween).

-* Optional Parameters are passed at the end of every method:
-*
-*   Example:
-*   LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
-*
-* You can pass the optional parameters in any order, and chain on as many as you wish.
-* You can also pass parameters at a later time by saving a reference to what is returned.
-*
-*   Example:
-*   LTDescr d = LeanTween.moveX(gameObject, 1f, 1f);
-*     ...later set some parameters
-*   d.setOnComplete( onCompleteFunc ).setEase( LeanTweenType.easeInOutBack );
-*
-* Retrieve a unique id for the tween by using the "id" property. You can pass this to LeanTween.pause, LeanTween.resume, LeanTween.cancel methods
-*
-*   Example:
-*   int id = LeanTween.moveX(gameObject, 1f, 3f).id;
-*   LeanTween.pause( id );
-* @class LTDescr -* @constructor -*/ -public class LTDescr{ - public bool toggle; - public bool useEstimatedTime; - public bool useFrames; - public bool useManualTime; - public bool hasInitiliazed; - public bool hasPhysics; - public bool onCompleteOnRepeat; - public bool onCompleteOnStart; - public float passed; - public float delay; - public float time; - public float lastVal; - private uint _id; - public int loopCount; - public uint counter; - public float direction; - public float directionLast; - public bool destroyOnComplete; - public Transform trans; - public LTRect ltRect; - public Vector3 from; - public Vector3 to; - public Vector3 diff; - public Vector3 point; - public Vector3 axis; - public Quaternion origRotation; - public LTBezierPath path; - public LTSpline spline; - public TweenAction type; - public LeanTweenType tweenType; - public AnimationCurve animationCurve; - public LeanTweenType loopType; - public bool hasUpdateCallback; - public Action onUpdateFloat; - public Action onUpdateFloatObject; - public Action onUpdateVector2; - public Action onUpdateVector3; - public Action onUpdateVector3Object; - public Action onUpdateColor; - public Action onComplete; - public Action onCompleteObject; - public object onCompleteParam; - public object onUpdateParam; - - #if LEANTWEEN_1 - public Hashtable optional; - #endif - #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 - public RectTransform rectTransform; - public UnityEngine.UI.Text uiText; - public UnityEngine.UI.Image uiImage; - #endif - - private static uint global_counter = 0; - - public override string ToString(){ - return (trans!=null ? "gameObject:"+trans.gameObject : "gameObject:null")+" toggle:"+toggle+" passed:"+passed+" time:"+time+" delay:"+delay+" from:"+from+" to:"+to+" type:"+type+" ease:"+tweenType+" useEstimatedTime:"+useEstimatedTime+" id:"+id+" hasInitiliazed:"+hasInitiliazed; + public LTDescr setOnUpdateVector3( Action onUpdate ){ + this.onUpdateVector3 = onUpdate; + this.hasUpdateCallback = true; + return this; + } + public LTDescr setOnUpdateColor( Action onUpdate ){ + this.onUpdateColor = onUpdate; + this.hasUpdateCallback = true; + return this; } - public LTDescr(){ + #if !UNITY_FLASH + public LTDescr setOnUpdate( Action onUpdate ){ + this.onUpdateColor = onUpdate; + this.hasUpdateCallback = true; + return this; } /** - * Cancel a tween - * - * @method cancel + * Have a method called on each frame that the tween is being animated (passes a float value and a object) + * @method setOnUpdate (object) + * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object, and an object of the person's choosing * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );
+ *
+ * void tweenMoved( float val, object obj ){ }
*/ - public LTDescr cancel(){ - LeanTween.removeTween((int)this._id); + public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ + this.onUpdateFloatObject = onUpdate; + this.hasUpdateCallback = true; + if(onUpdateParam!=null) + this.onUpdateParam = onUpdateParam; return this; } - public int uniqueId{ - get{ - uint toId = _id | counter << 16; + public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ + this.onUpdateVector3Object = onUpdate; + this.hasUpdateCallback = true; + if(onUpdateParam!=null) + this.onUpdateParam = onUpdateParam; + return this; + } - /*uint backId = toId & 0xFFFF; - uint backCounter = toId >> 16; - if(_id!=backId || backCounter!=counter){ - Debug.LogError("BAD CONVERSION toId:"+_id); - }*/ + public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ + this.onUpdateVector2 = onUpdate; + this.hasUpdateCallback = true; + if(onUpdateParam!=null) + this.onUpdateParam = onUpdateParam; + return this; + } - return (int)toId; - } + /** + * Have a method called on each frame that the tween is being animated (passes a float value) + * @method setOnUpdate (Vector3) + * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );
+ *
+ * void tweenMoved( Vector3 val ){ }
+ */ + public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ + this.onUpdateVector3 = onUpdate; + this.hasUpdateCallback = true; + if(onUpdateParam!=null) + this.onUpdateParam = onUpdateParam; + return this; } + #endif + - public int id{ - get{ - return uniqueId; - } + /** + * Have an object passed along with the onUpdate method + * @method setOnUpdateParam + * @param {object} onUpdateParam:object an object that will be passed along with the onUpdate method + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );
+ *
+ * void tweenMoved( float val, object obj ){ }
+ */ + public LTDescr setOnUpdateParam( object onUpdateParam ){ + this.onUpdateParam = onUpdateParam; + return this; } - public void reset(){ - this.toggle = true; - #if LEANTWEEN_1 - this.optional = null; - #endif - this.trans = null; - this.passed = this.delay = this.lastVal = 0.0f; - this.hasUpdateCallback = this.useEstimatedTime = this.useFrames = this.hasInitiliazed = this.onCompleteOnRepeat = this.destroyOnComplete = this.onCompleteOnStart = this.useManualTime = false; - this.animationCurve = null; - this.tweenType = LeanTweenType.linear; - this.loopType = LeanTweenType.once; - this.loopCount = 0; - this.direction = this.directionLast = 1.0f; - this.onUpdateFloat = null; - this.onUpdateVector2 = null; - this.onUpdateVector3 = null; - this.onUpdateFloatObject = null; - this.onUpdateVector3Object = null; - this.onUpdateColor = null; - this.onComplete = null; - this.onCompleteObject = null; - this.onCompleteParam = null; - this.point = Vector3.zero; - global_counter++; - if(global_counter>0x8000) - global_counter = 0; - } - - // This method is only for internal use - public void init(){ - this.hasInitiliazed = true; - - // Set time based on current timeScale - if( !this.useEstimatedTime ){ - this.time = this.time*Time.timeScale; + /** + * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon + * @method setOrientToPath + * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);
+ */ + public LTDescr setOrientToPath( bool doesOrient ){ + if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){ + if(this.path==null) + this.path = new LTBezierPath(); + this.path.orientToPath = doesOrient; + }else{ + this.spline.orientToPath = doesOrient; } + return this; + } - // Initialize From Values - switch(this.type){ - case TweenAction.MOVE: - this.from = trans.position; break; - case TweenAction.MOVE_X: - this.from.x = trans.position.x; break; - case TweenAction.MOVE_Y: - this.from.x = trans.position.y; break; - case TweenAction.MOVE_Z: - this.from.x = trans.position.z; break; - case TweenAction.MOVE_LOCAL_X: - this.from.x = trans.localPosition.x; break; - case TweenAction.MOVE_LOCAL_Y: - this.from.x = trans.localPosition.y; break; - case TweenAction.MOVE_LOCAL_Z: - this.from.x = trans.localPosition.z; break; - case TweenAction.SCALE_X: - this.from.x = trans.localScale.x; break; - case TweenAction.SCALE_Y: - this.from.x = trans.localScale.y; break; - case TweenAction.SCALE_Z: - this.from.x = trans.localScale.z; break; - case TweenAction.ALPHA: - #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 - this.from.x = trans.gameObject.renderer.material.color.a; - break; - #else - SpriteRenderer ren = trans.gameObject.GetComponent(); - if(ren!=null){ - this.from.x = ren.color.a; - }else if(trans.gameObject.GetComponent()!=null){ - this.from.x = trans.gameObject.GetComponent().material.color.a; - } - break; - #endif - case TweenAction.MOVE_LOCAL: - this.from = trans.localPosition; break; - case TweenAction.MOVE_CURVED: - case TweenAction.MOVE_CURVED_LOCAL: - case TweenAction.MOVE_SPLINE: - case TweenAction.MOVE_SPLINE_LOCAL: - this.from.x = 0; break; - case TweenAction.ROTATE: - this.from = trans.eulerAngles; - this.to = new Vector3(LeanTween.closestRot( this.from.x, this.to.x), LeanTween.closestRot( this.from.y, this.to.y), LeanTween.closestRot( this.from.z, this.to.z)); - break; - case TweenAction.ROTATE_X: - this.from.x = trans.eulerAngles.x; - this.to.x = LeanTween.closestRot( this.from.x, this.to.x); - break; - case TweenAction.ROTATE_Y: - this.from.x = trans.eulerAngles.y; - this.to.x = LeanTween.closestRot( this.from.x, this.to.x); - break; - case TweenAction.ROTATE_Z: - this.from.x = trans.eulerAngles.z; - this.to.x = LeanTween.closestRot( this.from.x, this.to.x); - break; - case TweenAction.ROTATE_AROUND: - this.lastVal = 0.0f; // optional["last"] - this.from.x = 0.0f; - this.origRotation = trans.rotation; // optional["origRotation" - break; - case TweenAction.ROTATE_AROUND_LOCAL: - this.lastVal = 0.0f; // optional["last"] - this.from.x = 0.0f; - this.origRotation = trans.localRotation; // optional["origRotation" - break; - case TweenAction.ROTATE_LOCAL: - this.from = trans.localEulerAngles; - this.to = new Vector3(LeanTween.closestRot( this.from.x, this.to.x), LeanTween.closestRot( this.from.y, this.to.y), LeanTween.closestRot( this.from.z, this.to.z)); - break; - case TweenAction.SCALE: - this.from = trans.localScale; break; - case TweenAction.GUI_MOVE: - this.from = new Vector3(this.ltRect.rect.x, this.ltRect.rect.y, 0); break; - case TweenAction.GUI_MOVE_MARGIN: - this.from = new Vector2(this.ltRect.margin.x, this.ltRect.margin.y); break; - case TweenAction.GUI_SCALE: - this.from = new Vector3(this.ltRect.rect.width, this.ltRect.rect.height, 0); break; - case TweenAction.GUI_ALPHA: - this.from.x = this.ltRect.alpha; break; - case TweenAction.GUI_ROTATE: - if(this.ltRect.rotateEnabled==false){ - this.ltRect.rotateEnabled = true; - this.ltRect.resetForRotation(); - } - - this.from.x = this.ltRect.rotation; break; - case TweenAction.ALPHA_VERTEX: - this.from.x = trans.GetComponent().mesh.colors32[0].a; - break; - case TweenAction.CALLBACK: - if(this.onCompleteOnStart){ - if(this.onComplete!=null){ - this.onComplete(); - }else if(this.onCompleteObject!=null){ - this.onCompleteObject(this.onCompleteParam); - } - } - break; - case TweenAction.CALLBACK_COLOR: - this.diff = new Vector3(1.0f,0.0f,0.0f); - break; - case TweenAction.COLOR: - #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 - if(trans.gameObject.renderer){ - Color col = trans.gameObject.renderer.material.color; - this.setFromColor( col ); - } - #else - SpriteRenderer ren2 = trans.gameObject.GetComponent(); - if(ren2!=null){ - this.from = new Vector3(0.0f, ren2.color.a, 0.0f); - this.diff = new Vector3(1.0f,0.0f,0.0f); - this.axis = new Vector3( ren2.color.r, ren2.color.g, ren2.color.b ); - }else if(trans.gameObject.GetComponent()!=null){ - if(trans.gameObject.GetComponent()){ - Color col = trans.gameObject.GetComponent().material.color; - this.setFromColor( col ); - } - } - #endif - break; - #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 - case TweenAction.CANVAS_ALPHA: - this.uiImage = trans.gameObject.GetComponent(); - if(this.uiImage != null) - this.from.x = this.uiImage.color.a; - break; - case TweenAction.CANVAS_COLOR: - this.uiImage = trans.gameObject.GetComponent(); - if(this.uiImage != null) - this.setFromColor( this.uiImage.color ); - break; - case TweenAction.TEXT_ALPHA: - this.uiText = trans.gameObject.GetComponent(); - if (this.uiText != null) - this.from.x = this.uiText.color.a; - break; - case TweenAction.TEXT_COLOR: - this.uiText = trans.gameObject.GetComponent(); - if (this.uiText != null) - this.setFromColor( this.uiText.color ); - break; - case TweenAction.CANVAS_MOVE: - this.from = this.rectTransform.anchoredPosition; break; - case TweenAction.CANVAS_ROTATEAROUND: - this.lastVal = 0.0f; - this.from.x = 0.0f; - this.origRotation = this.rectTransform.rotation; - break; - case TweenAction.CANVAS_SCALE: - this.from = this.rectTransform.localScale; break; - #endif + /** + * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon + * @method setOrientToPath2d + * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along + * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);
+ */ + public LTDescr setOrientToPath2d( bool doesOrient2d ){ + setOrientToPath(doesOrient2d); + if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){ + this.path.orientToPath2d = doesOrient2d; + }else{ + this.spline.orientToPath2d = doesOrient2d; } - if(this.type!=TweenAction.CALLBACK_COLOR && this.type!=TweenAction.COLOR && this.type!=TweenAction.TEXT_COLOR && this.type!=TweenAction.CANVAS_COLOR) - this.diff = this.to - this.from; + return this; } - public LTDescr setFromColor( Color col ){ - this.from = new Vector3(0.0f, col.a, 0.0f); - this.diff = new Vector3(1.0f,0.0f,0.0f); - this.axis = new Vector3( col.r, col.g, col.b ); + public LTDescr setRect( LTRect rect ){ + this.ltRect = rect; return this; } - /** - * Pause a tween - * - * @method pause - * @return {LTDescr} LTDescr an object that distinguishes the tween - */ - public LTDescr pause(){ - if(this.direction != 0.0f){ // check if tween is already paused - this.directionLast = this.direction; - this.direction = 0.0f; - } + public LTDescr setRect( Rect rect ){ + this.ltRect = new LTRect(rect); + return this; + } - return this; + public LTDescr setPath( LTBezierPath path ){ + this.path = path; + return this; } /** - * Resume a paused tween - * - * @method resume + * Set the point at which the GameObject will be rotated around + * @method setPoint + * @param {Vector3} point:Vector3 point at which you want the object to rotate around (local space) * @return {LTDescr} LTDescr an object that distinguishes the tween + * @example + * LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ) .setPoint( new Vector3(1f,0f,0f) ) .setEase( LeanTweenType.easeInOutBounce );
*/ - public LTDescr resume(){ - this.direction = this.directionLast; + public LTDescr setPoint( Vector3 point ){ + this.point = point; return this; } - public LTDescr setAxis( Vector3 axis ){ - this.axis = axis; + public LTDescr setDestroyOnComplete( bool doesDestroy ){ + this.destroyOnComplete = doesDestroy; + return this; + } + + public LTDescr setAudio( object audio ){ + this.onCompleteParam = audio; return this; } /** - * Delay the start of a tween - * - * @method setDelay - * @param {float} float time The time to complete the tween in + * Set the onComplete method to be called at the end of every loop cycle (also applies to the delayedCall method) + * @method setOnCompleteOnRepeat + * @param {bool} isOn:bool does call onComplete on every loop cycle * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setDelay( 1.5f ); + * LeanTween.delayedCall(gameObject,0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true); */ - public LTDescr setDelay( float delay ){ - if(this.useEstimatedTime){ - this.delay = delay; - }else{ - this.delay = delay*Time.timeScale; - } - - return this; - } - - /** - * Set the type of easing used for the tween.
- * - * - * @method setEase - * @param {LeanTweenType} easeType:LeanTweenType the easing type to use - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce ); - */ - public LTDescr setEase( LeanTweenType easeType ){ - this.tweenType = easeType; + public LTDescr setOnCompleteOnRepeat( bool isOn ){ + this.onCompleteOnRepeat = isOn; return this; } /** - * Set the type of easing used for the tween with a custom curve.
- * @method setEase (AnimationCurve) - * @param {AnimationCurve} easeDefinition:AnimationCurve an AnimationCure that describes the type of easing you want, this is great for when you want a unique type of movement + * Set the onComplete method to be called at the beginning of the tween (it will still be called when it is completed as well) + * @method setOnCompleteOnStart + * @param {bool} isOn:bool does call onComplete at the start of the tween * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce ); + * LeanTween.delayedCall(gameObject, 2f, ()=>{
// Flash an object 5 times + *  LeanTween.alpha(gameObject, 0f, 1f);
+ *  LeanTween.alpha(gameObject, 1f, 0f).setDelay(1f);
+ * }).setOnCompleteOnStart(true).setRepeat(5);
*/ - public LTDescr setEase( AnimationCurve easeCurve ){ - this.animationCurve = easeCurve; - return this; - } - - public LTDescr setTo( Vector3 to ){ - if(this.hasInitiliazed){ - this.to = to; - this.diff = to - this.from; - }else{ - this.to = to; - } - - return this; - } - - public LTDescr setFrom( Vector3 from ){ - if(this.trans) - this.init(); - this.from = from; - // this.hasInitiliazed = true; // this is set, so that the "from" value isn't overwritten later on when the tween starts - this.diff = this.to - this.from; - return this; - } - - public LTDescr setDiff( Vector3 diff ){ - this.diff = diff; + public LTDescr setOnCompleteOnStart( bool isOn ){ + this.onCompleteOnStart = isOn; return this; } - public LTDescr setHasInitialized( bool has ){ - this.hasInitiliazed = has; +#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 + public LTDescr setRect( RectTransform rect ){ + this.rectTransform = rect; return this; } - public LTDescr setId( uint id ){ - this._id = id; - this.counter = global_counter; + public LTDescr setSprites( UnityEngine.Sprite[] sprites ){ + this.sprites = sprites; return this; } - public LTDescr setTime( float time ){ - this.time = time; + public LTDescr setFrameRate( float frameRate ){ + this.time = this.sprites.Length / frameRate; return this; } - +#endif + /** - * Set the tween to repeat a number of times. - * @method setRepeat - * @param {int} repeatNum:int the number of times to repeat the tween. -1 to repeat infinite times + * Have a method called when the tween starts + * @method setOnStart () + * @param {Action<>} onStart:Action<> the method that should be called when the tween is starting ex: tweenStarted( ){ } * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 10 ).setLoopPingPong(); + * C#:
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( ()=>{ Debug.Log("I started!"); }); + * Javascript:
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( function(){ Debug.Log("I started!"); } ); */ - public LTDescr setRepeat( int repeat ){ - this.loopCount = repeat; - if((repeat>1 && this.loopType == LeanTweenType.once) || (repeat < 0 && this.loopType == LeanTweenType.once)){ - this.loopType = LeanTweenType.clamp; - } - if(this.type==TweenAction.CALLBACK || this.type==TweenAction.CALLBACK_COLOR){ - this.setOnCompleteOnRepeat(true); - } - return this; - } - - public LTDescr setLoopType( LeanTweenType loopType ){ - this.loopType = loopType; - return this; - } + public LTDescr setOnStart( Action onStart ){ + this.onStart = onStart; + return this; + } - /** - * Use estimated time when tweening an object when you want the animation to be time-scale independent (ignores the Time.timeScale value). Great for pause screens, when you want all other action to be stopped (or slowed down) - * @method setUseEstimatedTime - * @param {bool} useEstimatedTime:bool whether to use estimated time or not + /** + * Set the direction of a tween -1f for backwards 1f for forwards (currently only bezier and spline paths are supported) + * @method setDirection () + * @param {float} direction:float the direction that the tween should run, -1f for backwards 1f for forwards * @return {LTDescr} LTDescr an object that distinguishes the tween * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseEstimatedTime( true ); + * LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setDirection(-1f);
*/ - public LTDescr setUseEstimatedTime( bool useEstimatedTime ){ - this.useEstimatedTime = useEstimatedTime; - return this; - } - /** - * Use frames when tweening an object, when you don't want the animation to be time-frame independent... - * @method setUseFrames - * @param {bool} useFrames:bool whether to use estimated time or not - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseFrames( true ); - */ - public LTDescr setUseFrames( bool useFrames ){ - this.useFrames = useFrames; - return this; - } + public LTDescr setDirection( float direction ){ + if(this.direction!=-1f && this.direction!=1f){ + Debug.LogWarning("You have passed an incorrect direction of '"+direction+"', direction must be -1f or 1f"); + return this; + } + + if(this.direction!=direction){ + // Debug.Log("reverse path:"+this.path+" spline:"+this.spline); + if(this.path!=null){ + this.path = new LTBezierPath( LTUtility.reverse( this.path.pts ) ); + }else if(this.spline!=null){ + this.spline = new LTSpline( LTUtility.reverse( this.spline.pts ) ); + } + } + + return this; + } +} - public LTDescr setUseManualTime( bool useManualTime ){ - this.useManualTime = useManualTime; - return this; - } +public class LTUtility { - public LTDescr setLoopCount( int loopCount ){ - this.loopCount = loopCount; - return this; - } - /** - * No looping involved, just run once (the default) - * @method setLoopOnce - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopOnce(); - */ - public LTDescr setLoopOnce(){ this.loopType = LeanTweenType.once; return this; } + public static Vector3[] reverse( Vector3[] arr ){ + + int k = arr.Length - 1; + for(int i=0;i<=(arr.Length/2);i++) + { + Vector3 temp = arr[i]; + arr[i]=arr[k]; + arr[k]=temp; + k--; + } - /** - * When the animation gets to the end it starts back at where it began - * @method setLoopClamp - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat(2).setLoopClamp(); - */ - public LTDescr setLoopClamp(){ - this.loopType = LeanTweenType.clamp; - if(this.loopCount==0) - this.loopCount = -1; - return this; + return arr; } +} - /** - * When the animation gets to the end it then tweens back to where it started (and on, and on) - * @method setLoopPingPong - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat(2).setLoopPingPong(); - */ - public LTDescr setLoopPingPong(){ - this.loopType = LeanTweenType.pingPong; - if(this.loopCount==0) - this.loopCount = -1; - return this; - } +/** +* LeanTween is an efficient tweening engine for Unity3d

+* Index of All Methods | Optional Paramaters that can be passed

+* Optional Parameters are passed at the end of every method
+*
+* Example:
+* LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
+*
+* You can pass the optional parameters in any order, and chain on as many as you wish!

+* You can also modify this tween later, just save the unique id of the tween.
+*

Example:

+* int id = LeanTween.moveX(gameObject, 1f, 1f).id;
+* LTDescr d = LeanTween.descr( id );

+* if(d!=null){ // if the tween has already finished it will return null
+*    // change some parameters
+*    d.setOnComplete( onCompleteFunc ).setEase( LeanTweenType.easeInOutBack );
+* } +* +* @class LeanTween +*/ - /** - * Have a method called when the tween finishes - * @method setOnComplete - * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished(){ } - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); - */ - public LTDescr setOnComplete( Action onComplete ){ - this.onComplete = onComplete; - return this; - } +public class LeanTween : MonoBehaviour { - /** - * Have a method called when the tween finishes - * @method setOnComplete (object) - * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished( object myObj ){ } - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); - */ - public LTDescr setOnComplete( Action onComplete ){ - this.onCompleteObject = onComplete; - return this; - } - public LTDescr setOnComplete( Action onComplete, object onCompleteParam ){ - this.onCompleteObject = onComplete; - if(onCompleteParam!=null) - this.onCompleteParam = onCompleteParam; - return this; - } +public static bool throwErrors = true; +public static float tau = Mathf.PI*2.0f; - /** - * Pass an object to along with the onComplete Function - * @method setOnCompleteParam - * @param {object} onComplete:object an object that - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); - */ - public LTDescr setOnCompleteParam( object onCompleteParam ){ - this.onCompleteParam = onCompleteParam; - return this; - } +private static LTDescr[] tweens; +private static int[] tweensFinished; +private static LTDescr tween; +private static int tweenMaxSearch = -1; +private static int maxTweens = 400; +private static int frameRendered= -1; +private static GameObject _tweenEmpty; +private static float dtEstimated = -1f; +public static float dtManual; +#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 +private static float previousRealTime; +#endif +private static float dt; +private static float dtActual; +private static int i; +private static int j; +private static int finishedCnt; +private static AnimationCurve punch = new AnimationCurve( new Keyframe(0.0f, 0.0f ), new Keyframe(0.112586f, 0.9976035f ), new Keyframe(0.3120486f, -0.1720615f ), new Keyframe(0.4316337f, 0.07030682f ), new Keyframe(0.5524869f, -0.03141804f ), new Keyframe(0.6549395f, 0.003909959f ), new Keyframe(0.770987f, -0.009817753f ), new Keyframe(0.8838775f, 0.001939224f ), new Keyframe(1.0f, 0.0f ) ); +private static AnimationCurve shake = new AnimationCurve( new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(0.75f, -1f), new Keyframe(1f, 0f) ) ; +public static void init(){ + init(maxTweens); +} - /** - * Have a method called on each frame that the tween is being animated (passes a float value) - * @method setOnUpdate - * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );
- *
- * void tweenMoved( float val ){ }
- */ - public LTDescr setOnUpdate( Action onUpdate ){ - this.onUpdateFloat = onUpdate; - this.hasUpdateCallback = true; - return this; +public static int maxSearch{ + get{ + return tweenMaxSearch; } - - public LTDescr setOnUpdateObject( Action onUpdate ){ - this.onUpdateFloatObject = onUpdate; - this.hasUpdateCallback = true; - return this; - } - public LTDescr setOnUpdateVector2( Action onUpdate ){ - this.onUpdateVector2 = onUpdate; - this.hasUpdateCallback = true; - return this; - } - public LTDescr setOnUpdateVector3( Action onUpdate ){ - this.onUpdateVector3 = onUpdate; - this.hasUpdateCallback = true; - return this; - } - public LTDescr setOnUpdateColor( Action onUpdate ){ - this.onUpdateColor = onUpdate; - this.hasUpdateCallback = true; - return this; - } - - #if !UNITY_FLASH - - public LTDescr setOnUpdate( Action onUpdate ){ - this.onUpdateColor = onUpdate; - this.hasUpdateCallback = true; - return this; - } - - /** - * Have a method called on each frame that the tween is being animated (passes a float value and a object) - * @method setOnUpdate (object) - * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object, and an object of the person's choosing - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );
- *
- * void tweenMoved( float val, object obj ){ }
- */ - public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ - this.onUpdateFloatObject = onUpdate; - this.hasUpdateCallback = true; - if(onUpdateParam!=null) - this.onUpdateParam = onUpdateParam; - return this; - } - - public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ - this.onUpdateVector3Object = onUpdate; - this.hasUpdateCallback = true; - if(onUpdateParam!=null) - this.onUpdateParam = onUpdateParam; - return this; - } - - public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ - this.onUpdateVector2 = onUpdate; - this.hasUpdateCallback = true; - if(onUpdateParam!=null) - this.onUpdateParam = onUpdateParam; - return this; - } - - /** - * Have a method called on each frame that the tween is being animated (passes a float value) - * @method setOnUpdate (Vector3) - * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );
- *
- * void tweenMoved( Vector3 val ){ }
- */ - public LTDescr setOnUpdate( Action onUpdate, object onUpdateParam = null ){ - this.onUpdateVector3 = onUpdate; - this.hasUpdateCallback = true; - if(onUpdateParam!=null) - this.onUpdateParam = onUpdateParam; - return this; - } - #endif - - - /** - * Have an object passed along with the onUpdate method - * @method setOnUpdateParam - * @param {object} onUpdateParam:object an object that will be passed along with the onUpdate method - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );
- *
- * void tweenMoved( float val, object obj ){ }
- */ - public LTDescr setOnUpdateParam( object onUpdateParam ){ - this.onUpdateParam = onUpdateParam; - return this; - } - - /** - * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon - * @method setOrientToPath - * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);
- */ - public LTDescr setOrientToPath( bool doesOrient ){ - if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){ - if(this.path==null) - this.path = new LTBezierPath(); - this.path.orientToPath = doesOrient; - }else{ - this.spline.orientToPath = doesOrient; - } - return this; - } - - /** - * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon - * @method setOrientToPath2d - * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);
- */ - public LTDescr setOrientToPath2d( bool doesOrient2d ){ - setOrientToPath(doesOrient2d); - if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){ - this.path.orientToPath2d = doesOrient2d; - }else{ - this.spline.orientToPath2d = doesOrient2d; - } - return this; - } - - public LTDescr setRect( LTRect rect ){ - this.ltRect = rect; - return this; - } - - public LTDescr setRect( Rect rect ){ - this.ltRect = new LTRect(rect); - return this; - } - - public LTDescr setPath( LTBezierPath path ){ - this.path = path; - return this; - } - - /** - * Set the point at which the GameObject will be rotated around - * @method setPoint - * @param {Vector3} point:Vector3 point at which you want the object to rotate around (local space) - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ) .setPoint( new Vector3(1f,0f,0f) ) .setEase( LeanTweenType.easeInOutBounce );
- */ - public LTDescr setPoint( Vector3 point ){ - this.point = point; - return this; - } - - public LTDescr setDestroyOnComplete( bool doesDestroy ){ - this.destroyOnComplete = doesDestroy; - return this; - } - - public LTDescr setAudio( object audio ){ - this.onCompleteParam = audio; - return this; - } - - /** - * Set the onComplete method to be called at the end of every loop cycle (also applies to the delayedCall method) - * @method setOnCompleteOnRepeat - * @param {bool} isOn:bool does call onComplete on every loop cycle - * @return {LTDescr} LTDescr an object that distinguishes the tween - * @example - * LeanTween.delayedCall(gameObject,0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true); - */ - public LTDescr setOnCompleteOnRepeat( bool isOn ){ - this.onCompleteOnRepeat = isOn; - return this; - } - - public LTDescr setOnCompleteOnStart( bool isOn ){ - this.onCompleteOnStart = isOn; - return this; - } - -#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 - public LTDescr setRect( RectTransform rect ){ - this.rectTransform = rect; - return this; - } -#endif - -} - -/** -* LeanTween is an efficient tweening engine for Unity3d

-* Index of All Methods | Optional Paramaters that can be passed

-* Optional Parameters are passed at the end of every method
-*
-* Example:
-* LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
-*
-* You can pass the optional parameters in any order, and chain on as many as you wish.
-* You can also pass parameters at a later time by saving a reference to what is returned.
-*
-* Example:
-* LTDescr d = LeanTween.moveX(gameObject, 1f, 1f);
-*   ...later set some parameters
-* d.setOnComplete( onCompleteFunc ).setEase( LeanTweenType.easeInOutBack );
-* -* @class LeanTween -*/ - -public class LeanTween: MonoBehaviour { - -public static bool throwErrors = true; - -private static LTDescr[] tweens; -private static int[] tweensFinished; -private static LTDescr tween; -private static int tweenMaxSearch = -1; -private static int maxTweens = 400; -private static int frameRendered= -1; -private static GameObject _tweenEmpty; -private static float dtEstimated; -public static float dtManual; -private static float previousRealTime; -private static float dt; -private static float dtActual; -private static int i; -private static int j; -private static int finishedCnt; -private static AnimationCurve punch = new AnimationCurve( new Keyframe(0.0f, 0.0f ), new Keyframe(0.112586f, 0.9976035f ), new Keyframe(0.3120486f, -0.1720615f ), new Keyframe(0.4316337f, 0.07030682f ), new Keyframe(0.5524869f, -0.03141804f ), new Keyframe(0.6549395f, 0.003909959f ), new Keyframe(0.770987f, -0.009817753f ), new Keyframe(0.8838775f, 0.001939224f ), new Keyframe(1.0f, 0.0f ) ); -private static AnimationCurve shake = new AnimationCurve( new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(0.75f, -1f), new Keyframe(1f, 0f) ) ; - -public static void init(){ - init(maxTweens); -} - -public static int maxSearch{ - get{ - return tweenMaxSearch; +} + +public static int tweensRunning{ + get{ + int count = 0; + for (int i = 0; i <= tweenMaxSearch; i++){ + if (tweens[i].toggle){ + count++; + } + } + return count; } } @@ -1824,7 +1335,11 @@ public static void init(int maxSimultaneousTweens){ } public static void reset(){ + for (int i = 0; i <= tweenMaxSearch; i++){ + tweens[i].toggle = false; + } tweens = null; + Destroy(_tweenEmpty); } public void Update(){ @@ -1841,7 +1356,7 @@ private static float timeTotal; private static TweenAction tweenAction; private static float ratioPassed; private static float from; -private static float to; +//private static float to = 1.0f; private static float val; private static bool isTweenFinished; private static int maxTweenReached; @@ -1853,35 +1368,50 @@ public static void update() { if(frameRendered != Time.frameCount){ // make sure update is only called once per frame init(); + #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 dtEstimated = Time.realtimeSinceStartup - previousRealTime; if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large dtEstimated = 0.2f; previousRealTime = Time.realtimeSinceStartup; - dtActual = Time.deltaTime*Time.timeScale; + #else + if(dtEstimated<0f){ + dtEstimated = 0f; + }else{ + dtEstimated = Time.unscaledDeltaTime; + } + // Debug.Log("Time.unscaledDeltaTime:"+Time.unscaledDeltaTime); + #endif + + dtActual = Time.deltaTime; maxTweenReached = 0; finishedCnt = 0; // if(tweenMaxSearch>1500) // Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens); for( int i = 0; i <= tweenMaxSearch && i < maxTweens; i++){ - //Debug.Log("tweens["+i+"].toggle:"+tweens[i].toggle); + //if(i==0 && tweens[i].toggle) + // Debug.Log("tweens["+i+"]"+tweens[i]+" dt:"+dt); if(tweens[i].toggle){ maxTweenReached = i; tween = tweens[i]; trans = tween.trans; timeTotal = tween.time; tweenAction = tween.type; - - dt = dtActual; + + /*if(trans.gameObject.name=="Main Camera"){ + Debug.Log("main tween:"+tween+" i:"+i); + }*/ + if( tween.useEstimatedTime ){ dt = dtEstimated; - timeTotal = tween.time; }else if( tween.useFrames ){ dt = 1; }else if( tween.useManualTime ){ dt = dtManual; }else if(tween.direction==0f){ dt = 0f; + }else{ + dt = dtActual; } if(trans==null){ @@ -1906,11 +1436,12 @@ public static void update() { if(!tween.hasInitiliazed && ((tween.passed==0.0 && tween.delay==0.0) || tween.passed>0.0) ){ tween.init(); } + if(tween.delay<=0){ // Move Values if(timeTotal<=0f){ //Debug.LogError("time total is zero Time.timeScale:"+Time.timeScale+" useEstimatedTime:"+tween.useEstimatedTime); - ratioPassed = 0f; + ratioPassed = 1f; }else{ ratioPassed = tween.passed / timeTotal; } @@ -1978,17 +1509,17 @@ public static void update() { case LeanTweenType.easeInOutBounce: val = easeInOutBounce(tween.from.x, tween.to.x, ratioPassed); break; case LeanTweenType.easeInBack: - val = easeInBack(tween.from.x, tween.to.x, ratioPassed); break; + val = easeInBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot); break; case LeanTweenType.easeOutBack: - val = easeOutBack(tween.from.x, tween.to.x, ratioPassed); break; + val = easeOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot); break; case LeanTweenType.easeInOutBack: - val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break; + val = easeInOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot); break; case LeanTweenType.easeInElastic: - val = easeInElastic(tween.from.x, tween.to.x, ratioPassed); break; + val = easeInElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period); break; case LeanTweenType.easeOutElastic: - val = easeOutElastic(tween.from.x, tween.to.x, ratioPassed); break; + val = easeOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period); break; case LeanTweenType.easeInOutElastic: - val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break; + val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period); break; case LeanTweenType.punch: case LeanTweenType.easeShake: if(tween.tweenType==LeanTweenType.punch){ @@ -2009,7 +1540,7 @@ public static void update() { } - //Debug.Log("from:"+from+" to:"+to+" val:"+val+" ratioPassed:"+ratioPassed); + // Debug.Log("from:"+from+" val:"+val+" ratioPassed:"+ratioPassed); if(tweenAction==TweenAction.MOVE_X){ trans.position=new Vector3( val,trans.position.y,trans.position.z); }else if(tweenAction==TweenAction.MOVE_Y){ @@ -2078,12 +1609,18 @@ public static void update() { trans.eulerAngles=new Vector3(trans.eulerAngles.x,trans.eulerAngles.y,val); }else if(tweenAction==TweenAction.ROTATE_AROUND){ Vector3 origPos = trans.localPosition; - trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, -val); + Vector3 rotateAroundPt = (Vector3)trans.TransformPoint( tween.point ); + trans.RotateAround(rotateAroundPt, tween.axis, -val); Vector3 diff = origPos - trans.localPosition; trans.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position trans.rotation = tween.origRotation; - trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, val); + + rotateAroundPt = (Vector3)trans.TransformPoint( tween.point ); + trans.RotateAround(rotateAroundPt, tween.axis, val); + + //GameObject cubeMarker = GameObject.Find("TweenRotatePoint"); + //cubeMarker.transform.position = rotateAroundPt; }else if(tweenAction==TweenAction.ROTATE_AROUND_LOCAL){ Vector3 origPos = trans.localPosition; @@ -2092,14 +1629,29 @@ public static void update() { trans.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position trans.localRotation = tween.origRotation; - trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), trans.TransformDirection(tween.axis), val); + Vector3 rotateAroundPt = (Vector3)trans.TransformPoint( tween.point ); + trans.RotateAround(rotateAroundPt, trans.TransformDirection(tween.axis), val); + + //GameObject cubeMarker = GameObject.Find("TweenRotatePoint"); + //cubeMarker.transform.position = rotateAroundPt; }else if(tweenAction==TweenAction.ALPHA){ #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 - foreach(Material mat in trans.gameObject.renderer.materials){ - mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); - } + if(trans.gameObject.renderer){ + foreach(Material mat in trans.gameObject.renderer.materials){ + mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); + } + } + if(trans.childCount>0){ + foreach (Transform child in trans) { + if(child.gameObject.renderer!=null){ + foreach(Material mat in child.gameObject.renderer.materials){ + mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); + } + } + } + } #else @@ -2110,14 +1662,19 @@ public static void update() { }else{ if(trans.gameObject.GetComponent()!=null){ foreach(Material mat in trans.gameObject.GetComponent().materials){ - mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); + if(mat.HasProperty("_Color")){ + mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); + }else if(mat.HasProperty("_TintColor")){ + Color col = mat.GetColor ("_TintColor"); + mat.SetColor("_TintColor", new Color( col.r, col.g, col.b, val)); + } } } if(trans.childCount>0){ foreach (Transform child in trans) { if(child.gameObject.GetComponent()!=null){ foreach(Material mat in child.gameObject.GetComponent().materials){ - mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); + mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); } } } @@ -2137,15 +1694,34 @@ public static void update() { mesh.colors32 = colors; }else if(tweenAction==TweenAction.COLOR || tweenAction==TweenAction.CALLBACK_COLOR){ Color toColor = tweenColor(tween, val); - // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff); - if(tweenAction==TweenAction.COLOR){ - if(trans.gameObject.GetComponent()!=null){ - foreach(Material mat in trans.gameObject.GetComponent().materials){ - mat.color = toColor; + + #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 + SpriteRenderer ren = trans.gameObject.GetComponent(); + if(ren!=null){ + ren.color = toColor; + }else{ + #endif + // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff); + if(tweenAction==TweenAction.COLOR){ + if(trans.gameObject.GetComponent()!=null){ + foreach(Material mat in trans.gameObject.GetComponent().materials){ + mat.color = toColor; + } + } + if(trans.childCount>0){ + foreach (Transform child in trans) { + if(child.gameObject.GetComponent()!=null){ + foreach(Material mat in child.gameObject.GetComponent().materials){ + mat.color = toColor; + } + } + } } - } - } - if(tween.onUpdateColor!=null){ + } + #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 + } + #endif + if(dt!=0f && tween.onUpdateColor!=null){ tween.onUpdateColor(toColor); } } @@ -2158,7 +1734,7 @@ public static void update() { else if (tweenAction == TweenAction.CANVAS_COLOR){ Color toColor = tweenColor(tween, val); tween.uiImage.color = toColor; - if (tween.onUpdateColor != null){ + if (dt!=0f && tween.onUpdateColor != null){ tween.onUpdateColor(toColor); } } @@ -2168,7 +1744,7 @@ public static void update() { else if (tweenAction == TweenAction.TEXT_COLOR){ Color toColor = tweenColor(tween, val); tween.uiText.color = toColor; - if (tween.onUpdateColor != null){ + if (dt!=0f && tween.onUpdateColor != null){ tween.onUpdateColor(toColor); } if(trans.childCount>0){ @@ -2190,7 +1766,30 @@ public static void update() { rect.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position rect.rotation = tween.origRotation; rect.RotateAround((Vector3)rect.TransformPoint( tween.point ), tween.axis, val); - } + }else if(tweenAction==TweenAction.CANVAS_ROTATEAROUND_LOCAL){ + // figure out how much the rotation has shifted the object over + RectTransform rect = tween.rectTransform; + Vector3 origPos = rect.localPosition; + rect.RotateAround((Vector3)rect.TransformPoint( tween.point ), rect.TransformDirection(tween.axis), -val); + Vector3 diff = origPos - rect.localPosition; + + rect.localPosition = origPos - diff; // Subtract the amount the object has been shifted over by the rotate, to get it back to it's orginal position + rect.rotation = tween.origRotation; + rect.RotateAround((Vector3)rect.TransformPoint( tween.point ), rect.TransformDirection(tween.axis), val); + }else if(tweenAction==TweenAction.CANVAS_PLAYSPRITE){ + int frame = (int)Mathf.Round( val ); + // Debug.Log("frame:"+frame+" val:"+val); + tween.uiImage.sprite = tween.sprites[ frame ]; + }else if(tweenAction==TweenAction.CANVAS_MOVE_X){ + Vector3 current = tween.rectTransform.anchoredPosition3D; + tween.rectTransform.anchoredPosition3D = new Vector3(val, current.y, current.z); + }else if(tweenAction==TweenAction.CANVAS_MOVE_Y){ + Vector3 current = tween.rectTransform.anchoredPosition3D; + tween.rectTransform.anchoredPosition3D = new Vector3(current.x, val, current.z); + }else if(tweenAction==TweenAction.CANVAS_MOVE_Z){ + Vector3 current = tween.rectTransform.anchoredPosition3D; + tween.rectTransform.anchoredPosition3D = new Vector3(current.x, current.y, val); + } #endif }else if(tweenAction>=TweenAction.MOVE){ @@ -2254,15 +1853,15 @@ public static void update() { case LeanTweenType.easeInBack: newVect = new Vector3(easeInBack(tween.from.x, tween.to.x, ratioPassed), easeInBack(tween.from.y, tween.to.y, ratioPassed), easeInBack(tween.from.z, tween.to.z, ratioPassed)); break; case LeanTweenType.easeOutBack: - newVect = new Vector3(easeOutBack(tween.from.x, tween.to.x, ratioPassed), easeOutBack(tween.from.y, tween.to.y, ratioPassed), easeOutBack(tween.from.z, tween.to.z, ratioPassed)); break; + newVect = new Vector3(easeOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot), easeOutBack(tween.from.y, tween.to.y, ratioPassed, tween.overshoot), easeOutBack(tween.from.z, tween.to.z, ratioPassed, tween.overshoot)); break; case LeanTweenType.easeInOutBack: - newVect = new Vector3(easeInOutBack(tween.from.x, tween.to.x, ratioPassed), easeInOutBack(tween.from.y, tween.to.y, ratioPassed), easeInOutBack(tween.from.z, tween.to.z, ratioPassed)); break; + newVect = new Vector3(easeInOutBack(tween.from.x, tween.to.x, ratioPassed, tween.overshoot), easeInOutBack(tween.from.y, tween.to.y, ratioPassed, tween.overshoot), easeInOutBack(tween.from.z, tween.to.z, ratioPassed, tween.overshoot)); break; case LeanTweenType.easeInElastic: - newVect = new Vector3(easeInElastic(tween.from.x, tween.to.x, ratioPassed), easeInElastic(tween.from.y, tween.to.y, ratioPassed), easeInElastic(tween.from.z, tween.to.z, ratioPassed)); break; + newVect = new Vector3(easeInElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period), easeInElastic(tween.from.y, tween.to.y, ratioPassed, tween.overshoot, tween.period), easeInElastic(tween.from.z, tween.to.z, ratioPassed, tween.overshoot, tween.period)); break; case LeanTweenType.easeOutElastic: - newVect = new Vector3(easeOutElastic(tween.from.x, tween.to.x, ratioPassed), easeOutElastic(tween.from.y, tween.to.y, ratioPassed), easeOutElastic(tween.from.z, tween.to.z, ratioPassed)); break; + newVect = new Vector3(easeOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period), easeOutElastic(tween.from.y, tween.to.y, ratioPassed, tween.overshoot, tween.period), easeOutElastic(tween.from.z, tween.to.z, ratioPassed, tween.overshoot, tween.period)); break; case LeanTweenType.easeInOutElastic: - newVect = new Vector3(easeInOutElastic(tween.from.x, tween.to.x, ratioPassed), easeInOutElastic(tween.from.y, tween.to.y, ratioPassed), easeInOutElastic(tween.from.z, tween.to.z, ratioPassed)); break; + newVect = new Vector3(easeInOutElastic(tween.from.x, tween.to.x, ratioPassed, tween.overshoot, tween.period), easeInOutElastic(tween.from.y, tween.to.y, ratioPassed, tween.overshoot, tween.period), easeInOutElastic(tween.from.z, tween.to.z, ratioPassed, tween.overshoot, tween.period)); break; case LeanTweenType.punch: case LeanTweenType.easeShake: if(tween.tweenType==LeanTweenType.punch){ @@ -2312,7 +1911,7 @@ public static void update() { } #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 else if(tweenAction==TweenAction.CANVAS_MOVE){ - tween.rectTransform.anchoredPosition = newVect; + tween.rectTransform.anchoredPosition3D = newVect; }else if(tweenAction==TweenAction.CANVAS_SCALE){ tween.rectTransform.localScale = newVect; } @@ -2320,10 +1919,13 @@ public static void update() { } // Debug.Log("tween.delay:"+tween.delay + " tween.passed:"+tween.passed + " tweenAction:"+tweenAction + " to:"+newVect+" axis:"+tween.axis); - if(tween.hasUpdateCallback){ + if(dt!=0f && tween.hasUpdateCallback){ if(tween.onUpdateFloat!=null){ tween.onUpdateFloat(val); - }else if(tween.onUpdateFloatObject!=null){ + } + if (tween.onUpdateFloatRatio != null){ + tween.onUpdateFloatRatio(val,ratioPassed); + }else if(tween.onUpdateFloatObject!=null){ tween.onUpdateFloatObject(val, tween.onUpdateParam); }else if(tween.onUpdateVector3Object!=null){ tween.onUpdateVector3Object(newVect, tween.onUpdateParam); @@ -2380,7 +1982,7 @@ public static void update() { tweensFinished[finishedCnt] = i; finishedCnt++; - // Debug.Log("finished tween:"+i+" tween:"+tween); + //Debug.Log("finished tween:"+i+" tween:"+tween); if(tweenAction==TweenAction.GUI_ROTATE) tween.ltRect.rotateFinished = true; @@ -2408,12 +2010,12 @@ public static void update() { tween.passed = Mathf.Epsilon; } } - }else if(tween.delay<=0){ + }else if(tween.delay<=0f){ tween.passed += dt*tween.direction; }else{ tween.delay -= dt; // Debug.Log("dt:"+dt+" tween:"+i+" tween:"+tween); - if(tween.delay<0){ + if(tween.delay<0f){ tween.passed = 0.0f;//-tween.delay tween.delay = 0.0f; } @@ -2429,12 +2031,20 @@ public static void update() { j = tweensFinished[i]; tween = tweens[ j ]; + // logError("removing tween:"+tween); if(tween.onComplete!=null){ + System.Action onComplete = tween.onComplete; + //logError("removing tween for j:"+j+" tween:"+tween); removeTween(j); - tween.onComplete(); + //tween.cleanup(); + onComplete(); + }else if(tween.onCompleteObject!=null){ + System.Action onCompleteObject = tween.onCompleteObject; + object onCompleteParam = tween.onCompleteParam; removeTween(j); - tween.onCompleteObject(tween.onCompleteParam); + //tween.cleanup(); + onCompleteObject(onCompleteParam); } #if LEANTWEEN_1 else if(tween.optional!=null){ @@ -2442,6 +2052,7 @@ public static void update() { System.Action callbackWithParam = null; string callbackS=string.Empty; object callbackParam=null; + Hashtable optional = tween.optional; if(tween.optional!=null && tween.trans){ if(tween.optional["onComplete"]!=null){ callbackParam = tween.optional["onCompleteParam"]; @@ -2464,8 +2075,8 @@ public static void update() { }else if(callback!=null){ callback(); }else if(callbackS!=string.Empty){ - if (tween.optional["onCompleteTarget"]!=null){ - customTarget = tween.optional["onCompleteTarget"] as GameObject; + if (optional["onCompleteTarget"]!=null){ + customTarget = optional["onCompleteTarget"] as GameObject; if(callbackParam!=null) customTarget.BroadcastMessage ( callbackS, callbackParam ); else customTarget.BroadcastMessage( callbackS ); }else{ @@ -2473,10 +2084,12 @@ public static void update() { else trans.gameObject.BroadcastMessage( callbackS ); } } + } #endif else{ removeTween(j); + //tween.cleanup(); } } @@ -2505,11 +2118,17 @@ private static Color tweenColor( LTDescr tween, float val ){ return new Color(tween.axis.x + diff3.x*val, tween.axis.y + diff3.y*val, tween.axis.z + diff3.z*val, tween.from.y + diffAlpha*val); } +public static void removeTween( int i, int uniqueId){ // Only removes the tween if the unique id matches + if(tweens[i].uniqueId==uniqueId){ + removeTween( i ); + } +} + // This method is only used internally! Do not call this from your scripts. To cancel a tween use LeanTween.cancel public static void removeTween( int i ){ if(tweens[i].toggle){ tweens[i].toggle = false; - // Debug.Log("removed i:"+i); + //logError("Removing tween["+i+"]:"+tweens[i]); if(tweens[i].destroyOnComplete){ //Debug.Log("destroying tween.type:"+tween.type); if(tweens[i].ltRect!=null){ @@ -2521,6 +2140,7 @@ public static void removeTween( int i ){ } } } + tweens[i].cleanup(); //tweens[i].optional = null; startSearch = i; //Debug.Log("start search reset:"+startSearch + " i:"+i+" tweenMaxSearch:"+tweenMaxSearch); @@ -2562,10 +2182,12 @@ public static float closestRot( float from, float to ){ * Cancels all tweens * * @method LeanTween.cancelAll -* @param {callComplete} callComplete:bool if true, then the onComplete event will be -* fired if it exists +* @param {bool} callComplete:bool (optional) if true, then the all onCompletes will run before canceling * @example LeanTween.cancelAll(true);
*/ +public static void cancelAll(){ + cancelAll(false); +} public static void cancelAll(bool callComplete){ init(); for (int i = 0; i <= tweenMaxSearch; i++) @@ -2583,165 +2205,85 @@ public static void cancelAll(bool callComplete){ * * @method LeanTween.cancel * @param {GameObject} gameObject:GameObject gameObject whose tweens you wish to cancel +* @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling * @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f);
* LeanTween.cancel( gameObject ); */ public static void cancel( GameObject gameObject ){ + cancel( gameObject, false); +} +public static void cancel( GameObject gameObject, bool callOnComplete ){ init(); Transform trans = gameObject.transform; for(int i = 0; i <= tweenMaxSearch; i++){ if(tweens[i].toggle && tweens[i].trans==trans){ - tweens[i].onComplete(); + if (callOnComplete && tweens[i].onComplete != null) + tweens[i].onComplete(); removeTween(i); } } } -/** -* Cancel a specific tween with the provided id -* -* @method LeanTween.cancel -* @param {GameObject} gameObject:GameObject gameObject whose tweens you want to cancel -* @param {float} id:int unique id that represents that tween -*/ public static void cancel( GameObject gameObject, int uniqueId ){ if(uniqueId>=0){ init(); int backId = uniqueId & 0xFFFF; int backCounter = uniqueId >> 16; // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tweens[backId].counter + " tweens[id].type:"+tweens[backId].type); - if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter)){ - tweens[i].onComplete(); + if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter)) removeTween((int)backId); - } } } -/** -* Cancel a specific tween with the provided id -* -* @method LeanTween.cancel -* @param {LTRect} ltRect:LTRect LTRect object whose tweens you want to cancel -* @param {float} id:int unique id that represents that tween -*/ public static void cancel( LTRect ltRect, int uniqueId ){ if(uniqueId>=0){ init(); int backId = uniqueId & 0xFFFF; int backCounter = uniqueId >> 16; // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); - if(tweens[backId].ltRect == ltRect && tweens[backId].counter==backCounter){ - tweens[i].onComplete(); + if(tweens[backId].ltRect == ltRect && tweens[backId].counter==backCounter) removeTween((int)backId); - } } } -private static void cancel( int uniqueId ){ +/** +* Cancel a specific tween with the provided id +* +* @method LeanTween.cancel +* @param {int} id:int unique id that represents that tween +* @param {bool} callOnComplete:int (optional) whether to call the onComplete method before canceling +* @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).id;
+* LeanTween.cancel( id ); +*/ +public static void cancel( int uniqueId ){ + cancel( uniqueId, false); +} +public static void cancel( int uniqueId, bool callOnComplete ){ if(uniqueId>=0){ init(); int backId = uniqueId & 0xFFFF; int backCounter = uniqueId >> 16; // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); - if(tweens[backId].hasInitiliazed && tweens[backId].counter==backCounter){ - tweens[i].onComplete(); + if(tweens[backId].counter==backCounter){ + if(callOnComplete && tweens[backId].onComplete != null) + tweens[backId].onComplete(); removeTween((int)backId); } } } - /** -* Cancel all tweens that are currently targeting the gameObject -* -* @method LeanTween.cancel -* @param {GameObject} gameObject:GameObject gameObject whose tweens you wish to cancel -* @param {callComplete} callComplete:bool if true, then the onComplete event will be -* fired if it exists -* @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f);
-* LeanTween.cancel( gameObject ); -*/ - public static void cancel( GameObject gameObject, bool callComplete ){ - init(); - Transform trans = gameObject.transform; - for(int i = 0; i <= tweenMaxSearch; i++){ - if(tweens[i].toggle && tweens[i].trans==trans){ - if (callComplete && tweens[i].onComplete != null) - tweens[i].onComplete(); - removeTween(i); - } - } - } - - /** -* Cancel a specific tween with the provided id -* -* @method LeanTween.cancel -* @param {GameObject} gameObject:GameObject gameObject whose tweens you want to cancel -* @param {float} id:int unique id that represents that tween -* @param {callComplete} callComplete:bool if true, then the onComplete event will be -* fired if it exists -*/ - public static void cancel( GameObject gameObject, int uniqueId, bool callComplete ){ - if(uniqueId>=0){ - init(); - int backId = uniqueId & 0xFFFF; - int backCounter = uniqueId >> 16; - // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tweens[backId].counter + " tweens[id].type:"+tweens[backId].type); - if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter)){ - if (callComplete && tweens[i].onComplete != null) - tweens[i].onComplete(); - removeTween((int)backId); - } - } - } - - /** -* Cancel a specific tween with the provided id -* -* @method LeanTween.cancel -* @param {LTRect} ltRect:LTRect LTRect object whose tweens you want to cancel -* @param {float} id:int unique id that represents that tween -* @param {callComplete} callComplete:bool if true, then the onComplete event will be -* fired if it exists -*/ - public static void cancel( LTRect ltRect, int uniqueId, bool callComplete ){ - if(uniqueId>=0){ - init(); - int backId = uniqueId & 0xFFFF; - int backCounter = uniqueId >> 16; - // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); - if(tweens[backId].ltRect == ltRect && tweens[backId].counter==backCounter){ - if (callComplete && tweens[i].onComplete != null) - tweens[i].onComplete(); - removeTween((int)backId); - } - } - } - - /** -* Cancel a specific tween with the provided id +/** +* Retrieve a tweens LTDescr object to modify * -* @method LeanTween.cancel -* @param {float} id:int unique id that represents that tween -* @param {callComplete} callComplete:bool if true, then the onComplete event will be -* fired if it exists +* @method LeanTween.descr +* @param {int} id:int unique id that represents that tween +* @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod ).id;

+*
// later I want decide I want to change onComplete method
+* LTDescr descr = LeanTween.descr( id );
+* if(descr!=null) // if the tween has already finished it will come back null
+*   descr.setOnComplete( newMethod );
*/ - private static void cancel( int uniqueId, bool callComplete ){ - if(uniqueId>=0){ - init(); - int backId = uniqueId & 0xFFFF; - int backCounter = uniqueId >> 16; - // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); - if(tweens[backId].hasInitiliazed && tweens[backId].counter==backCounter){ - if (callComplete && tweens[i].onComplete != null) - tweens[i].onComplete(); - removeTween((int)backId); - } - } - } - -// Deprecated -public static LTDescr description( int uniqueId ){ +public static LTDescr descr( int uniqueId ){ int backId = uniqueId & 0xFFFF; int backCounter = uniqueId >> 16; @@ -2754,11 +2296,49 @@ public static LTDescr description( int uniqueId ){ return null; } +public static LTDescr description( int uniqueId ){ + return descr( uniqueId ); +} + +/** +* Retrieve a tweens LTDescr object(s) to modify +* +* @method LeanTween.descriptions +* @param {GameObject} id:GameObject object whose tween descriptions you want to retrieve +* @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod );

+*
// later I want decide I want to change onComplete method
+* LTDescr[] descr = LeanTween.descriptions( gameObject );
+* if(descr.Length>0) // make sure there is a valid description for this target
+*   descr[0].setOnComplete( newMethod );// in this case we only ever expect there to be one tween on this object
+*/ +public static LTDescr[] descriptions(GameObject gameObject = null) { + if (gameObject == null) return null; + + List descrs = new List(); + Transform trans = gameObject.transform; + for (int i = 0; i <= tweenMaxSearch; i++) { + if (tweens[i].toggle && tweens[i].trans == trans) + descrs.Add( tweens[i] ); + } + return descrs.ToArray(); + } + [System.Obsolete("Use 'pause( id )' instead")] public static void pause( GameObject gameObject, int uniqueId ){ pause( uniqueId ); } +/** +* Pause all tweens for a GameObject +* +* @method LeanTween.pause +* @param {int} id:int Id of the tween you want to pause +* @example +* int id = LeanTween.moveX(gameObject, 5, 1.0).id
+* LeanTween.pause( id );
+* // Later....
+* LeanTween.resume( id ); +*/ public static void pause( int uniqueId ){ int backId = uniqueId & 0xFFFF; int backCounter = uniqueId >> 16; @@ -2815,7 +2395,12 @@ public static void resume( GameObject gameObject, int uniqueId ){ * Resume a specific tween * * @method LeanTween.resume -* @param {int} id:int Id of the tween you want to resume ex: int id = LeanTween.MoveX(gameObject, 5, 1.0).id; +* @param {int} id:int Id of the tween you want to resume +* @example +* int id = LeanTween.moveX(gameObject, 5, 1.0).id
+* LeanTween.pause( id );
+* // Later....
+* LeanTween.resume( id ); */ public static void resume( int uniqueId ){ int backId = uniqueId & 0xFFFF; @@ -2845,7 +2430,14 @@ public static void resume( GameObject gameObject ){ * @method LeanTween.isTweening * @param {GameObject} gameObject:GameObject GameObject that you want to test if it is tweening */ -public static bool isTweening( GameObject gameObject ){ +public static bool isTweening( GameObject gameObject = null ){ + if(gameObject==null){ + for(int i = 0; i <= tweenMaxSearch; i++){ + if(tweens[i].toggle) + return true; + } + return false; + } Transform trans = gameObject.transform; for(int i = 0; i <= tweenMaxSearch; i++){ if(tweens[i].toggle && tweens[i].trans==trans) @@ -2859,11 +2451,11 @@ public static bool isTweening( GameObject gameObject ){ * * @method LeanTween.isTweening * @param {GameObject} id:int id of the tween that you want to test if it is tweening -*   Example:
-*   int id = LeanTween.moveX(gameObject, 1f, 3f).id;
-*   if(LeanTween.isTweening( id ))
+* @example +* int id = LeanTween.moveX(gameObject, 1f, 3f).id;
+* if(LeanTween.isTweening( id ))
*      Debug.Log("I am tweening!");
-*/ +*/ public static bool isTweening( int uniqueId ){ int backId = uniqueId & 0xFFFF; int backCounter = uniqueId >> 16; @@ -2875,12 +2467,6 @@ public static bool isTweening( int uniqueId ){ return false; } -/** -* Test whether or not a tween is active on a LTRect -* -* @method LeanTween.isTweening -* @param {LTRect} ltRect:LTRect LTRect that you want to test if it is tweening -*/ public static bool isTweening( LTRect ltRect ){ for( int i = 0; i <= tweenMaxSearch; i++){ if(tweens[i].toggle && tweens[i].ltRect==ltRect) @@ -2889,18 +2475,57 @@ public static bool isTweening( LTRect ltRect ){ return false; } -public static void drawBezierPath(Vector3 a, Vector3 b, Vector3 c, Vector3 d){ +public static void drawBezierPath(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float arrowSize = 0.0f, Transform arrowTransform = null){ Vector3 last = a; Vector3 p; Vector3 aa = (-a + 3*(b-c) + d); Vector3 bb = 3*(a+c) - 6*b; Vector3 cc = 3*(b-a); + float t; - for(float k = 1.0f; k <= 30.0f; k++){ - t = k / 30.0f; - p = ((aa* t + (bb))* t + cc)* t + a; - Gizmos.DrawLine(last, p); - last = p; + + if(arrowSize>0.0f){ + Vector3 beforePos = arrowTransform.position; + Quaternion beforeQ = arrowTransform.rotation; + float distanceTravelled = 0f; + + for(float k = 1.0f; k <= 120.0f; k++){ + t = k / 120.0f; + p = ((aa* t + (bb))* t + cc)* t + a; + Gizmos.DrawLine(last, p); + distanceTravelled += (p-last).magnitude; + if(distanceTravelled>1f){ + distanceTravelled = distanceTravelled - 1f; + /*float deltaY = p.y - last.y; + float deltaX = p.x - last.x; + float ang = Mathf.Atan(deltaY / deltaX); + Vector3 arrow = p + new Vector3( Mathf.Cos(ang+2.5f), Mathf.Sin(ang+2.5f), 0f)*0.5f; + Gizmos.DrawLine(p, arrow); + arrow = p + new Vector3( Mathf.Cos(ang+-2.5f), Mathf.Sin(ang+-2.5f), 0f)*0.5f; + Gizmos.DrawLine(p, arrow);*/ + + arrowTransform.position = p; + arrowTransform.LookAt( last, Vector3.forward ); + Vector3 to = arrowTransform.TransformDirection(Vector3.right); + // Debug.Log("to:"+to+" tweenEmpty.transform.position:"+arrowTransform.position); + Vector3 back = (last-p); + back = back.normalized; + Gizmos.DrawLine(p, p + (to + back)*arrowSize); + to = arrowTransform.TransformDirection(-Vector3.right); + Gizmos.DrawLine(p, p + (to + back)*arrowSize); + } + last = p; + } + + arrowTransform.position = beforePos; + arrowTransform.rotation = beforeQ; + }else{ + for(float k = 1.0f; k <= 30.0f; k++){ + t = k / 30.0f; + p = ((aa* t + (bb))* t + cc)* t + a; + Gizmos.DrawLine(last, p); + last = p; + } } } @@ -2915,6 +2540,7 @@ public static LTDescr options(LTDescr seed){ Debug.LogError("error this function public static LTDescr options(){ init(); + bool found = false; for(j=0, i = startSearch; j < maxTweens; i++){ if(i>=maxTweens-1) i = 0; @@ -2922,6 +2548,7 @@ public static LTDescr options(){ if(i+1>tweenMaxSearch) tweenMaxSearch = i+1; startSearch = i + 1; + found = true; break; } @@ -2929,12 +2556,13 @@ public static LTDescr options(){ if(j >= maxTweens) return logError("LeanTween - You have run out of available spaces for tweening. To avoid this error increase the number of spaces to available for tweening when you initialize the LeanTween class ex: LeanTween.init( "+(maxTweens*2)+" );") as LTDescr; } + if(found==false) + logError("no available tween found!"); + // Debug.Log("new tween with i:"+i+" counter:"+tweens[i].counter+" tweenMaxSearch:"+tweenMaxSearch+" tween:"+tweens[i]); tweens[i].reset(); tweens[i].setId( (uint)i ); - // Debug.Log("new tween with i:"+i+" counter:"+tweens[i].counter+" tweenMaxSearch:"+tweenMaxSearch+" tween:"+tweens[i]); - return tweens[i]; } @@ -2946,7 +2574,7 @@ public static GameObject tweenEmpty{ } public static int startSearch = 0; -public static LTDescr descr; +public static LTDescr d; private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, LTDescr tween ){ init(maxTweens); @@ -2962,6 +2590,24 @@ private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float ti return tween; } +#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 +/** +* Play a sequence of images on a Unity UI Object +* +* @method LeanTween.play +* @param {RectTransform} rectTransform:RectTransform RectTransform that you want to play the sequence of sprites on +* @param {Sprite[]} sprites:Sprite[] Sequence of sprites to be played +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example +* LeanTween.play(gameObject.GetComponent(), sprites).setLoopPingPong(); +*/ +public static LTDescr play(RectTransform rectTransform, UnityEngine.Sprite[] sprites){ + float defaultFrameRate = 0.25f; + float time = defaultFrameRate * sprites.Length; + return pushNewTween(rectTransform.gameObject, new Vector3((float)sprites.Length - 1.0f,0,0), time, TweenAction.CANVAS_PLAYSPRITE, options().setSprites( sprites ).setRepeat(-1)); +} +#endif + /** * Fade a gameobject's material to a certain alpha value. The material's shader needs to support alpha. Owl labs has some excellent efficient shaders. * @@ -3090,7 +2736,7 @@ public static LTDescr destroyAfter( LTRect rect, float delayTime){ * Move a GameObject to a certain location * * @method LeanTween.move -* @param {GameObject} GameObject gameObject Gameobject that you wish to move +* @param {GameObject} gameObject:GameObject Gameobject that you wish to move * @param {Vector3} vec:Vector3 to The final positin with which to move to * @param {float} time:float time The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween @@ -3119,13 +2765,27 @@ public static LTDescr move(GameObject gameObject, Vector2 to, float time){ * LeanTween.move(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);;
*/ public static LTDescr move(GameObject gameObject, Vector3[] to, float time){ - descr = options(); - if(descr.path==null) - descr.path = new LTBezierPath( to ); + d = options(); + if(d.path==null) + d.path = new LTBezierPath( to ); else - descr.path.setPoints( to ); + d.path.setPoints( to ); - return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED, descr ); + return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED, d ); +} + +public static LTDescr move(GameObject gameObject, LTBezierPath to, float time) { + d = options(); + d.path = to; + + return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED, d); +} + +public static LTDescr move(GameObject gameObject, LTSpline to, float time) { + d = options(); + d.spline = to; + + return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE, d); } /** @@ -3133,7 +2793,7 @@ public static LTDescr move(GameObject gameObject, Vector3[] to, float time){ * * @method LeanTween.moveSpline * @param {GameObject} gameObject:GameObject Gameobject that you wish to move -* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd +* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
Note: The first and last item just define the angle of the end points, they are not actually used in the spline path itself. If you do not care about the angle you can jus set the first two items and last two items as the same value. * @param {float} time:float The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween * @example @@ -3143,10 +2803,10 @@ public static LTDescr move(GameObject gameObject, Vector3[] to, float time){ * LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
*/ public static LTDescr moveSpline(GameObject gameObject, Vector3[] to, float time){ - descr = options(); - descr.spline = new LTSpline( to ); + d = options(); + d.spline = new LTSpline( to ); - return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE, descr ); + return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE, d ); } /** @@ -3164,10 +2824,10 @@ public static LTDescr moveSpline(GameObject gameObject, Vector3[] to, float time * LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
*/ public static LTDescr moveSplineLocal(GameObject gameObject, Vector3[] to, float time){ - descr = options(); - descr.spline = new LTSpline( to ); + d = options(); + d.spline = new LTSpline( to ); - return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, descr ); + return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, d ); } /** @@ -3255,13 +2915,13 @@ public static LTDescr moveLocal(GameObject gameObject, Vector3 to, float time){ * LeanTween.move(gameObject, new Vector3[]{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
*/ public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time){ - descr = options(); - if(descr.path==null) - descr.path = new LTBezierPath( to ); + d = options(); + if(d.path==null) + d.path = new LTBezierPath( to ); else - descr.path.setPoints( to ); + d.path.setPoints( to ); - return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED_LOCAL, descr ); + return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED_LOCAL, d ); } public static LTDescr moveLocalX(GameObject gameObject, float to, float time){ @@ -3276,6 +2936,19 @@ public static LTDescr moveLocalZ(GameObject gameObject, float to, float time){ return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_Z, options() ); } +public static LTDescr moveLocal(GameObject gameObject, LTBezierPath to, float time) { + d = options(); + d.path = to; + + return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED_LOCAL, d); +} +public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time) { + d = options(); + d.spline = to; + + return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, d); +} + /** * Rotate a GameObject, to values are in passed in degrees * @@ -3474,6 +3147,104 @@ public static LTDescr scaleZ(GameObject gameObject, float to, float time){ return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Z, options()); } +/** +* Tween any particular value (float) +* +* @method LeanTween.value (float) +* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to +* @param {float} from:float The original value to start the tween from +* @param {Vector3} to:float The final float with which to tween to +* @param {float} time:float The time to complete the tween in +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example +* Example Javascript:
+* LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( function( val:float ){
+*  Debug.Log("tweened val:"+val);
+* } );
+*
+* Example C#:
+* LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( (float val)=>{
+*  Debug.Log("tweened val:"+val);
+* } );
+*/ +public static LTDescr value(GameObject gameObject, float from, float to, float time){ + return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setFrom( new Vector3(from,0,0) ) ); +} + +/** +* Tween any particular value (Vector2) +* +* @method LeanTween.value (Vector2) +* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to +* @param {Vector2} from:Vector2 The original value to start the tween from +* @param {Vector3} to:Vector2 The final Vector2 with which to tween to +* @param {float} time:float The time to complete the tween in +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example +* Example Javascript:
+* LeanTween.value( gameObject, new Vector2(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( function( val:Vector2 ){
+*  Debug.Log("tweened val:"+val);
+* } );
+*
+* Example C#:
+* LeanTween.value( gameObject, new Vector3(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( (Vector2 val)=>{
+*  Debug.Log("tweened val:"+val);
+* } );
+*/ +public static LTDescr value(GameObject gameObject, Vector2 from, Vector2 to, float time){ + return pushNewTween( gameObject, new Vector3(to.x,to.y,0), time, TweenAction.VALUE3, options().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0) ) ); +} + +/** +* Tween any particular value (Vector3) +* +* @method LeanTween.value (Vector3) +* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to +* @param {Vector3} from:Vector3 The original value to start the tween from +* @param {Vector3} to:Vector3 The final Vector3 with which to tween to +* @param {float} time:float The time to complete the tween in +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example +* Example Javascript:
+* LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( function( val:Vector3 ){
+*  Debug.Log("tweened val:"+val);
+* } );
+*
+* Example C#:
+* LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( (Vector3 val)=>{
+*  Debug.Log("tweened val:"+val);
+* } );
+*/ +public static LTDescr value(GameObject gameObject, Vector3 from, Vector3 to, float time){ + return pushNewTween( gameObject, to, time, TweenAction.VALUE3, options().setFrom( from ) ); +} + +/** +* Tween any particular value (Color) +* +* @method LeanTween.value (Color) +* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to +* @param {Color} from:Color The original value to start the tween from +* @param {Color} to:Color The final Color with which to tween to +* @param {float} time:float The time to complete the tween in +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example +* Example Javascript:
+* LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( function( val:Color ){
+*  Debug.Log("tweened val:"+val);
+* } );
+*
+* Example C#:
+* LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( (Color val)=>{
+*  Debug.Log("tweened val:"+val);
+* } );
+*/ +public static LTDescr value(GameObject gameObject, Color from, Color to, float time){ + return pushNewTween( gameObject, new Vector3(1f, to.a, 0f), time, TweenAction.CALLBACK_COLOR, options().setPoint( new Vector3(to.r, to.g, to.b) ) + .setFromColor(from).setHasInitialized(false) + ); +} + /** * Tween any particular value, it does not need to be tied to any particular type or GameObject * @@ -3502,6 +3273,34 @@ public static LTDescr value(GameObject gameObject, Action callOnUpdate, f return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setTo( new Vector3(to,0,0) ).setFrom( new Vector3(from,0,0) ).setOnUpdate(callOnUpdate) ); } +/** +* Tweens any float value, it does not need to be tied to any particular type or GameObject +* +* @method LeanTween.value (float) +* @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject +* @param {Action} callOnUpdateRatio:Action Function that's called every Update frame. It must accept two float values ex: function updateValue( float val, float ratio){ } +* @param {float} float from The original value to start the tween from +* @param {float} float to The value to end the tween on +* @param {float} float time The time to complete the tween in +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example +* Example Javascript:
+* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
+* function updateValueExampleCallback( val:float, ratio:float ){
+*   Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);
+* }
+*
+* Example C#:
+* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
+* void updateValueExampleCallback( float val, float ratio ){
+*   Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);
+* }
+*/ + +public static LTDescr value(GameObject gameObject, Action callOnUpdateRatio, float from, float to, float time) { + return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.CALLBACK, options().setTo(new Vector3(to, 0, 0)).setFrom(new Vector3(from, 0, 0)).setOnUpdateRatio(callOnUpdateRatio)); +} + /** * Tween from one color to another * @@ -3532,7 +3331,7 @@ public static LTDescr value(GameObject gameObject, Action callOnUpdate, C } /** -* Tween any particular value (Vector2), this could be used to tween an arbitrary value like a material color +* Tween any particular value (Vector2), this could be used to tween an arbitrary value like offset property * * @method LeanTween.value (Vector2) * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to @@ -3543,11 +3342,11 @@ public static LTDescr value(GameObject gameObject, Action callOnUpdate, C * @return {LTDescr} LTDescr an object that distinguishes the tween */ public static LTDescr value(GameObject gameObject, Action callOnUpdate, Vector2 from, Vector2 to, float time){ - return pushNewTween( gameObject, new Vector3(to.x,to.y,0f), time, TweenAction.CALLBACK, options().setTo( new Vector3(to.x,to.y,0f) ).setFrom( from ).setOnUpdateVector2(callOnUpdate) ); + return pushNewTween( gameObject, new Vector3(to.x,to.y,0f), time, TweenAction.VALUE3, options().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0f) ).setOnUpdateVector2(callOnUpdate) ); } /** -* Tween any particular value (Vector3), this could be used to tween an arbitrary value like a material color +* Tween any particular value (Vector3), this could be used to tween an arbitrary property that uses a Vector * * @method LeanTween.value (Vector3) * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to @@ -3576,86 +3375,72 @@ public static LTDescr value(GameObject gameObject, Action callOnUp return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setTo( new Vector3(to,0,0) ).setFrom( new Vector3(from,0,0) ).setOnUpdateObject(callOnUpdate) ); } -/** -* Tween any particular value (float) -* -* @method LeanTween.value (float) -* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to -* @param {float} from:float The original value to start the tween from -* @param {Vector3} to:float The final float with which to tween to -* @param {float} time:float The time to complete the tween in -* @return {LTDescr} LTDescr an object that distinguishes the tween -*/ -public static LTDescr value(GameObject gameObject, float from, float to, float time){ - return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setFrom( new Vector3(from,0,0) ) ); +public static LTDescr delayedSound( AudioClip audio, Vector3 pos, float volume ){ + //Debug.LogError("Delay sound??"); + return pushNewTween( tweenEmpty, pos, 0f, TweenAction.DELAYED_SOUND, options().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) ); } -/** -* Tween any particular value (Vector2) +public static LTDescr delayedSound( GameObject gameObject, AudioClip audio, Vector3 pos, float volume ){ + //Debug.LogError("Delay sound??"); + return pushNewTween( gameObject, pos, 0f, TweenAction.DELAYED_SOUND, options().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) ); +} + +#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 + +/** +* Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) * -* @method LeanTween.value (Vector2) -* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to -* @param {Vector2} from:Vector2 The original value to start the tween from -* @param {Vector3} to:Vector2 The final Vector2 with which to tween to +* @method LeanTween.move (RectTransform) +* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to +* @param {Vector3} to:Vector3 The final Vector3 with which to tween to * @param {float} time:float The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween +* @example LeanTween.move(gameObject.GetComponent<RectTransform>(), new Vector3(200f,-100f,0f), 1f).setDelay(1f); */ -public static LTDescr value(GameObject gameObject, Vector2 from, Vector2 to, float time){ - return pushNewTween( gameObject, new Vector3(to.x,to.y,0), time, TweenAction.VALUE3, options().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0) ) ); +public static LTDescr move(RectTransform rectTrans, Vector3 to, float time){ + return pushNewTween( rectTrans.gameObject, to, time, TweenAction.CANVAS_MOVE, options().setRect( rectTrans ) ); } /** -* Tween any particular value (Vector3) +* Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) * -* @method LeanTween.value (Vector3) -* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to -* @param {Vector3} from:Vector3 The original value to start the tween from -* @param {Vector3} to:Vector3 The final Vector3 with which to tween to +* @method LeanTween.moveX (RectTransform) +* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to +* @param {float} to:float The final x location with which to tween to * @param {float} time:float The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween +* @example LeanTween.moveX(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f); */ -public static LTDescr value(GameObject gameObject, Vector3 from, Vector3 to, float time){ - return pushNewTween( gameObject, to, time, TweenAction.VALUE3, options().setFrom( from ) ); +public static LTDescr moveX(RectTransform rectTrans, float to, float time){ + return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_MOVE_X, options().setRect( rectTrans ) ); } /** -* Tween any particular value (Color) +* Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) * -* @method LeanTween.value (Color) -* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to -* @param {Color} from:Color The original value to start the tween from -* @param {Color} to:Color The final Color with which to tween to +* @method LeanTween.moveY (RectTransform) +* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to +* @param {float} to:float The final y location with which to tween to * @param {float} time:float The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween +* @example LeanTween.moveY(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f); */ -public static LTDescr value(GameObject gameObject, Color from, Color to, float time){ - return pushNewTween( gameObject, new Vector3(1f, to.a, 0f), time, TweenAction.CALLBACK_COLOR, options().setPoint( new Vector3(to.r, to.g, to.b) ) - .setFromColor(from).setHasInitialized(false) - ); -} - -public static LTDescr delayedSound( AudioClip audio, Vector3 pos, float volume ){ - return pushNewTween( tweenEmpty, pos, 0f, TweenAction.DELAYED_SOUND, options().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) ); -} - -public static LTDescr delayedSound( GameObject gameObject, AudioClip audio, Vector3 pos, float volume ){ - return pushNewTween( gameObject, pos, 0f, TweenAction.DELAYED_SOUND, options().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) ); +public static LTDescr moveY(RectTransform rectTrans, float to, float time){ + return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_MOVE_Y, options().setRect( rectTrans ) ); } -#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 - /** -* Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) +* Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) * -* @method LeanTween.move (RectTransform) +* @method LeanTween.moveZ (RectTransform) * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to -* @param {Vector3} to:Vector3 The final Vector3 with which to tween to +* @param {float} to:float The final x location with which to tween to * @param {float} time:float The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween -* @example LeanTween.move(gameObject.GetComponent<RectTransform>(), new Vector3(200f,-100f,0f), 1f).setDelay(1f); +* @example LeanTween.moveZ(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f); */ -public static LTDescr move(RectTransform rectTrans, Vector3 to, float time){ - return pushNewTween( rectTrans.gameObject, to, time, TweenAction.CANVAS_MOVE, options().setRect( rectTrans ) ); +public static LTDescr moveZ(RectTransform rectTrans, float to, float time){ + return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_MOVE_Z, options().setRect( rectTrans ) ); } /** @@ -3687,6 +3472,21 @@ public static LTDescr rotateAround(RectTransform rectTrans, Vector3 axis, float return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_ROTATEAROUND, options().setRect( rectTrans ).setAxis(axis) ); } +/** +* Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) +* +* @method LeanTween.rotateAroundLocal (RectTransform) +* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to +* @param {Vector3} axis:Vector3 The local axis in which to rotate the RectTransform (Vector3.forward is most commonly used) +* @param {float} to:float The degree with which to rotate the RectTransform +* @param {float} time:float The time to complete the tween in +* @return {LTDescr} LTDescr an object that distinguishes the tween +* @example LeanTween.rotateAroundLocal(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f); +*/ +public static LTDescr rotateAroundLocal(RectTransform rectTrans, Vector3 axis, float to, float time){ + return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_ROTATEAROUND_LOCAL, options().setRect( rectTrans ).setAxis(axis) ); +} + /** * Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) * @@ -3723,7 +3523,7 @@ public static LTDescr alpha(RectTransform rectTrans, float to, float time){ * @param {float} to:float The final Vector3 with which to tween to (localScale) * @param {float} time:float The time to complete the tween in * @return {LTDescr} LTDescr an object that distinguishes the tween -* @example LeanTween.alpha(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f); +* @example LeanTween.color(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f); */ public static LTDescr color(RectTransform rectTrans, Color to, float time){ return pushNewTween( rectTrans.gameObject, new Vector3(1.0f, to.a, 0.0f), time, TweenAction.CANVAS_COLOR, options().setRect( rectTrans ).setPoint( new Vector3(to.r, to.g, to.b) ) ); @@ -4123,511 +3923,1259 @@ public static int alpha(LTRect ltRect, float to, float time, Hashtable optional) if( optional==null || optional.Count == 0 ) optional = new Hashtable(); - ltRect.alphaEnabled = true; - optional["rect"] = ltRect; - return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, TweenAction.GUI_ALPHA, optional ); -} -public static int alpha(LTRect ltRect, float to, float time, object[] optional){ - return alpha( ltRect, to, time, h(optional) ); -} -public static int scaleX(GameObject gameObject, float to, float time, Hashtable optional){ - return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_X, optional ); -} -public static int scaleX(GameObject gameObject, float to, float time, object[] optional){ - return scaleX( gameObject, to, time, h(optional) ); -} -public static int scaleY(GameObject gameObject, float to, float time, Hashtable optional){ - return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Y, optional ); -} -public static int scaleY(GameObject gameObject, float to, float time, object[] optional){ - return scaleY( gameObject, to, time, h(optional) ); -} -public static int scaleZ(GameObject gameObject, float to, float time, Hashtable optional){ - return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Z, optional ); -} -public static int scaleZ(GameObject gameObject, float to, float time, object[] optional){ - return scaleZ( gameObject, to, time, h(optional) ); -} -public static int delayedCall( float delayTime, string callback, Hashtable optional ){ - init(); - return delayedCall( tweenEmpty, delayTime, callback, optional ); -} -public static int delayedCall( float delayTime, Action callback, object[] optional){ - init(); - return delayedCall( tweenEmpty, delayTime, callback, h(optional) ); -} -public static int delayedCall( GameObject gameObject, float delayTime, string callback, object[] optional){ - return delayedCall( gameObject, delayTime, callback, h(optional) ); -} -public static int delayedCall( GameObject gameObject, float delayTime, Action callback, object[] optional){ - return delayedCall( gameObject, delayTime, callback, h(optional) ); + ltRect.alphaEnabled = true; + optional["rect"] = ltRect; + return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, TweenAction.GUI_ALPHA, optional ); +} +public static int alpha(LTRect ltRect, float to, float time, object[] optional){ + return alpha( ltRect, to, time, h(optional) ); +} +public static int scaleX(GameObject gameObject, float to, float time, Hashtable optional){ + return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_X, optional ); +} +public static int scaleX(GameObject gameObject, float to, float time, object[] optional){ + return scaleX( gameObject, to, time, h(optional) ); +} +public static int scaleY(GameObject gameObject, float to, float time, Hashtable optional){ + return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Y, optional ); +} +public static int scaleY(GameObject gameObject, float to, float time, object[] optional){ + return scaleY( gameObject, to, time, h(optional) ); +} +public static int scaleZ(GameObject gameObject, float to, float time, Hashtable optional){ + return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Z, optional ); +} +public static int scaleZ(GameObject gameObject, float to, float time, object[] optional){ + return scaleZ( gameObject, to, time, h(optional) ); +} +public static int delayedCall( float delayTime, string callback, Hashtable optional ){ + init(); + return delayedCall( tweenEmpty, delayTime, callback, optional ); +} +public static int delayedCall( float delayTime, Action callback, object[] optional){ + init(); + return delayedCall( tweenEmpty, delayTime, callback, h(optional) ); +} +public static int delayedCall( GameObject gameObject, float delayTime, string callback, object[] optional){ + return delayedCall( gameObject, delayTime, callback, h(optional) ); +} +public static int delayedCall( GameObject gameObject, float delayTime, Action callback, object[] optional){ + return delayedCall( gameObject, delayTime, callback, h(optional) ); +} +public static int delayedCall( GameObject gameObject, float delayTime, string callback, Hashtable optional){ + if(optional==null || optional.Count == 0) + optional = new Hashtable(); + optional["onComplete"] = callback; + + return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional ); +} +public static int delayedCall( GameObject gameObject, float delayTime, Action callback, Hashtable optional){ + if(optional==null) + optional = new Hashtable(); + optional["onComplete"] = callback; + + return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional ); +} +public static int delayedCall( GameObject gameObject, float delayTime, Action callback, Hashtable optional){ + if(optional==null) + optional = new Hashtable(); + optional["onComplete"] = callback; + + return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional ); +} +public static int alpha(GameObject gameObject, float to, float time, Hashtable optional){ + return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ALPHA, optional ); +} +public static int alpha(GameObject gameObject, float to, float time, object[] optional){ + return alpha(gameObject, to, time, h(optional)); +} +#endif + +// Tweening Functions - Thanks to Robert Penner and GFX47 + +private static float tweenOnCurve( LTDescr tweenDescr, float ratioPassed ){ + // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed)); + return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed); +} + +private static Vector3 tweenOnCurveVector( LTDescr tweenDescr, float ratioPassed ){ + return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed), + tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.animationCurve.Evaluate(ratioPassed), + tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.animationCurve.Evaluate(ratioPassed) ); +} + +private static float easeOutQuadOpt( float start, float diff, float ratioPassed ){ + return -diff * ratioPassed * (ratioPassed - 2) + start; +} + +private static float easeInQuadOpt( float start, float diff, float ratioPassed ){ + return diff * ratioPassed * ratioPassed + start; +} + +private static float easeInOutQuadOpt( float start, float diff, float ratioPassed ){ + ratioPassed /= .5f; + if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start; + ratioPassed--; + return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start; +} + +private static float linear(float start, float end, float val){ + return Mathf.Lerp(start, end, val); +} + +private static float clerp(float start, float end, float val){ + float min = 0.0f; + float max = 360.0f; + float half = Mathf.Abs((max - min) / 2.0f); + float retval = 0.0f; + float diff = 0.0f; + if ((end - start) < -half){ + diff = ((max - start) + end) * val; + retval = start + diff; + }else if ((end - start) > half){ + diff = -((max - end) + start) * val; + retval = start + diff; + }else retval = start + (end - start) * val; + return retval; +} + +private static float spring(float start, float end, float val ){ + val = Mathf.Clamp01(val); + val = (Mathf.Sin(val * Mathf.PI * (0.2f + 2.5f * val * val * val)) * Mathf.Pow(1f - val, 2.2f ) + val) * (1f + (1.2f * (1f - val) )); + return start + (end - start) * val; +} + +private static float easeInQuad(float start, float end, float val){ + end -= start; + return end * val * val + start; +} + +private static float easeOutQuad(float start, float end, float val){ + end -= start; + return -end * val * (val - 2) + start; +} + +private static float easeInOutQuad(float start, float end, float val){ + val /= .5f; + end -= start; + if (val < 1) return end / 2 * val * val + start; + val--; + return -end / 2 * (val * (val - 2) - 1) + start; +} + +private static float easeInCubic(float start, float end, float val){ + end -= start; + return end * val * val * val + start; +} + +private static float easeOutCubic(float start, float end, float val){ + val--; + end -= start; + return end * (val * val * val + 1) + start; +} + +private static float easeInOutCubic(float start, float end, float val){ + val /= .5f; + end -= start; + if (val < 1) return end / 2 * val * val * val + start; + val -= 2; + return end / 2 * (val * val * val + 2) + start; +} + +private static float easeInQuart(float start, float end, float val){ + end -= start; + return end * val * val * val * val + start; +} + +private static float easeOutQuart(float start, float end, float val){ + val--; + end -= start; + return -end * (val * val * val * val - 1) + start; +} + +private static float easeInOutQuart(float start, float end, float val){ + val /= .5f; + end -= start; + if (val < 1) return end / 2 * val * val * val * val + start; + val -= 2; + return -end / 2 * (val * val * val * val - 2) + start; +} + +private static float easeInQuint(float start, float end, float val){ + end -= start; + return end * val * val * val * val * val + start; +} + +private static float easeOutQuint(float start, float end, float val){ + val--; + end -= start; + return end * (val * val * val * val * val + 1) + start; +} + +private static float easeInOutQuint(float start, float end, float val){ + val /= .5f; + end -= start; + if (val < 1) return end / 2 * val * val * val * val * val + start; + val -= 2; + return end / 2 * (val * val * val * val * val + 2) + start; +} + +private static float easeInSine(float start, float end, float val){ + end -= start; + return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start; +} + +private static float easeOutSine(float start, float end, float val){ + end -= start; + return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start; +} + +private static float easeInOutSine(float start, float end, float val){ + end -= start; + return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start; +} + +private static float easeInExpo(float start, float end, float val){ + end -= start; + return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start; +} + +private static float easeOutExpo(float start, float end, float val){ + end -= start; + return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start; +} + +private static float easeInOutExpo(float start, float end, float val){ + val /= .5f; + end -= start; + if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start; + val--; + return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start; +} + +private static float easeInCirc(float start, float end, float val){ + end -= start; + return -end * (Mathf.Sqrt(1 - val * val) - 1) + start; +} + +private static float easeOutCirc(float start, float end, float val){ + val--; + end -= start; + return end * Mathf.Sqrt(1 - val * val) + start; +} + +private static float easeInOutCirc(float start, float end, float val){ + val /= .5f; + end -= start; + if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start; + val -= 2; + return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start; +} + +private static float easeInBounce(float start, float end, float val){ + end -= start; + float d = 1f; + return end - easeOutBounce(0, end, d-val) + start; +} + +private static float easeOutBounce(float start, float end, float val){ + val /= 1f; + end -= start; + if (val < (1 / 2.75f)){ + return end * (7.5625f * val * val) + start; + }else if (val < (2 / 2.75f)){ + val -= (1.5f / 2.75f); + return end * (7.5625f * (val) * val + .75f) + start; + }else if (val < (2.5 / 2.75)){ + val -= (2.25f / 2.75f); + return end * (7.5625f * (val) * val + .9375f) + start; + }else{ + val -= (2.625f / 2.75f); + return end * (7.5625f * (val) * val + .984375f) + start; + } +} + +/*private static float easeOutBounce( float start, float end, float val, float overshoot = 1.0f ){ + end -= start; + float baseAmt = 2.75f * overshoot; + float baseAmt2 = baseAmt * baseAmt; + Debug.Log("val:"+val); // 1f, 0.75f, 0.5f, 0.25f, 0.125f + if (val < ((baseAmt-(baseAmt - 1f)) / baseAmt)){ // 0.36 + return end * (baseAmt2 * val * val) + start; // 1 - 1/1 + + }else if (val < ((baseAmt-0.75f) / baseAmt)){ // .72 + val -= ((baseAmt-(baseAmt - 1f - 0.5f)) / baseAmt); // 1.25f + return end * (baseAmt2 * val * val + .75f) + start; // 1 - 1/(4) + + }else if (val < ((baseAmt-(baseAmt - 1f - 0.5f - 0.25f)) / baseAmt)){ // .909 + val -= ((baseAmt-0.5f) / baseAmt); // 0.5 + return end * (baseAmt2 * val * val + .9375f) + start; // 1 - 1/(4*4) + + }else{ // x + // Debug.Log("else val:"+val); + val -= ((baseAmt-0.125f) / baseAmt); // 0.125 + return end * (baseAmt2 * val * val + .984375f) + start; // 1 - 1/(4*4*4) + + } +}*/ + +private static float easeInOutBounce(float start, float end, float val){ + end -= start; + float d= 1f; + if (val < d/2) return easeInBounce(0, end, val*2) * 0.5f + start; + else return easeOutBounce(0, end, val*2-d) * 0.5f + end*0.5f + start; +} + +private static float easeInBack(float start, float end, float val, float overshoot = 1.0f){ + end -= start; + val /= 1; + float s= 1.70158f * overshoot; + return end * (val) * val * ((s + 1) * val - s) + start; +} + +private static float easeOutBack(float start, float end, float val, float overshoot = 1.0f){ + float s = 1.70158f * overshoot; + end -= start; + val = (val / 1) - 1; + return end * ((val) * val * ((s + 1) * val + s) + 1) + start; +} + +private static float easeInOutBack(float start, float end, float val, float overshoot = 1.0f){ + float s = 1.70158f * overshoot; + end -= start; + val /= .5f; + if ((val) < 1){ + s *= (1.525f) * overshoot; + return end / 2 * (val * val * (((s) + 1) * val - s)) + start; + } + val -= 2; + s *= (1.525f) * overshoot; + return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start; +} + +private static float easeInElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){ + end -= start; + + float p = period; + float s = 0f; + float a = 0f; + + if (val == 0f) return start; + + if (val == 1f) return start + end; + + if (a == 0f || a < Mathf.Abs(end)){ + a = end; + s = p / 4f; + }else{ + s = p / (2f * Mathf.PI) * Mathf.Asin(end / a); + } + + if(overshoot>1f && val>0.6f ) + overshoot = 1f + ((1f-val) / 0.4f * (overshoot-1f)); + // Debug.Log("ease in elastic val:"+val+" a:"+a+" overshoot:"+overshoot); + + val = val-1f; + return start-(a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot; +} + +private static float easeOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){ + end -= start; + + float p = period; + float s = 0f; + float a = 0f; + + if (val == 0f) return start; + + // Debug.Log("ease out elastic val:"+val+" a:"+a); + if (val == 1f) return start + end; + + if (a == 0f || a < Mathf.Abs(end)){ + a = end; + s = p / 4f; + }else{ + s = p / (2f * Mathf.PI) * Mathf.Asin(end / a); + } + if(overshoot>1f && val<0.4f ) + overshoot = 1f + (val / 0.4f * (overshoot-1f)); + // Debug.Log("ease out elastic val:"+val+" a:"+a+" overshoot:"+overshoot); + + return start + end + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * overshoot; +} + +private static float easeInOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f) +{ + end -= start; + + float p = period; + float s = 0f; + float a = 0f; + + if (val == 0f) return start; + + val = val / (1f/2f); + if (val == 2f) return start + end; + + if (a == 0f || a < Mathf.Abs(end)){ + a = end; + s = p / 4f; + }else{ + s = p / (2f * Mathf.PI) * Mathf.Asin(end / a); + } + + if(overshoot>1f){ + if( val<0.2f ){ + overshoot = 1f + (val / 0.2f * (overshoot-1f)); + }else if( val > 0.8f ){ + overshoot = 1f + ((1f-val) / 0.2f * (overshoot-1f)); + } + } + + if (val < 1f){ + val = val-1f; + return start - 0.5f * (a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot; + } + val = val-1f; + return end + start + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * 0.5f * overshoot; +} + +// LeanTween Listening/Dispatch + +private static System.Action[] eventListeners; +private static GameObject[] goListeners; +private static int eventsMaxSearch = 0; +public static int EVENTS_MAX = 10; +public static int LISTENERS_MAX = 10; +private static int INIT_LISTENERS_MAX = LISTENERS_MAX; + +public static void addListener( int eventId, System.Action callback ){ + addListener(tweenEmpty, eventId, callback); +} + +/** +* Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called +* +* @method LeanTween.addListener +* @param {GameObject} caller:GameObject the gameObject the listener is attached to +* @param {int} eventId:int a unique int that describes the event (best to use an enum) +* @param {System.Action} callback:System.Action the method to call when the event has been dispatched +* @example +* LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);
+*
+* void jumpUp( LTEvent e ){ Debug.Log("jump!"); }
+*/ +public static void addListener( GameObject caller, int eventId, System.Action callback ){ + if(eventListeners==null){ + INIT_LISTENERS_MAX = LISTENERS_MAX; + eventListeners = new System.Action[ EVENTS_MAX * LISTENERS_MAX ]; + goListeners = new GameObject[ EVENTS_MAX * LISTENERS_MAX ]; + } + // Debug.Log("searching for an empty space for:"+caller + " eventid:"+event); + for(i = 0; i < INIT_LISTENERS_MAX; i++){ + int point = eventId*INIT_LISTENERS_MAX + i; + if(goListeners[ point ]==null || eventListeners[ point ]==null){ + eventListeners[ point ] = callback; + goListeners[ point ] = caller; + if(i>=eventsMaxSearch) + eventsMaxSearch = i+1; + // Debug.Log("adding event for:"+caller.name); + + return; + } + #if UNITY_FLASH + if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback)){ + // Debug.Log("This event is already being listened for."); + return; + } + #else + if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback)){ + // Debug.Log("This event is already being listened for."); + return; + } + #endif + } + Debug.LogError("You ran out of areas to add listeners, consider increasing INIT_LISTENERS_MAX, ex: LeanTween.INIT_LISTENERS_MAX = "+(INIT_LISTENERS_MAX*2)); +} + +public static bool removeListener( int eventId, System.Action callback ){ + return removeListener( tweenEmpty, eventId, callback); +} + +/** +* Remove an event listener you have added +* @method LeanTween.removeListener +* @param {GameObject} caller:GameObject the gameObject the listener is attached to +* @param {int} eventId:int a unique int that describes the event (best to use an enum) +* @param {System.Action} callback:System.Action the method that was specified to call when the event has been dispatched +* @example +* LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);
+*
+* void jumpUp( LTEvent e ){ }
+*/ +public static bool removeListener( GameObject caller, int eventId, System.Action callback ){ + for(i = 0; i < eventsMaxSearch; i++){ + int point = eventId*INIT_LISTENERS_MAX + i; + #if UNITY_FLASH + if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback) ){ + #else + if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback) ){ + #endif + eventListeners[ point ] = null; + goListeners[ point ] = null; + return true; + } + } + return false; +} + +/** +* Tell the added listeners that you are dispatching the event +* @method LeanTween.dispatchEvent +* @param {int} eventId:int a unique int that describes the event (best to use an enum) +* @example +* LeanTween.dispatchEvent( (int)MyEvents.JUMP );
+*/ +public static void dispatchEvent( int eventId ){ + dispatchEvent( eventId, null); +} + +/** +* Tell the added listeners that you are dispatching the event +* @method LeanTween.dispatchEvent +* @param {int} eventId:int a unique int that describes the event (best to use an enum) +* @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object +* @example +* LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );
+*
+* void jumpUp( LTEvent e ){
+*   Transform tran = (Transform)e.data;
+* }
+*/ +public static void dispatchEvent( int eventId, object data ){ + for(int k = 0; k < eventsMaxSearch; k++){ + int point = eventId*INIT_LISTENERS_MAX + k; + if(eventListeners[ point ]!=null){ + if(goListeners[point]){ + eventListeners[ point ]( new LTEvent(eventId, data) ); + }else{ + eventListeners[ point ] = null; + } + } + } +} + +} // End LeanTween class + +public class LTBezier { + public float length; + + private Vector3 a; + private Vector3 aa; + private Vector3 bb; + private Vector3 cc; + private float len; + private float[] arcLengths; + + public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision){ + this.a = a; + aa = (-a + 3*(b-c) + d); + bb = 3*(a+c) - 6*b; + cc = 3*(b-a); + + this.len = 1.0f / precision; + arcLengths = new float[(int)this.len + (int)1]; + arcLengths[0] = 0; + + Vector3 ov = a; + Vector3 v; + float clen = 0.0f; + for(int i = 1; i <= this.len; i++) { + v = bezierPoint(i * precision); + clen += (ov - v).magnitude; + this.arcLengths[i] = clen; + ov = v; + } + this.length = clen; + } + + private float map(float u) { + float targetLength = u * this.arcLengths[(int)this.len]; + int low = 0; + int high = (int)this.len; + int index = 0; + while (low < high) { + index = low + ((int)((high - low) / 2.0f) | 0); + if (this.arcLengths[index] < targetLength) { + low = index + 1; + } else { + high = index; + } + } + if(this.arcLengths[index] > targetLength) + index--; + if(index<0) + index = 0; + + return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len; + } + + private Vector3 bezierPoint(float t){ + return ((aa* t + (bb))* t + cc)* t + a; + } + + public Vector3 point(float t){ + return bezierPoint( map(t) ); + } +} + +/** +* Manually animate along a bezier path with this class +* @class LTBezierPath +* @constructor +* @param {Vector3 Array} pts A set of points that define one or many bezier paths (the paths should be passed in multiples of 4, which correspond to each individual bezier curve) +* @example +* LTBezierPath ltPath = new LTBezierPath( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(1f,0f,0f), new Vector3(1f,0f,0f), new Vector3(1f,1f,0f)} );

+* LeanTween.move(lt, ltPath.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
+* Vector3 pt = ltPath.point( 0.6f ); // retrieve a point along the path +*/ +public class LTBezierPath { + public Vector3[] pts; + public float length; + public bool orientToPath; + public bool orientToPath2d; + + private LTBezier[] beziers; + private float[] lengthRatio; + private int currentBezier=0,previousBezier=0; + + public LTBezierPath(){ } + public LTBezierPath( Vector3[] pts_ ){ + setPoints( pts_ ); + } + + public void setPoints( Vector3[] pts_ ){ + if(pts_.Length<4) + LeanTween.logError( "LeanTween - When passing values for a vector path, you must pass four or more values!" ); + if(pts_.Length%4!=0) + LeanTween.logError( "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..." ); + + pts = pts_; + + int k = 0; + beziers = new LTBezier[ pts.Length / 4 ]; + lengthRatio = new float[ beziers.Length ]; + int i; + length = 0; + for(i = 0; i < pts.Length; i+=4){ + beziers[k] = new LTBezier(pts[i+0],pts[i+2],pts[i+1],pts[i+3],0.05f); + length += beziers[k].length; + k++; + } + // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers); + for(i = 0; i < beziers.Length; i++){ + lengthRatio[i] = beziers[i].length / length; + } + } + + /** + * Retrieve a point along a path + * + * @method point + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @return {Vector3} Vector3 position of the point along the path + * @example + * transform.position = ltPath.point( 0.6f ); + */ + public Vector3 point( float ratio ){ + float added = 0.0f; + for(int i = 0; i < lengthRatio.Length; i++){ + added += lengthRatio[i]; + if(added >= ratio) + return beziers[i].point( (ratio-(added-lengthRatio[i])) / lengthRatio[i] ); + } + return beziers[lengthRatio.Length-1].point( 1.0f ); + } + + public void place2d( Transform transform, float ratio ){ + transform.position = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f){ + Vector3 v3Dir = point( ratio ) - transform.position; + float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg; + transform.eulerAngles = new Vector3(0, 0, angle); + } + } + + public void placeLocal2d( Transform transform, float ratio ){ + transform.localPosition = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f){ + Vector3 v3Dir = transform.parent.TransformPoint( point( ratio ) ) - transform.localPosition; + float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg; + transform.eulerAngles = new Vector3(0, 0, angle); + } + } + + /** + * Place an object along a certain point on the path (facing the direction perpendicular to the path) + * + * @method place + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @example + * ltPath.place( transform, 0.6f ); + */ + public void place( Transform transform, float ratio ){ + place( transform, ratio, Vector3.up ); + + } + + /** + * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path + * + * @method place + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * @example + * ltPath.place( transform, 0.6f, Vector3.left ); + */ + public void place( Transform transform, float ratio, Vector3 worldUp ){ + transform.position = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f) + transform.LookAt( point( ratio ), worldUp ); + + } + + /** + * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space + * + * @method placeLocal + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @example + * ltPath.placeLocal( transform, 0.6f ); + */ + public void placeLocal( Transform transform, float ratio ){ + placeLocal( transform, ratio, Vector3.up ); + } + + /** + * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space + * + * @method placeLocal + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * @example + * ltPath.placeLocal( transform, 0.6f, Vector3.left ); + */ + public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){ + transform.localPosition = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f) + transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp ); + } + + public void gizmoDraw(float t = -1.0f) + { + Vector3 prevPt = point(0); + + for (int i = 1; i <= 120; i++) + { + float pm = (float)i / 120f; + Vector3 currPt2 = point(pm); + //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1); + Gizmos.color = (previousBezier == currentBezier) ? Color.magenta : Color.grey; + Gizmos.DrawLine(currPt2, prevPt); + prevPt = currPt2; + previousBezier = currentBezier; + } + } } -public static int delayedCall( GameObject gameObject, float delayTime, string callback, Hashtable optional){ - if(optional==null || optional.Count == 0) - optional = new Hashtable(); - optional["onComplete"] = callback; - return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional ); -} -public static int delayedCall( GameObject gameObject, float delayTime, Action callback, Hashtable optional){ - if(optional==null) - optional = new Hashtable(); - optional["onComplete"] = callback; +/** +* Animate along a set of points that need to be in the format: controlPoint, point1, point2.... pointLast, endControlPoint +* @class LTSpline +* @constructor +* @param {Vector3 Array} pts A set of points that define the points the path will pass through (starting with starting control point, and ending with a control point) +* @example +* LTSpline ltSpline = new LTSpline( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(0f,0f,0f), new Vector3(0f,0.5f,0f), new Vector3(1f,1f,0f), new Vector3(1f,1f,0f)} );

+* LeanTween.moveSpline(lt, ltSpline.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
+* Vector3 pt = ltSpline.point( 0.6f ); // retrieve a point along the path +*/ +[System.Serializable] +public class LTSpline { + public static int DISTANCE_COUNT = 30; // increase for a more accurate constant speed + public static int SUBLINE_COUNT = 50; // increase for a more accurate smoothing of the curves into lines - return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional ); -} -public static int delayedCall( GameObject gameObject, float delayTime, Action callback, Hashtable optional){ - if(optional==null) - optional = new Hashtable(); - optional["onComplete"] = callback; + public Vector3[] pts; + public Vector3[] ptsAdj; + public int ptsAdjLength; + public bool orientToPath; + public bool orientToPath2d; + private int numSections; + private int currPt; + private float totalLength; + + public LTSpline(params Vector3[] pts) { + this.pts = new Vector3[pts.Length]; + System.Array.Copy(pts, this.pts, pts.Length); - return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional ); -} -public static int alpha(GameObject gameObject, float to, float time, Hashtable optional){ - return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ALPHA, optional ); -} -public static int alpha(GameObject gameObject, float to, float time, object[] optional){ - return alpha(gameObject, to, time, h(optional)); -} -#endif + numSections = pts.Length - 3; -// Tweening Functions - Thanks to Robert Penner and GFX47 + float minSegment = float.PositiveInfinity; + Vector3 earlierPoint = this.pts[1]; + float totalDistance = 0f; + for(int i=2; i < this.pts.Length-2; i++){ + float pointDistance = Vector3.Distance(this.pts[i], earlierPoint); + if(pointDistance < minSegment){ + minSegment = pointDistance; + } -private static float tweenOnCurve( LTDescr tweenDescr, float ratioPassed ){ - // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed)); - return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed); -} + totalDistance += pointDistance; + } -private static Vector3 tweenOnCurveVector( LTDescr tweenDescr, float ratioPassed ){ - return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed), - tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.animationCurve.Evaluate(ratioPassed), - tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.animationCurve.Evaluate(ratioPassed) ); -} + float minPrecision = minSegment / SUBLINE_COUNT; // number of subdivisions in each segment + int precision = (int)Mathf.Ceil(totalDistance / minPrecision) * DISTANCE_COUNT; -private static float easeOutQuadOpt( float start, float diff, float ratioPassed ){ - return -diff * ratioPassed * (ratioPassed - 2) + start; -} + ptsAdj = new Vector3[ precision ]; + earlierPoint = interp( 0f ); + int num = 0; + for(int i = 0; i < precision; i++){ + float fract = ((float)(i+1f)) / precision; + Vector3 point = interp( fract ); + float dist = Vector3.Distance(point, earlierPoint); + if(dist>=minPrecision){ + ptsAdj[num] = point; -private static float easeInQuadOpt( float start, float diff, float ratioPassed ){ - return diff * ratioPassed * ratioPassed + start; -} + earlierPoint = point; + // Debug.Log("fract:"+fract+" point:"+point); + num++; + } + } + // make sure there is a point at the very end + /*num++; + Vector3 endPoint = interp( 1f ); + ptsAdj[num] = endPoint;*/ + // Debug.Log("fract 1f endPoint:"+endPoint); -private static float easeInOutQuadOpt( float start, float diff, float ratioPassed ){ - ratioPassed /= .5f; - if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start; - ratioPassed--; - return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start; -} + ptsAdjLength = num; + // Debug.Log("map 1f:"+map(1f)+" end:"+ptsAdj[ ptsAdjLength-1 ]); -private static float linear(float start, float end, float val){ - return Mathf.Lerp(start, end, val); -} + // Debug.Log("ptsAdjLength:"+ptsAdjLength+" minPrecision:"+minPrecision+" precision:"+precision); -private static float clerp(float start, float end, float val){ - float min = 0.0f; - float max = 360.0f; - float half = Mathf.Abs((max - min) / 2.0f); - float retval = 0.0f; - float diff = 0.0f; - if ((end - start) < -half){ - diff = ((max - start) + end) * val; - retval = start + diff; - }else if ((end - start) > half){ - diff = -((max - end) + start) * val; - retval = start + diff; - }else retval = start + (end - start) * val; - return retval; -} + } -private static float spring(float start, float end, float val){ - val = Mathf.Clamp01(val); - val = (Mathf.Sin(val * Mathf.PI * (0.2f + 2.5f * val * val * val)) * Mathf.Pow(1f - val, 2.2f) + val) * (1f + (1.2f * (1f - val))); - return start + (end - start) * val; -} + public Vector3 map( float u ){ + if(u>=1f) + return pts[ pts.Length - 2]; + float t = u * (ptsAdjLength-1); + int first = (int)Mathf.Floor( t ); + int next = (int)Mathf.Ceil( t ); -private static float easeInQuad(float start, float end, float val){ - end -= start; - return end * val * val + start; -} + Vector3 val = ptsAdj[ first ]; + -private static float easeOutQuad(float start, float end, float val){ - end -= start; - return -end * val * (val - 2) + start; -} + Vector3 nextVal = ptsAdj[ next ]; + float diff = t - first; -private static float easeInOutQuad(float start, float end, float val){ - val /= .5f; - end -= start; - if (val < 1) return end / 2 * val * val + start; - val--; - return -end / 2 * (val * (val - 2) - 1) + start; -} + // Debug.Log("u:"+u+" val:"+val +" nextVal:"+nextVal+" diff:"+diff+" first:"+first+" next:"+next); -private static float easeInCubic(float start, float end, float val){ - end -= start; - return end * val * val * val + start; -} + val = val + (nextVal - val) * diff; -private static float easeOutCubic(float start, float end, float val){ - val--; - end -= start; - return end * (val * val * val + 1) + start; -} + return val; + } + + public Vector3 interp(float t) { + currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1); + float u = t * (float) numSections - (float) currPt; + + // Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length ); + Vector3 a = pts[currPt]; + Vector3 b = pts[currPt + 1]; + Vector3 c = pts[currPt + 2]; + Vector3 d = pts[currPt + 3]; + + return .5f * ( + (-a + 3f * b - 3f * c + d) * (u * u * u) + + (2f * a - 5f * b + 4f * c - d) * (u * u) + + (-a + c) * u + + 2f * b + ); + } -private static float easeInOutCubic(float start, float end, float val){ - val /= .5f; - end -= start; - if (val < 1) return end / 2 * val * val * val + start; - val -= 2; - return end / 2 * (val * val * val + 2) + start; -} + /** + * Retrieve a point along a path + * + * @method point + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @return {Vector3} Vector3 position of the point along the path + * @example + * transform.position = ltSpline.point( 0.6f ); + */ + public Vector3 point( float ratio ){ + float t = ratio>1f?1f:ratio; + + return map(t); + } + + public void place2d( Transform transform, float ratio ){ + transform.position = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f){ + Vector3 v3Dir = point( ratio ) - transform.position; + float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg; + transform.eulerAngles = new Vector3(0, 0, angle); + } + } + + public void placeLocal2d( Transform transform, float ratio ){ + transform.localPosition = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f){ + Vector3 v3Dir = transform.parent.TransformPoint( point( ratio ) ) - transform.localPosition; + float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg; + transform.eulerAngles = new Vector3(0, 0, angle); + } + } + + + /** + * Place an object along a certain point on the path (facing the direction perpendicular to the path) + * + * @method place + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @example + * ltPath.place( transform, 0.6f ); + */ + public void place( Transform transform, float ratio ){ + place(transform, ratio, Vector3.up); + } + + /** + * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path + * + * @method place + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * @example + * ltPath.place( transform, 0.6f, Vector3.left ); + */ + public void place( Transform transform, float ratio, Vector3 worldUp ){ + transform.position = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f) + transform.LookAt( point( ratio ), worldUp ); + + } -private static float easeInQuart(float start, float end, float val){ - end -= start; - return end * val * val * val * val + start; -} + /** + * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space + * + * @method placeLocal + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @example + * ltPath.placeLocal( transform, 0.6f ); + */ + public void placeLocal( Transform transform, float ratio ){ + placeLocal( transform, ratio, Vector3.up ); + } -private static float easeOutQuart(float start, float end, float val){ - val--; - end -= start; - return -end * (val * val * val * val - 1) + start; -} + /** + * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space + * + * @method placeLocal + * @param {Transform} transform:Transform the transform of the object you wish to place along the path + * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) + * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up + * @example + * ltPath.placeLocal( transform, 0.6f, Vector3.left ); + */ + public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){ + transform.localPosition = point( ratio ); + ratio += 0.001f; + if(ratio<=1.0f) + transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp ); + } + + public void gizmoDraw(float t = -1.0f) { + + Vector3 prevPt = point(0); + + for (int i = 1; i <= 120; i++) { + float pm = (float) i / 120f; + Vector3 currPt2 = point(pm); + //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1); + Gizmos.DrawLine(currPt2, prevPt); + prevPt = currPt2; + } + + } -private static float easeInOutQuart(float start, float end, float val){ - val /= .5f; - end -= start; - if (val < 1) return end / 2 * val * val * val * val + start; - val -= 2; - return -end / 2 * (val * val * val * val - 2) + start; -} + /*public Vector3 Velocity(float t) { + t = map( t ); -private static float easeInQuint(float start, float end, float val){ - end -= start; - return end * val * val * val * val * val + start; -} + int numSections = pts.Length - 3; + int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1); + float u = t * (float) numSections - (float) currPt; + + Vector3 a = pts[currPt]; + Vector3 b = pts[currPt + 1]; + Vector3 c = pts[currPt + 2]; + Vector3 d = pts[currPt + 3]; -private static float easeOutQuint(float start, float end, float val){ - val--; - end -= start; - return end * (val * val * val * val * val + 1) + start; + return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u) + + (2f * a -5f * b + 4f * c - d) * u + + .5f * c - .5f * a; + }*/ } -private static float easeInOutQuint(float start, float end, float val){ - val /= .5f; - end -= start; - if (val < 1) return end / 2 * val * val * val * val * val + start; - val -= 2; - return end / 2 * (val * val * val * val * val + 2) + start; -} +/** +* Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method

+* Example Javascript:
var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
+* LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );
+* function OnGUI(){
+*   if(GUI.Button(bRect.rect, "Scale")){ }
+* }
+*
+* Example C#:
+* LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
+* LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f );
+* void OnGUI(){
+*   if(GUI.Button(bRect.rect, "Scale")){ }
+* }
+* +* @class LTRect +* @constructor +* @param {float} x:float X location +* @param {float} y:float Y location +* @param {float} width:float Width +* @param {float} height:float Height +* @param {float} alpha:float (Optional) initial alpha amount (0-1) +* @param {float} rotation:float (Optional) initial rotation in degrees (0-360) +*/ -private static float easeInSine(float start, float end, float val){ - end -= start; - return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start; -} +[System.Serializable] +public class LTRect : System.Object{ + /** + * Pass this value to the GUI Methods + * + * @property rect + * @type {Rect} rect:Rect Rect object that controls the positioning and size + */ + public Rect _rect; + public float alpha = 1f; + public float rotation; + public Vector2 pivot; + public Vector2 margin; + public Rect relativeRect = new Rect(0f,0f,float.PositiveInfinity,float.PositiveInfinity); -private static float easeOutSine(float start, float end, float val){ - end -= start; - return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start; -} + public bool rotateEnabled; + [HideInInspector] + public bool rotateFinished; + public bool alphaEnabled; + public string labelStr; + public LTGUI.Element_Type type; + public GUIStyle style; + public bool useColor = false; + public Color color = Color.white; + public bool fontScaleToFit; + public bool useSimpleScale; + public bool sizeByHeight; -private static float easeInOutSine(float start, float end, float val){ - end -= start; - return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start; -} + public Texture texture; -private static float easeInExpo(float start, float end, float val){ - end -= start; - return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start; -} + private int _id = -1; + [HideInInspector] + public int counter; -private static float easeOutExpo(float start, float end, float val){ - end -= start; - return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start; -} + public static bool colorTouched; -private static float easeInOutExpo(float start, float end, float val){ - val /= .5f; - end -= start; - if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start; - val--; - return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start; -} + public LTRect(){ + reset(); + this.rotateEnabled = this.alphaEnabled = true; + _rect = new Rect(0f,0f,1f,1f); + } -private static float easeInCirc(float start, float end, float val){ - end -= start; - return -end * (Mathf.Sqrt(1 - val * val) - 1) + start; -} + public LTRect(Rect rect){ + _rect = rect; + reset(); + } -private static float easeOutCirc(float start, float end, float val){ - val--; - end -= start; - return end * Mathf.Sqrt(1 - val * val) + start; -} + public LTRect(float x, float y, float width, float height){ + _rect = new Rect(x,y,width,height); + this.alpha = 1.0f; + this.rotation = 0.0f; + this.rotateEnabled = this.alphaEnabled = false; + } -private static float easeInOutCirc(float start, float end, float val){ - val /= .5f; - end -= start; - if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start; - val -= 2; - return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start; -} + public LTRect(float x, float y, float width, float height, float alpha){ + _rect = new Rect(x,y,width,height); + this.alpha = alpha; + this.rotation = 0.0f; + this.rotateEnabled = this.alphaEnabled = false; + } -private static float easeInBounce(float start, float end, float val){ - end -= start; - float d = 1f; - return end - easeOutBounce(0, end, d-val) + start; -} + public LTRect(float x, float y, float width, float height, float alpha, float rotation){ + _rect = new Rect(x,y,width,height); + this.alpha = alpha; + this.rotation = rotation; + this.rotateEnabled = this.alphaEnabled = false; + if(rotation!=0.0f){ + this.rotateEnabled = true; + resetForRotation(); + } + } -private static float easeOutBounce(float start, float end, float val){ - val /= 1f; - end -= start; - if (val < (1 / 2.75f)){ - return end * (7.5625f * val * val) + start; - }else if (val < (2 / 2.75f)){ - val -= (1.5f / 2.75f); - return end * (7.5625f * (val) * val + .75f) + start; - }else if (val < (2.5 / 2.75)){ - val -= (2.25f / 2.75f); - return end * (7.5625f * (val) * val + .9375f) + start; - }else{ - val -= (2.625f / 2.75f); - return end * (7.5625f * (val) * val + .984375f) + start; + public bool hasInitiliazed{ + get{ + return _id!=-1; + } } -} -private static float easeInOutBounce(float start, float end, float val){ - end -= start; - float d= 1f; - if (val < d/2) return easeInBounce(0, end, val*2) * 0.5f + start; - else return easeOutBounce(0, end, val*2-d) * 0.5f + end*0.5f + start; -} + public int id{ + get{ + int toId = _id | counter << 16; -private static float easeInBack(float start, float end, float val){ - end -= start; - val /= 1; - float s= 1.70158f; - return end * (val) * val * ((s + 1) * val - s) + start; -} + /*uint backId = toId & 0xFFFF; + uint backCounter = toId >> 16; + if(_id!=backId || backCounter!=counter){ + Debug.LogError("BAD CONVERSION toId:"+_id); + }*/ + + return toId; + } + } -private static float easeOutBack(float start, float end, float val){ - float s= 1.70158f; - end -= start; - val = (val / 1) - 1; - return end * ((val) * val * ((s + 1) * val + s) + 1) + start; -} + public void setId( int id, int counter){ + this._id = id; + this.counter = counter; + } -private static float easeInOutBack(float start, float end, float val){ - float s= 1.70158f; - end -= start; - val /= .5f; - if ((val) < 1){ - s *= (1.525f); - return end / 2 * (val * val * (((s) + 1) * val - s)) + start; + public void reset(){ + this.alpha = 1.0f; + this.rotation = 0.0f; + this.rotateEnabled = this.alphaEnabled = false; + this.margin = Vector2.zero; + this.sizeByHeight = false; + this.useColor = false; } - val -= 2; - s *= (1.525f); - return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start; -} -private static float easeInElastic(float start, float end, float val){ - end -= start; - - float d = 1f; - float p = d * .3f; - float s= 0; - float a = 0; - - if (val == 0) return start; - val = val/d; - if (val == 1) return start + end; - - if (a == 0f || a < Mathf.Abs(end)){ - a = end; - s = p / 4; - }else{ - s = p / (2 * Mathf.PI) * Mathf.Asin(end / a); + public void resetForRotation(){ + Vector3 scale = new Vector3(GUI.matrix[0,0], GUI.matrix[1,1], GUI.matrix[2,2]); + if(pivot==Vector2.zero){ + pivot = new Vector2((_rect.x+((_rect.width)*0.5f )) * scale.x + GUI.matrix[0,3], (_rect.y+((_rect.height)*0.5f )) * scale.y + GUI.matrix[1,3]); + } } - val = val-1; - return -(a * Mathf.Pow(2, 10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p)) + start; -} -private static float easeOutElastic(float start, float end, float val){ - end -= start; - - float d = 1f; - float p= d * .3f; - float s= 0; - float a= 0; - - if (val == 0) return start; - - val = val / d; - if (val == 1) return start + end; - - if (a == 0f || a < Mathf.Abs(end)){ - a = end; - s = p / 4; - }else{ - s = p / (2 * Mathf.PI) * Mathf.Asin(end / a); + public float x{ + get{ return _rect.x; } + set{ _rect.x = value; } } - - return (a * Mathf.Pow(2, -10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p) + end + start); -} -private static float easeInOutElastic(float start, float end, float val) -{ - end -= start; - - float d = 1f; - float p= d * .3f; - float s= 0; - float a = 0; - - if (val == 0) return start; - - val = val / (d/2); - if (val == 2) return start + end; - - if (a == 0f || a < Mathf.Abs(end)){ - a = end; - s = p / 4; - }else{ - s = p / (2 * Mathf.PI) * Mathf.Asin(end / a); + public float y{ + get{ return _rect.y; } + set{ _rect.y = value; } } - - if (val < 1){ - val = val-1; - return -0.5f * (a * Mathf.Pow(2, 10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p)) + start; + + public float width{ + get{ return _rect.width; } + set{ _rect.width = value; } } - val = val-1; - return a * Mathf.Pow(2, -10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p) * 0.5f + end + start; -} -// LeanTween Listening/Dispatch + public float height{ + get{ return _rect.height; } + set{ _rect.height = value; } + } -private static System.Action[] eventListeners; -private static GameObject[] goListeners; -private static int eventsMaxSearch = 0; -public static int EVENTS_MAX = 10; -public static int LISTENERS_MAX = 10; -private static int INIT_LISTENERS_MAX = LISTENERS_MAX; + public Rect rect{ -public static void addListener( int eventId, System.Action callback ){ - addListener(tweenEmpty, eventId, callback); -} + get{ + if(colorTouched){ + colorTouched = false; + GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,1.0f); + } + if(rotateEnabled){ + if(rotateFinished){ + rotateFinished = false; + rotateEnabled = false; + //this.rotation = 0.0f; + pivot = Vector2.zero; + }else{ + GUIUtility.RotateAroundPivot(rotation, pivot); + } + } + if(alphaEnabled){ + GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,alpha); + colorTouched = true; + } + if(fontScaleToFit){ + if(this.useSimpleScale){ + style.fontSize = (int)(_rect.height*this.relativeRect.height); + }else{ + style.fontSize = (int)_rect.height; + } + } + return _rect; + } -/** -* Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called -* -* @method LeanTween.addListener -* @param {GameObject} caller:GameObject the gameObject the listener is attached to -* @param {int} eventId:int a unique int that describes the event (best to use an enum) -* @param {System.Action} callback:System.Action the method to call when the event has been dispatched -* @example -* LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);
-*
-* void jumpUp( LTEvent e ){ Debug.Log("jump!"); }
-*/ -public static void addListener( GameObject caller, int eventId, System.Action callback ){ - if(eventListeners==null){ - INIT_LISTENERS_MAX = LISTENERS_MAX; - eventListeners = new System.Action[ EVENTS_MAX * LISTENERS_MAX ]; - goListeners = new GameObject[ EVENTS_MAX * LISTENERS_MAX ]; + set{ + _rect = value; + } } - // Debug.Log("searching for an empty space for:"+caller + " eventid:"+event); - for(i = 0; i < INIT_LISTENERS_MAX; i++){ - int point = eventId*INIT_LISTENERS_MAX + i; - if(goListeners[ point ]==null || eventListeners[ point ]==null){ - eventListeners[ point ] = callback; - goListeners[ point ] = caller; - if(i>=eventsMaxSearch) - eventsMaxSearch = i+1; - // Debug.Log("adding event for:"+caller.name); - return; - } - #if UNITY_FLASH - if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback)){ - // Debug.Log("This event is already being listened for."); - return; - } - #else - if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback)){ - // Debug.Log("This event is already being listened for."); - return; - } - #endif + public LTRect setStyle( GUIStyle style ){ + this.style = style; + return this; } - Debug.LogError("You ran out of areas to add listeners, consider increasing INIT_LISTENERS_MAX, ex: LeanTween.INIT_LISTENERS_MAX = "+(INIT_LISTENERS_MAX*2)); -} -public static bool removeListener( int eventId, System.Action callback ){ - return removeListener( tweenEmpty, eventId, callback); -} + public LTRect setFontScaleToFit( bool fontScaleToFit ){ + this.fontScaleToFit = fontScaleToFit; + return this; + } -/** -* Remove an event listener you have added -* @method LeanTween.removeListener -* @param {GameObject} caller:GameObject the gameObject the listener is attached to -* @param {int} eventId:int a unique int that describes the event (best to use an enum) -* @param {System.Action} callback:System.Action the method that was specified to call when the event has been dispatched -* @example -* LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);
-*
-* void jumpUp( LTEvent e ){ }
-*/ -public static bool removeListener( GameObject caller, int eventId, System.Action callback ){ - for(i = 0; i < eventsMaxSearch; i++){ - int point = eventId*INIT_LISTENERS_MAX + i; - #if UNITY_FLASH - if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback) ){ - #else - if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback) ){ - #endif - eventListeners[ point ] = null; - goListeners[ point ] = null; - return true; - } + public LTRect setColor( Color color ){ + this.color = color; + this.useColor = true; + return this; } - return false; -} -/** -* Tell the added listeners that you are dispatching the event -* @method LeanTween.dispatchEvent -* @param {int} eventId:int a unique int that describes the event (best to use an enum) -* @example -* LeanTween.dispatchEvent( (int)MyEvents.JUMP );
-*/ -public static void dispatchEvent( int eventId ){ - dispatchEvent( eventId, null); -} + public LTRect setAlpha( float alpha ){ + this.alpha = alpha; + return this; + } -/** -* Tell the added listeners that you are dispatching the event -* @method LeanTween.dispatchEvent -* @param {int} eventId:int a unique int that describes the event (best to use an enum) -* @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object -* @example -* LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );
-*
-* void jumpUp( LTEvent e ){
-*   Transform tran = (Transform)e.data;
-* }
-*/ -public static void dispatchEvent( int eventId, object data ){ - for(int k = 0; k < eventsMaxSearch; k++){ - int point = eventId*INIT_LISTENERS_MAX + k; - if(eventListeners[ point ]!=null){ - if(goListeners[point]){ - eventListeners[ point ]( new LTEvent(eventId, data) ); - }else{ - eventListeners[ point ] = null; - } - } + public LTRect setLabel( String str ){ + this.labelStr = str; + return this; + } + + public LTRect setUseSimpleScale( bool useSimpleScale, Rect relativeRect){ + this.useSimpleScale = useSimpleScale; + this.relativeRect = relativeRect; + return this; + } + + public LTRect setUseSimpleScale( bool useSimpleScale){ + this.useSimpleScale = useSimpleScale; + this.relativeRect = new Rect(0f,0f,Screen.width,Screen.height); + return this; } -} + public LTRect setSizeByHeight( bool sizeByHeight){ + this.sizeByHeight = sizeByHeight; + return this; + } + + public override string ToString(){ + return "x:"+_rect.x+" y:"+_rect.y+" width:"+_rect.width+" height:"+_rect.height; + } } /** @@ -4636,7 +5184,7 @@ public static void dispatchEvent( int eventId, object data ){ * @constructor * @param {object} data:object Data that has been passed from the dispatchEvent method */ -public class LTEvent{ +public class LTEvent { public int id; public object data; @@ -4646,7 +5194,7 @@ public class LTEvent{ } } -public class LTGUI{ +public class LTGUI { public static int RECT_LEVELS = 5; public static int RECTS_PER_LEVEL = 10; public static int BUTTONS_MAX = 24; diff --git a/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs.meta b/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs.meta index 13d23f82..7f4fba2c 100644 --- a/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs.meta +++ b/Assets/Fungus/Thirdparty/LeanTween/LeanTween.cs.meta @@ -1,8 +1,12 @@ fileFormatVersion: 2 guid: 9c2f4b27196f84954b44753aaac214bb +timeCreated: 1445946121 +licenseType: Store MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Thirdparty/LeanTween/ReadMe.txt b/Assets/Fungus/Thirdparty/LeanTween/ReadMe.txt new file mode 100644 index 00000000..49687ded --- /dev/null +++ b/Assets/Fungus/Thirdparty/LeanTween/ReadMe.txt @@ -0,0 +1,9 @@ +LeanTween is an efficient tweening engine for Unity3d + +Full Documentation: + http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html + This can also be accessed offline! From the Unity menu Help->LeanTween Documentation + +Getting Started + + There are many examples included! Look in the “LeanTween/LeanTweenExamples" folder to see many of the methods outlined. diff --git a/Assets/Fungus/Thirdparty/LeanTween/ReadMe.txt.meta b/Assets/Fungus/Thirdparty/LeanTween/ReadMe.txt.meta new file mode 100644 index 00000000..c08c74a3 --- /dev/null +++ b/Assets/Fungus/Thirdparty/LeanTween/ReadMe.txt.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f1e0da947b69648fdb1884d602088d92 diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 794c061b..5a96ca8a 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -22,7 +22,7 @@ GraphicsSettings: - {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_ShaderSettings: - useScreenSpaceShadows: 0 + useScreenSpaceShadows: 1 m_BuildTargetShaderSettings: [] m_LightmapStripping: 0 m_FogStripping: 0