//namespace DentedPixel{
using System;
using UnityEngine;
/**
* 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.
*
* 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
*/
namespace GameLogic
{
public class LTDescr
{
public bool toggle;
public bool useEstimatedTime;
public bool useFrames;
public bool useManualTime;
public bool usesNormalDt;
public bool hasInitiliazed;
public bool hasExtraOnCompletes;
public bool hasPhysics;
public bool onCompleteOnRepeat;
public bool onCompleteOnStart;
public bool useRecursion;
public float ratioPassed;
public float passed;
public float delay;
public float time;
public float speed;
public float lastVal;
private uint _id;
public int loopCount;
public uint counter = uint.MaxValue;
public float direction;
public float directionLast;
public float overshoot;
public float period;
public float scale;
public bool destroyOnComplete;
public Transform trans;
internal Vector3 fromInternal;
public Vector3 from
{
get { return this.fromInternal; }
set { this.fromInternal = value; }
}
internal Vector3 toInternal;
public Vector3 to
{
get { return this.toInternal; }
set { this.toInternal = value; }
}
internal Vector3 diff;
internal Vector3 diffDiv2;
public TweenAction type;
private LeanTweenType easeType;
public LeanTweenType loopType;
public bool hasUpdateCallback;
public EaseTypeDelegate easeMethod;
public ActionMethodDelegate easeInternal { get; set; }
public ActionMethodDelegate initInternal { get; set; }
public delegate Vector3 EaseTypeDelegate();
public delegate void ActionMethodDelegate();
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
public SpriteRenderer spriteRen;
#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.UI.RawImage rawImage;
public UnityEngine.Sprite[] sprites;
#endif
public LTDescrOptional _optional = new LTDescrOptional();
public override string ToString()
{
return (trans != null ? "name:" + trans.gameObject.name : "gameObject:null") + " toggle:" + toggle +
" passed:" + passed + " time:" + time + " delay:" + delay + " direction:" + direction + " from:" +
from + " to:" + to + " diff:" + diff + " type:" + type + " ease:" + easeType + " useEstimatedTime:" +
useEstimatedTime + " id:" + id + " hasInitiliazed:" + hasInitiliazed;
}
public LTDescr()
{
}
[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 int uniqueId
{
get
{
uint toId = _id | counter << 16;
/*uint backId = toId & 0xFFFF;
uint backCounter = toId >> 16;
if(_id!=backId || backCounter!=counter){
Debug.LogError("BAD CONVERSION toId:"+_id);
}*/
return (int) toId;
}
}
public int id
{
get { return uniqueId; }
}
public LTDescrOptional optional
{
get { return _optional; }
set { this._optional = value; }
}
public void reset()
{
this.toggle = this.useRecursion = this.usesNormalDt = true;
this.trans = null;
this.spriteRen = 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 = this.hasExtraOnCompletes = false;
this.easeType = LeanTweenType.linear;
this.loopType = LeanTweenType.once;
this.loopCount = 0;
this.direction = this.directionLast = this.overshoot = this.scale = 1.0f;
this.period = 0.3f;
this.speed = -1f;
this.easeMethod = this.easeLinear;
this.from = this.to = Vector3.zero;
this._optional.reset();
}
// Initialize and Internal Methods
public LTDescr setMoveX()
{
this.type = TweenAction.MOVE_X;
this.initInternal = () => { this.fromInternal.x = trans.position.x; };
this.easeInternal =
() => { trans.position = new Vector3(easeMethod().x, trans.position.y, trans.position.z); };
return this;
}
public LTDescr setMoveY()
{
this.type = TweenAction.MOVE_Y;
this.initInternal = () => { this.fromInternal.x = trans.position.y; };
this.easeInternal =
() => { trans.position = new Vector3(trans.position.x, easeMethod().x, trans.position.z); };
return this;
}
public LTDescr setMoveZ()
{
this.type = TweenAction.MOVE_Z;
this.initInternal = () => { this.fromInternal.x = trans.position.z; };
;
this.easeInternal =
() => { trans.position = new Vector3(trans.position.x, trans.position.y, easeMethod().x); };
return this;
}
public LTDescr setMoveLocalX()
{
this.type = TweenAction.MOVE_LOCAL_X;
this.initInternal = () => { this.fromInternal.x = trans.localPosition.x; };
this.easeInternal =
() =>
{
trans.localPosition = new Vector3(easeMethod().x, trans.localPosition.y, trans.localPosition.z);
};
return this;
}
public LTDescr setMoveLocalY()
{
this.type = TweenAction.MOVE_LOCAL_Y;
this.initInternal = () => { this.fromInternal.x = trans.localPosition.y; };
this.easeInternal =
() =>
{
trans.localPosition = new Vector3(trans.localPosition.x, easeMethod().x, trans.localPosition.z);
};
return this;
}
public LTDescr setMoveLocalZ()
{
this.type = TweenAction.MOVE_LOCAL_Z;
this.initInternal = () => { this.fromInternal.x = trans.localPosition.z; };
this.easeInternal =
() =>
{
trans.localPosition = new Vector3(trans.localPosition.x, trans.localPosition.y, easeMethod().x);
};
return this;
}
private void initFromInternal()
{
this.fromInternal.x = 0;
}
public LTDescr setMoveCurved()
{
this.type = TweenAction.MOVE_CURVED;
this.initInternal = this.initFromInternal;
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
if (this._optional.path.orientToPath)
{
if (this._optional.path.orientToPath2d)
{
this._optional.path.place2d(trans, val);
}
else
{
this._optional.path.place(trans, val);
}
}
else
{
trans.position = this._optional.path.point(val);
}
};
return this;
}
public LTDescr setMoveCurvedLocal()
{
this.type = TweenAction.MOVE_CURVED_LOCAL;
this.initInternal = this.initFromInternal;
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
if (this._optional.path.orientToPath)
{
if (this._optional.path.orientToPath2d)
{
this._optional.path.placeLocal2d(trans, val);
}
else
{
this._optional.path.placeLocal(trans, val);
}
}
else
{
trans.localPosition = this._optional.path.point(val);
}
};
return this;
}
public LTDescr setMoveSpline()
{
this.type = TweenAction.MOVE_SPLINE;
this.initInternal = this.initFromInternal;
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
if (this._optional.spline.orientToPath)
{
if (this._optional.spline.orientToPath2d)
{
this._optional.spline.place2d(trans, val);
}
else
{
this._optional.spline.place(trans, val);
}
}
else
{
trans.position = this._optional.spline.point(val);
}
};
return this;
}
public LTDescr setMoveSplineLocal()
{
this.type = TweenAction.MOVE_SPLINE_LOCAL;
this.initInternal = this.initFromInternal;
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
if (this._optional.spline.orientToPath)
{
if (this._optional.spline.orientToPath2d)
{
this._optional.spline.placeLocal2d(trans, val);
}
else
{
this._optional.spline.placeLocal(trans, val);
}
}
else
{
trans.localPosition = this._optional.spline.point(val);
}
};
return this;
}
public LTDescr setScaleX()
{
this.type = TweenAction.SCALE_X;
this.initInternal = () => { this.fromInternal.x = trans.localScale.x; };
this.easeInternal =
() => { trans.localScale = new Vector3(easeMethod().x, trans.localScale.y, trans.localScale.z); };
return this;
}
public LTDescr setScaleY()
{
this.type = TweenAction.SCALE_Y;
this.initInternal = () => { this.fromInternal.x = trans.localScale.y; };
this.easeInternal =
() => { trans.localScale = new Vector3(trans.localScale.x, easeMethod().x, trans.localScale.z); };
return this;
}
public LTDescr setScaleZ()
{
this.type = TweenAction.SCALE_Z;
this.initInternal = () => { this.fromInternal.x = trans.localScale.z; };
this.easeInternal =
() => { trans.localScale = new Vector3(trans.localScale.x, trans.localScale.y, easeMethod().x); };
return this;
}
public LTDescr setRotateX()
{
this.type = TweenAction.ROTATE_X;
this.initInternal = () =>
{
this.fromInternal.x = trans.eulerAngles.x;
this.toInternal.x = LeanTween.closestRot(this.fromInternal.x, this.toInternal.x);
};
this.easeInternal =
() => { trans.eulerAngles = new Vector3(easeMethod().x, trans.eulerAngles.y, trans.eulerAngles.z); };
return this;
}
public LTDescr setRotateY()
{
this.type = TweenAction.ROTATE_Y;
this.initInternal = () =>
{
this.fromInternal.x = trans.eulerAngles.y;
this.toInternal.x = LeanTween.closestRot(this.fromInternal.x, this.toInternal.x);
};
this.easeInternal =
() => { trans.eulerAngles = new Vector3(trans.eulerAngles.x, easeMethod().x, trans.eulerAngles.z); };
return this;
}
public LTDescr setRotateZ()
{
this.type = TweenAction.ROTATE_Z;
this.initInternal = () =>
{
this.fromInternal.x = trans.eulerAngles.z;
this.toInternal.x = LeanTween.closestRot(this.fromInternal.x, this.toInternal.x);
};
this.easeInternal =
() => { trans.eulerAngles = new Vector3(trans.eulerAngles.x, trans.eulerAngles.y, easeMethod().x); };
return this;
}
public LTDescr setRotateAround()
{
this.type = TweenAction.ROTATE_AROUND;
this.initInternal = () =>
{
this.fromInternal.x = 0f;
this._optional.origRotation = trans.rotation;
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Vector3 origPos = trans.localPosition;
Vector3 rotateAroundPt = (Vector3) trans.TransformPoint(this._optional.point);
// Debug.Log("this._optional.point:"+this._optional.point);
trans.RotateAround(rotateAroundPt, this._optional.axis, -this._optional.lastVal);
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 = this._optional.origRotation;
rotateAroundPt = (Vector3) trans.TransformPoint(this._optional.point);
trans.RotateAround(rotateAroundPt, this._optional.axis, val);
this._optional.lastVal = val;
};
return this;
}
public LTDescr setRotateAroundLocal()
{
this.type = TweenAction.ROTATE_AROUND_LOCAL;
this.initInternal = () =>
{
this.fromInternal.x = 0f;
this._optional.origRotation = trans.localRotation;
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Vector3 origPos = trans.localPosition;
trans.RotateAround((Vector3) trans.TransformPoint(this._optional.point),
trans.TransformDirection(this._optional.axis), -this._optional.lastVal);
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.localRotation = this._optional.origRotation;
Vector3 rotateAroundPt = (Vector3) trans.TransformPoint(this._optional.point);
trans.RotateAround(rotateAroundPt, trans.TransformDirection(this._optional.axis), val);
this._optional.lastVal = val;
};
return this;
}
public LTDescr setAlpha()
{
this.type = TweenAction.ALPHA;
this.initInternal = () =>
{
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
if(trans.gameObject.renderer){ this.fromInternal.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.fromInternal.x = col.a; break; }}}
this.easeInternal = this.alpha;
break;
#else
SpriteRenderer ren = trans.GetComponent();
if (ren != null)
{
this.fromInternal.x = ren.color.a;
}
else
{
if (trans.GetComponent() != null &&
trans.GetComponent().material.HasProperty("_Color"))
{
this.fromInternal.x = trans.GetComponent().material.color.a;
}
else if (trans.GetComponent() != null &&
trans.GetComponent().material.HasProperty("_TintColor"))
{
Color col = trans.GetComponent().material.GetColor("_TintColor");
this.fromInternal.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.fromInternal.x = col.a;
break;
}
}
}
}
#endif
this.easeInternal = () =>
{
val = easeMethod().x;
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
alphaRecursive(this.trans, val, this.useRecursion);
#else
if (this.spriteRen != null)
{
this.spriteRen.color = new Color(this.spriteRen.color.r, this.spriteRen.color.g,
this.spriteRen.color.b, val);
alphaRecursiveSprite(this.trans, val);
}
else
{
alphaRecursive(this.trans, val, this.useRecursion);
}
#endif
};
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
alphaRecursive(this.trans, val, this.useRecursion);
#else
if (this.spriteRen != null)
{
this.spriteRen.color = new Color(this.spriteRen.color.r, this.spriteRen.color.g,
this.spriteRen.color.b, val);
alphaRecursiveSprite(this.trans, val);
}
else
{
alphaRecursive(this.trans, val, this.useRecursion);
}
#endif
};
return this;
}
public LTDescr setTextAlpha()
{
this.type = TweenAction.TEXT_ALPHA;
this.initInternal = () =>
{
this.uiText = trans.GetComponent();
this.fromInternal.x = this.uiText != null ? this.uiText.color.a : 1f;
};
this.easeInternal = () => { textAlphaRecursive(trans, easeMethod().x, this.useRecursion); };
return this;
}
public LTDescr setAlphaVertex()
{
this.type = TweenAction.ALPHA_VERTEX;
this.initInternal = () => { this.fromInternal.x = trans.GetComponent().mesh.colors32[0].a; };
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Mesh mesh = trans.GetComponent().mesh;
Vector3[] vertices = mesh.vertices;
Color32[] colors = new Color32[vertices.Length];
if (colors.Length == 0)
{
//MaxFW fix: add vertex colors if the mesh doesn't have any
Color32 transparentWhiteColor32 = new Color32(0xff, 0xff, 0xff, 0x00);
colors = new Color32[mesh.vertices.Length];
for (int k = 0; k < colors.Length; k++)
colors[k] = transparentWhiteColor32;
mesh.colors32 = colors;
} // fix end
Color32 c = mesh.colors32[0];
c = new Color(c.r, c.g, c.b, val);
for (int k = 0; k < vertices.Length; k++)
colors[k] = c;
mesh.colors32 = colors;
};
return this;
}
public LTDescr setColor()
{
this.type = TweenAction.COLOR;
this.initInternal = () =>
{
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
if(trans.gameObject.renderer){
this.setFromColor( trans.gameObject.renderer.material.color );
}else if(trans.childCount>0){
foreach (Transform child in trans) {
if(child.gameObject.renderer!=null){
this.setFromColor( child.gameObject.renderer.material.color );
break;
}
}
}
#else
SpriteRenderer renColor = trans.GetComponent();
if (renColor != null)
{
this.setFromColor(renColor.color);
}
else
{
if (trans.GetComponent() != null &&
trans.GetComponent().material.HasProperty("_Color"))
{
Color col = trans.GetComponent().material.color;
this.setFromColor(col);
}
else if (trans.GetComponent() != null &&
trans.GetComponent().material.HasProperty("_TintColor"))
{
Color col = trans.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
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Color toColor = tweenColor(this, val);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
if (this.spriteRen != null)
{
this.spriteRen.color = toColor;
colorRecursiveSprite(trans, toColor);
}
else
{
#endif
// Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
if (this.type == TweenAction.COLOR)
colorRecursive(trans, toColor, this.useRecursion);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
}
#endif
if (dt != 0f && this._optional.onUpdateColor != null)
{
this._optional.onUpdateColor(toColor);
}
else if (dt != 0f && this._optional.onUpdateColorObject != null)
{
this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
}
};
return this;
}
public LTDescr setCallbackColor()
{
this.type = TweenAction.CALLBACK_COLOR;
this.initInternal = () => { this.diff = new Vector3(1.0f, 0.0f, 0.0f); };
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Color toColor = tweenColor(this, val);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
if (this.spriteRen != null)
{
this.spriteRen.color = toColor;
colorRecursiveSprite(trans, toColor);
}
else
{
#endif
// Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
if (this.type == TweenAction.COLOR)
colorRecursive(trans, toColor, this.useRecursion);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
}
#endif
if (dt != 0f && this._optional.onUpdateColor != null)
{
this._optional.onUpdateColor(toColor);
}
else if (dt != 0f && this._optional.onUpdateColorObject != null)
{
this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
}
};
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 setTextColor()
{
this.type = TweenAction.TEXT_COLOR;
this.initInternal = () =>
{
this.uiText = trans.GetComponent();
this.setFromColor(this.uiText != null ? this.uiText.color : Color.white);
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Color toColor = tweenColor(this, val);
this.uiText.color = toColor;
if (dt != 0f && this._optional.onUpdateColor != null)
this._optional.onUpdateColor(toColor);
if (this.useRecursion && trans.childCount > 0)
textColorRecursive(this.trans, toColor);
};
return this;
}
public LTDescr setCanvasAlpha()
{
this.type = TweenAction.CANVAS_ALPHA;
this.initInternal = () =>
{
this.uiImage = trans.GetComponent();
if (this.uiImage != null)
{
this.fromInternal.x = this.uiImage.color.a;
}
else
{
this.rawImage = trans.GetComponent();
if (this.rawImage != null)
{
this.fromInternal.x = this.rawImage.color.a;
}
else
{
this.fromInternal.x = 1f;
}
}
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
if (this.uiImage != null)
{
Color c = this.uiImage.color;
c.a = val;
this.uiImage.color = c;
}
else if (this.rawImage != null)
{
Color c = this.rawImage.color;
c.a = val;
this.rawImage.color = c;
}
if (this.useRecursion)
{
alphaRecursive(this.rectTransform, val, 0);
textAlphaChildrenRecursive(this.rectTransform, val);
}
};
return this;
}
public LTDescr setCanvasGroupAlpha()
{
this.type = TweenAction.CANVASGROUP_ALPHA;
this.initInternal = () => { this.fromInternal.x = trans.GetComponent().alpha; };
this.easeInternal = () => { this.trans.GetComponent().alpha = easeMethod().x; };
return this;
}
public LTDescr setCanvasColor()
{
this.type = TweenAction.CANVAS_COLOR;
this.initInternal = () =>
{
this.uiImage = trans.GetComponent();
if (this.uiImage == null)
{
this.rawImage = trans.GetComponent();
this.setFromColor(this.rawImage != null ? this.rawImage.color : Color.white);
}
else
{
this.setFromColor(this.uiImage.color);
}
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
Color toColor = tweenColor(this, val);
if (this.uiImage != null)
{
this.uiImage.color = toColor;
}
else if (this.rawImage != null)
{
this.rawImage.color = toColor;
}
if (dt != 0f && this._optional.onUpdateColor != null)
this._optional.onUpdateColor(toColor);
if (this.useRecursion)
colorRecursive(this.rectTransform, toColor);
};
return this;
}
public LTDescr setCanvasMoveX()
{
this.type = TweenAction.CANVAS_MOVE_X;
this.initInternal = () => { this.fromInternal.x = this.rectTransform.anchoredPosition3D.x; };
this.easeInternal = () =>
{
Vector3 c = this.rectTransform.anchoredPosition3D;
this.rectTransform.anchoredPosition3D = new Vector3(easeMethod().x, c.y, c.z);
};
return this;
}
public LTDescr setCanvasMoveY()
{
this.type = TweenAction.CANVAS_MOVE_Y;
this.initInternal = () => { this.fromInternal.x = this.rectTransform.anchoredPosition3D.y; };
this.easeInternal = () =>
{
Vector3 c = this.rectTransform.anchoredPosition3D;
this.rectTransform.anchoredPosition3D = new Vector3(c.x, easeMethod().x, c.z);
};
return this;
}
public LTDescr setCanvasMoveZ()
{
this.type = TweenAction.CANVAS_MOVE_Z;
this.initInternal = () => { this.fromInternal.x = this.rectTransform.anchoredPosition3D.z; };
this.easeInternal = () =>
{
Vector3 c = this.rectTransform.anchoredPosition3D;
this.rectTransform.anchoredPosition3D = new Vector3(c.x, c.y, easeMethod().x);
};
return this;
}
private void initCanvasRotateAround()
{
this.lastVal = 0.0f;
this.fromInternal.x = 0.0f;
this._optional.origRotation = this.rectTransform.rotation;
}
public LTDescr setCanvasRotateAround()
{
this.type = TweenAction.CANVAS_ROTATEAROUND;
this.initInternal = this.initCanvasRotateAround;
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
RectTransform rect = this.rectTransform;
Vector3 origPos = rect.localPosition;
rect.RotateAround((Vector3) rect.TransformPoint(this._optional.point), this._optional.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 = this._optional.origRotation;
rect.RotateAround((Vector3) rect.TransformPoint(this._optional.point), this._optional.axis, val);
};
return this;
}
public LTDescr setCanvasRotateAroundLocal()
{
this.type = TweenAction.CANVAS_ROTATEAROUND_LOCAL;
this.initInternal = this.initCanvasRotateAround;
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
RectTransform rect = this.rectTransform;
Vector3 origPos = rect.localPosition;
rect.RotateAround((Vector3) rect.TransformPoint(this._optional.point),
rect.TransformDirection(this._optional.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 = this._optional.origRotation;
rect.RotateAround((Vector3) rect.TransformPoint(this._optional.point),
rect.TransformDirection(this._optional.axis), val);
};
return this;
}
public LTDescr setCanvasPlaySprite()
{
this.type = TweenAction.CANVAS_PLAYSPRITE;
this.initInternal = () =>
{
this.uiImage = trans.GetComponent();
this.fromInternal.x = 0f;
};
this.easeInternal = () =>
{
newVect = easeMethod();
val = newVect.x;
int frame = (int) Mathf.Round(val);
this.uiImage.sprite = this.sprites[frame];
};
return this;
}
public LTDescr setCanvasMove()
{
this.type = TweenAction.CANVAS_MOVE;
this.initInternal = () => { this.fromInternal = this.rectTransform.anchoredPosition3D; };
this.easeInternal = () => { this.rectTransform.anchoredPosition3D = easeMethod(); };
return this;
}
public LTDescr setCanvasScale()
{
this.type = TweenAction.CANVAS_SCALE;
this.initInternal = () => { this.from = this.rectTransform.localScale; };
this.easeInternal = () => { this.rectTransform.localScale = easeMethod(); };
return this;
}
public LTDescr setCanvasSizeDelta()
{
this.type = TweenAction.CANVAS_SIZEDELTA;
this.initInternal = () => { this.from = this.rectTransform.sizeDelta; };
this.easeInternal = () => { this.rectTransform.sizeDelta = easeMethod(); };
return this;
}
#endif
private void callback()
{
newVect = easeMethod();
val = newVect.x;
}
public LTDescr setCallback()
{
this.type = TweenAction.CALLBACK;
this.initInternal = () => { };
this.easeInternal = this.callback;
return this;
}
public LTDescr setValue3()
{
this.type = TweenAction.VALUE3;
this.initInternal = () => { };
this.easeInternal = this.callback;
return this;
}
public LTDescr setMove()
{
this.type = TweenAction.MOVE;
this.initInternal = () => { this.from = trans.position; };
this.easeInternal = () =>
{
newVect = easeMethod();
trans.position = newVect;
};
return this;
}
public LTDescr setMoveLocal()
{
this.type = TweenAction.MOVE_LOCAL;
this.initInternal = () => { this.from = trans.localPosition; };
this.easeInternal = () =>
{
newVect = easeMethod();
trans.localPosition = newVect;
};
return this;
}
public LTDescr setMoveToTransform()
{
this.type = TweenAction.MOVE_TO_TRANSFORM;
this.initInternal = () => { this.from = trans.position; };
this.easeInternal = () =>
{
this.to = this._optional.toTrans.position;
this.diff = this.to - this.from;
this.diffDiv2 = this.diff*0.5f;
newVect = easeMethod();
this.trans.position = newVect;
};
return this;
}
public LTDescr setRotate()
{
this.type = TweenAction.ROTATE;
this.initInternal = () =>
{
this.from = trans.eulerAngles;
this.to = new Vector3(LeanTween.closestRot(this.fromInternal.x, this.toInternal.x),
LeanTween.closestRot(this.from.y, this.to.y), LeanTween.closestRot(this.from.z, this.to.z));
};
this.easeInternal = () =>
{
newVect = easeMethod();
trans.eulerAngles = newVect;
};
return this;
}
public LTDescr setRotateLocal()
{
this.type = TweenAction.ROTATE_LOCAL;
this.initInternal = () =>
{
this.from = trans.localEulerAngles;
this.to = new Vector3(LeanTween.closestRot(this.fromInternal.x, this.toInternal.x),
LeanTween.closestRot(this.from.y, this.to.y), LeanTween.closestRot(this.from.z, this.to.z));
};
this.easeInternal = () =>
{
newVect = easeMethod();
trans.localEulerAngles = newVect;
};
return this;
}
public LTDescr setScale()
{
this.type = TweenAction.SCALE;
this.initInternal = () => { this.from = trans.localScale; };
this.easeInternal = () =>
{
newVect = easeMethod();
trans.localScale = newVect;
};
return this;
}
public LTDescr setGUIMove()
{
this.type = TweenAction.GUI_MOVE;
this.initInternal =
() => { this.from = new Vector3(this._optional.ltRect.rect.x, this._optional.ltRect.rect.y, 0); };
this.easeInternal = () =>
{
Vector3 v = easeMethod();
this._optional.ltRect.rect = new Rect(v.x, v.y, this._optional.ltRect.rect.width,
this._optional.ltRect.rect.height);
};
return this;
}
public LTDescr setGUIMoveMargin()
{
this.type = TweenAction.GUI_MOVE_MARGIN;
this.initInternal =
() => { this.from = new Vector2(this._optional.ltRect.margin.x, this._optional.ltRect.margin.y); };
this.easeInternal = () =>
{
Vector3 v = easeMethod();
this._optional.ltRect.margin = new Vector2(v.x, v.y);
};
return this;
}
public LTDescr setGUIScale()
{
this.type = TweenAction.GUI_SCALE;
this.initInternal =
() =>
{
this.from = new Vector3(this._optional.ltRect.rect.width, this._optional.ltRect.rect.height, 0);
};
this.easeInternal = () =>
{
Vector3 v = easeMethod();
this._optional.ltRect.rect = new Rect(this._optional.ltRect.rect.x, this._optional.ltRect.rect.y, v.x,
v.y);
};
return this;
}
public LTDescr setGUIAlpha()
{
this.type = TweenAction.GUI_ALPHA;
this.initInternal = () => { this.fromInternal.x = this._optional.ltRect.alpha; };
this.easeInternal = () => { this._optional.ltRect.alpha = easeMethod().x; };
return this;
}
public LTDescr setGUIRotate()
{
this.type = TweenAction.GUI_ROTATE;
this.initInternal = () =>
{
if (this._optional.ltRect.rotateEnabled == false)
{
this._optional.ltRect.rotateEnabled = true;
this._optional.ltRect.resetForRotation();
}
this.fromInternal.x = this._optional.ltRect.rotation;
};
this.easeInternal = () => { this._optional.ltRect.rotation = easeMethod().x; };
return this;
}
public LTDescr setDelayedSound()
{
this.type = TweenAction.DELAYED_SOUND;
this.initInternal = () => { this.hasExtraOnCompletes = true; };
this.easeInternal = this.callback;
return this;
}
private void init()
{
this.hasInitiliazed = true;
usesNormalDt = !(useEstimatedTime || useManualTime || useFrames);
// only set this to true if it uses non of the other timing modes
if (useFrames)
this.optional.initFrameCount = Time.frameCount;
if (this.time <= 0f) // avoid dividing by zero
this.time = Mathf.Epsilon;
this.initInternal();
this.diff = this.to - this.from;
this.diffDiv2 = this.diff*0.5f;
if (this._optional.onStart != null)
this._optional.onStart();
if (this.onCompleteOnStart)
callOnCompletes();
if (this.speed >= 0)
{
initSpeed();
}
}
private void initSpeed()
{
if (this.type == TweenAction.MOVE_CURVED || this.type == TweenAction.MOVE_CURVED_LOCAL)
{
this.time = this._optional.path.distance/this.speed;
}
else if (this.type == TweenAction.MOVE_SPLINE || this.type == TweenAction.MOVE_SPLINE_LOCAL)
{
this.time = this._optional.spline.distance/this.speed;
}
else
{
this.time = (this.to - this.from).magnitude/this.speed;
}
}
public static float val;
public static float dt;
public static Vector3 newVect;
/**
* If you need a tween to happen immediately instead of waiting for the next Update call, you can force it with this method
*
* @method updateNow
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.moveX(gameObject, 5f, 0f ).updateNow();
*/
public LTDescr updateNow()
{
updateInternal();
return this;
}
public bool updateInternal()
{
float directionLocal = this.direction;
if (this.usesNormalDt)
{
dt = LeanTween.dtActual;
}
else if (this.useEstimatedTime)
{
dt = LeanTween.dtEstimated;
}
else if (this.useFrames)
{
dt = this.optional.initFrameCount == 0 ? 0 : 1;
this.optional.initFrameCount = Time.frameCount;
}
else if (this.useManualTime)
{
dt = LeanTween.dtManual;
}
// Debug.Log ("tween:" + this+ " dt:"+dt);
if (this.delay <= 0f && directionLocal != 0f)
{
if (trans == null)
return true;
// initialize if has not done so yet
if (!this.hasInitiliazed)
this.init();
dt = dt*directionLocal;
this.passed += dt;
this.passed = Mathf.Clamp(this.passed, 0f, this.time);
this.ratioPassed = (this.passed/this.time);
// need to clamp when finished so it will finish at the exact spot and not overshoot
this.easeInternal();
if (this.hasUpdateCallback)
this._optional.callOnUpdate(val, this.ratioPassed);
bool isTweenFinished = directionLocal > 0f ? this.passed >= this.time : this.passed <= 0f;
// Debug.Log("lt "+this+" dt:"+dt+" fin:"+isTweenFinished);
if (isTweenFinished)
{
// increment or flip tween
this.loopCount--;
if (this.loopType == LeanTweenType.pingPong)
{
this.direction = 0.0f - directionLocal;
}
else
{
this.passed = Mathf.Epsilon;
}
isTweenFinished = this.loopCount == 0 || this.loopType == LeanTweenType.once;
// only return true if it is fully complete
if (isTweenFinished == false && this.onCompleteOnRepeat && this.hasExtraOnCompletes)
callOnCompletes();
// this only gets called if onCompleteOnRepeat is set to true, otherwise LeanTween class takes care of calling it
return isTweenFinished;
}
}
else
{
this.delay -= dt;
}
return false;
}
public void callOnCompletes()
{
if (this.type == TweenAction.GUI_ROTATE)
this._optional.ltRect.rotateFinished = true;
if (this.type == TweenAction.DELAYED_SOUND)
{
AudioSource.PlayClipAtPoint((AudioClip) this._optional.onCompleteParam, this.to, this.from.x);
}
if (this._optional.onComplete != null)
{
this._optional.onComplete();
}
else if (this._optional.onCompleteObject != null)
{
this._optional.onCompleteObject(this._optional.onCompleteParam);
}
}
// Helper Methods
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._optional.axis = new Vector3(col.r, col.g, col.b);
return this;
}
private static void alphaRecursive(Transform transform, float val, bool useRecursion = true)
{
Renderer renderer = transform.gameObject.GetComponent();
if (renderer != null)
{
foreach (Material mat in renderer.materials)
{
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 (useRecursion && transform.childCount > 0)
{
foreach (Transform child in transform)
{
alphaRecursive(child, val);
}
}
}
private static void colorRecursive(Transform transform, Color toColor, bool useRecursion = true)
{
Renderer ren = transform.gameObject.GetComponent();
if (ren != null)
{
foreach (Material mat in ren.materials)
{
mat.color = toColor;
}
}
if (useRecursion && transform.childCount > 0)
{
foreach (Transform child in transform)
{
colorRecursive(child, toColor);
}
}
}
#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 void alphaRecursive(RectTransform rectTransform, float val, int recursiveLevel = 0)
{
if (rectTransform.childCount > 0)
{
foreach (RectTransform child in rectTransform)
{
UnityEngine.UI.MaskableGraphic uiImage = child.GetComponent();
if (uiImage != null)
{
Color c = uiImage.color;
c.a = val;
uiImage.color = c;
}
else
{
uiImage = child.GetComponent();
if (uiImage != null)
{
Color c = uiImage.color;
c.a = val;
uiImage.color = c;
}
}
alphaRecursive(child, val, recursiveLevel + 1);
}
}
}
private static void alphaRecursiveSprite(Transform transform, float val)
{
if (transform.childCount > 0)
{
foreach (Transform child in transform)
{
SpriteRenderer ren = child.GetComponent();
if (ren != null)
ren.color = new Color(ren.color.r, ren.color.g, ren.color.b, val);
alphaRecursiveSprite(child, val);
}
}
}
private static void colorRecursiveSprite(Transform transform, Color toColor)
{
if (transform.childCount > 0)
{
foreach (Transform child in transform)
{
SpriteRenderer ren = transform.gameObject.GetComponent();
if (ren != null)
ren.color = toColor;
colorRecursiveSprite(child, toColor);
}
}
}
private static void colorRecursive(RectTransform rectTransform, Color toColor)
{
if (rectTransform.childCount > 0)
{
foreach (RectTransform child in rectTransform)
{
UnityEngine.UI.MaskableGraphic uiImage = child.GetComponent();
if (uiImage != null)
{
uiImage.color = toColor;
}
else
{
uiImage = child.GetComponent();
if (uiImage != null)
uiImage.color = toColor;
}
colorRecursive(child, toColor);
}
}
}
private static void textAlphaChildrenRecursive(Transform trans, float val, bool useRecursion = true)
{
if (useRecursion && trans.childCount > 0)
{
foreach (Transform child in trans)
{
UnityEngine.UI.Text uiText = child.GetComponent();
if (uiText != null)
{
Color c = uiText.color;
c.a = val;
uiText.color = c;
}
textAlphaChildrenRecursive(child, val);
}
}
}
private static void textAlphaRecursive(Transform trans, float val, bool useRecursion = true)
{
UnityEngine.UI.Text uiText = trans.GetComponent();
if (uiText != null)
{
Color c = uiText.color;
c.a = val;
uiText.color = c;
}
if (useRecursion && trans.childCount > 0)
{
foreach (Transform child in trans)
{
textAlphaRecursive(child, val);
}
}
}
private static void textColorRecursive(Transform trans, Color toColor)
{
if (trans.childCount > 0)
{
foreach (Transform child in trans)
{
UnityEngine.UI.Text uiText = child.GetComponent();
if (uiText != null)
{
uiText.color = toColor;
}
textColorRecursive(child, toColor);
}
}
}
#endif
private static Color tweenColor(LTDescr tween, float val)
{
Vector3 diff3 = tween._optional.point - tween._optional.axis;
float diffAlpha = tween.to.y - tween.from.y;
return new Color(tween._optional.axis.x + diff3.x*val, tween._optional.axis.y + diff3.y*val,
tween._optional.axis.z + diff3.z*val, tween.from.y + diffAlpha*val);
}
/**
* 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;
}
/**
* Resume a paused tween
*
* @method resume
* @return {LTDescr} LTDescr an object that distinguishes the tween
*/
public LTDescr resume()
{
this.direction = this.directionLast;
return this;
}
/**
* Set Axis optional axis for tweens where it is relevant
*
* @method setAxis
* @param {Vector3} axis either the tween rotates around, or the direction it faces in the case of setOrientToPath
* @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 setAxis(Vector3 axis)
{
this._optional.axis = axis;
return this;
}
/**
* 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)
{
this.delay = delay;
return this;
}
/**
* Set the type of easing used for the tween.
*