You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2246 lines
78 KiB

7 years ago
  1. //namespace DentedPixel{
  2. using System;
  3. using UnityEngine;
  4. /**
  5. * Internal Representation of a Tween<br>
  6. * <br>
  7. * This class represents all of the optional parameters you can pass to a method (it also represents the internal representation of the tween).<br><br>
  8. * <strong id='optional'>Optional Parameters</strong> are passed at the end of every method:<br>
  9. * <br>
  10. * &nbsp;&nbsp;<i>Example:</i><br>
  11. * &nbsp;&nbsp;LeanTween.moveX( gameObject, 1f, 1f).setEase( <a href="LeanTweenType.html">LeanTweenType</a>.easeInQuad ).setDelay(1f);<br>
  12. * <br>
  13. * You can pass the optional parameters in any order, and chain on as many as you wish.<br>
  14. * You can also <strong>pass parameters at a later time</strong> by saving a reference to what is returned.<br>
  15. * <br>
  16. * Retrieve a <strong>unique id</strong> for the tween by using the "id" property. You can pass this to LeanTween.pause, LeanTween.resume, LeanTween.cancel, LeanTween.isTweening methods<br>
  17. * <br>
  18. * &nbsp;&nbsp;<h4>Example:</h4>
  19. * &nbsp;&nbsp;int id = LeanTween.moveX(gameObject, 1f, 3f).id;<br>
  20. * <div style="color:gray">&nbsp;&nbsp;// pause a specific tween</div>
  21. * &nbsp;&nbsp;LeanTween.pause(id);<br>
  22. * <div style="color:gray">&nbsp;&nbsp;// resume later</div>
  23. * &nbsp;&nbsp;LeanTween.resume(id);<br>
  24. * <div style="color:gray">&nbsp;&nbsp;// check if it is tweening before kicking of a new tween</div>
  25. * &nbsp;&nbsp;if( LeanTween.isTweening( id ) ){<br>
  26. * &nbsp;&nbsp; &nbsp;&nbsp; LeanTween.cancel( id );<br>
  27. * &nbsp;&nbsp; &nbsp;&nbsp; LeanTween.moveZ(gameObject, 10f, 3f);<br>
  28. * &nbsp;&nbsp;}<br>
  29. * @class LTDescr
  30. * @constructor
  31. */
  32. public class LTDescr
  33. {
  34. public bool toggle;
  35. public bool useEstimatedTime;
  36. public bool useFrames;
  37. public bool useManualTime;
  38. public bool usesNormalDt;
  39. public bool hasInitiliazed;
  40. public bool hasExtraOnCompletes;
  41. public bool hasPhysics;
  42. public bool onCompleteOnRepeat;
  43. public bool onCompleteOnStart;
  44. public bool useRecursion;
  45. public float ratioPassed;
  46. public float passed;
  47. public float delay;
  48. public float time;
  49. public float speed;
  50. public float lastVal;
  51. private uint _id;
  52. public int loopCount;
  53. public uint counter;
  54. public float direction;
  55. public float directionLast;
  56. public float overshoot;
  57. public float period;
  58. public float scale;
  59. public bool destroyOnComplete;
  60. public Transform trans;
  61. public LTRect ltRect;
  62. internal Vector3 fromInternal;
  63. public Vector3 from { get { return this.fromInternal; } set { this.fromInternal = value; } }
  64. internal Vector3 toInternal;
  65. public Vector3 to { get { return this.toInternal; } set { this.toInternal = value; } }
  66. internal Vector3 diff;
  67. internal Vector3 diffDiv2;
  68. public TweenAction type;
  69. public LeanTweenType tweenType;
  70. public LeanTweenType loopType;
  71. public bool hasUpdateCallback;
  72. public EaseTypeDelegate easeMethod;
  73. public ActionMethodDelegate easeInternal {get; set; }
  74. public ActionMethodDelegate initInternal {get; set; }
  75. public delegate Vector3 EaseTypeDelegate();
  76. public delegate void ActionMethodDelegate();
  77. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  78. public SpriteRenderer spriteRen;
  79. #endif
  80. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  81. public RectTransform rectTransform;
  82. public UnityEngine.UI.Text uiText;
  83. public UnityEngine.UI.Image uiImage;
  84. public UnityEngine.UI.RawImage rawImage;
  85. public UnityEngine.Sprite[] sprites;
  86. #endif
  87. public LTDescrOptional _optional = new LTDescrOptional();
  88. private static uint global_counter = 0;
  89. public override string ToString(){
  90. 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:"+tweenType+" useEstimatedTime:"+useEstimatedTime+" id:"+id+" hasInitiliazed:"+hasInitiliazed;
  91. }
  92. public LTDescr(){
  93. }
  94. [System.Obsolete("Use 'LeanTween.cancel( id )' instead")]
  95. public LTDescr cancel( GameObject gameObject ){
  96. // Debug.Log("canceling id:"+this._id+" this.uniqueId:"+this.uniqueId+" go:"+this.trans.gameObject);
  97. if(gameObject==this.trans.gameObject)
  98. LeanTween.removeTween((int)this._id, this.uniqueId);
  99. return this;
  100. }
  101. public int uniqueId{
  102. get{
  103. uint toId = _id | counter << 16;
  104. /*uint backId = toId & 0xFFFF;
  105. uint backCounter = toId >> 16;
  106. if(_id!=backId || backCounter!=counter){
  107. Debug.LogError("BAD CONVERSION toId:"+_id);
  108. }*/
  109. return (int)toId;
  110. }
  111. }
  112. public int id{
  113. get{
  114. return uniqueId;
  115. }
  116. }
  117. public LTDescrOptional optional{
  118. get{
  119. return _optional;
  120. }
  121. set{
  122. this._optional = optional;
  123. }
  124. }
  125. public void reset(){
  126. this.toggle = this.useRecursion = this.usesNormalDt = true;
  127. this.trans = null;
  128. this.passed = this.delay = this.lastVal = 0.0f;
  129. this.hasUpdateCallback = this.useEstimatedTime = this.useFrames = this.hasInitiliazed = this.onCompleteOnRepeat = this.destroyOnComplete = this.onCompleteOnStart = this.useManualTime = this.hasExtraOnCompletes = false;
  130. this.tweenType = LeanTweenType.linear;
  131. this.loopType = LeanTweenType.once;
  132. this.loopCount = 0;
  133. this.direction = this.directionLast = this.overshoot = this.scale = 1.0f;
  134. this.period = 0.3f;
  135. this.speed = -1f;
  136. this.easeMethod = this.easeLinear;
  137. this.from = this.to = Vector3.zero;
  138. this._optional.reset();
  139. global_counter++;
  140. if(global_counter>0x8000)
  141. global_counter = 0;
  142. }
  143. // Initialize and Internal Methods
  144. public LTDescr setMoveX(){
  145. this.type = TweenAction.MOVE_X;
  146. this.initInternal = ()=>{ this.fromInternal.x = trans.position.x; };
  147. this.easeInternal = ()=>{ trans.position=new Vector3( easeMethod().x,trans.position.y,trans.position.z); };
  148. return this;
  149. }
  150. public LTDescr setMoveY(){
  151. this.type = TweenAction.MOVE_Y;
  152. this.initInternal = ()=>{ this.fromInternal.x = trans.position.y; };
  153. this.easeInternal = ()=>{ trans.position=new Vector3( trans.position.x,easeMethod().x,trans.position.z); };
  154. return this;
  155. }
  156. public LTDescr setMoveZ(){
  157. this.type = TweenAction.MOVE_Z;
  158. this.initInternal = ()=>{ this.fromInternal.x = trans.position.z; };;
  159. this.easeInternal = ()=>{ trans.position=new Vector3( trans.position.x,trans.position.y,easeMethod().x); };
  160. return this;
  161. }
  162. public LTDescr setMoveLocalX(){
  163. this.type = TweenAction.MOVE_LOCAL_X;
  164. this.initInternal = ()=>{ this.fromInternal.x = trans.localPosition.x; };
  165. this.easeInternal = ()=>{ trans.localPosition=new Vector3( easeMethod().x,trans.localPosition.y,trans.localPosition.z); };
  166. return this;
  167. }
  168. public LTDescr setMoveLocalY(){
  169. this.type = TweenAction.MOVE_LOCAL_Y;
  170. this.initInternal = ()=>{ this.fromInternal.x = trans.localPosition.y; };
  171. this.easeInternal = ()=>{ trans.localPosition=new Vector3( trans.localPosition.x,easeMethod().x,trans.localPosition.z); };
  172. return this;
  173. }
  174. public LTDescr setMoveLocalZ(){
  175. this.type = TweenAction.MOVE_LOCAL_Z;
  176. this.initInternal = ()=>{ this.fromInternal.x = trans.localPosition.z; };
  177. this.easeInternal = ()=>{ trans.localPosition=new Vector3( trans.localPosition.x,trans.localPosition.y,easeMethod().x); };
  178. return this;
  179. }
  180. private void initFromInternal(){ this.fromInternal.x = 0; }
  181. public LTDescr setMoveCurved(){
  182. this.type = TweenAction.MOVE_CURVED;
  183. this.initInternal = this.initFromInternal;
  184. this.easeInternal = ()=>{
  185. newVect = easeMethod();
  186. val = newVect.x;
  187. if(this._optional.path.orientToPath){
  188. if(this._optional.path.orientToPath2d){
  189. this._optional.path.place2d( trans, val );
  190. }else{
  191. this._optional.path.place( trans, val );
  192. }
  193. }else{
  194. trans.position = this._optional.path.point( val );
  195. }
  196. };
  197. return this;
  198. }
  199. public LTDescr setMoveCurvedLocal(){
  200. this.type = TweenAction.MOVE_CURVED_LOCAL;
  201. this.initInternal = this.initFromInternal;
  202. this.easeInternal = ()=>{
  203. newVect = easeMethod();
  204. val = newVect.x;
  205. if(this._optional.path.orientToPath){
  206. if(this._optional.path.orientToPath2d){
  207. this._optional.path.placeLocal2d( trans, val );
  208. }else{
  209. this._optional.path.placeLocal( trans, val );
  210. }
  211. }else{
  212. trans.localPosition = this._optional.path.point( val );
  213. }
  214. };
  215. return this;
  216. }
  217. public LTDescr setMoveSpline(){
  218. this.type = TweenAction.MOVE_SPLINE;
  219. this.initInternal = this.initFromInternal;
  220. this.easeInternal = ()=>{
  221. newVect = easeMethod();
  222. val = newVect.x;
  223. if(this._optional.spline.orientToPath){
  224. if(this._optional.spline.orientToPath2d){
  225. this._optional.spline.place2d( trans, val );
  226. }else{
  227. this._optional.spline.place( trans, val );
  228. }
  229. }else{
  230. trans.position = this._optional.spline.point( val );
  231. }
  232. };
  233. return this;
  234. }
  235. public LTDescr setMoveSplineLocal(){
  236. this.type = TweenAction.MOVE_SPLINE_LOCAL;
  237. this.initInternal = this.initFromInternal;
  238. this.easeInternal = ()=>{
  239. newVect = easeMethod();
  240. val = newVect.x;
  241. if(this._optional.spline.orientToPath){
  242. if(this._optional.spline.orientToPath2d){
  243. this._optional.spline.placeLocal2d( trans, val );
  244. }else{
  245. this._optional.spline.placeLocal( trans, val );
  246. }
  247. }else{
  248. trans.localPosition = this._optional.spline.point( val );
  249. }
  250. };
  251. return this;
  252. }
  253. public LTDescr setScaleX(){
  254. this.type = TweenAction.SCALE_X;
  255. this.initInternal = ()=>{ this.fromInternal.x = trans.localScale.x; };
  256. this.easeInternal = ()=>{ trans.localScale = new Vector3( easeMethod().x,trans.localScale.y,trans.localScale.z); };
  257. return this;
  258. }
  259. public LTDescr setScaleY(){
  260. this.type = TweenAction.SCALE_Y;
  261. this.initInternal = ()=>{ this.fromInternal.x = trans.localScale.y; };
  262. this.easeInternal = ()=>{ trans.localScale=new Vector3( trans.localScale.x,easeMethod().x,trans.localScale.z); };
  263. return this;
  264. }
  265. public LTDescr setScaleZ(){
  266. this.type = TweenAction.SCALE_Z;
  267. this.initInternal = ()=>{ this.fromInternal.x = trans.localScale.z; };
  268. this.easeInternal = ()=>{ trans.localScale=new Vector3( trans.localScale.x,trans.localScale.y,easeMethod().x); };
  269. return this;
  270. }
  271. public LTDescr setRotateX(){
  272. this.type = TweenAction.ROTATE_X;
  273. this.initInternal = ()=>{ this.fromInternal.x = trans.eulerAngles.x; this.toInternal.x = LeanTween.closestRot( this.fromInternal.x, this.toInternal.x);};
  274. this.easeInternal = ()=>{ trans.eulerAngles=new Vector3(easeMethod().x,trans.eulerAngles.y,trans.eulerAngles.z); };
  275. return this;
  276. }
  277. public LTDescr setRotateY(){
  278. this.type = TweenAction.ROTATE_Y;
  279. this.initInternal = ()=>{ this.fromInternal.x = trans.eulerAngles.y; this.toInternal.x = LeanTween.closestRot( this.fromInternal.x, this.toInternal.x);};
  280. this.easeInternal = ()=>{ trans.eulerAngles=new Vector3(trans.eulerAngles.x,easeMethod().x,trans.eulerAngles.z); };
  281. return this;
  282. }
  283. public LTDescr setRotateZ(){
  284. this.type = TweenAction.ROTATE_Z;
  285. this.initInternal = ()=>{
  286. this.fromInternal.x = trans.eulerAngles.z;
  287. this.toInternal.x = LeanTween.closestRot( this.fromInternal.x, this.toInternal.x);
  288. };
  289. this.easeInternal = ()=>{ trans.eulerAngles=new Vector3(trans.eulerAngles.x,trans.eulerAngles.y,easeMethod().x); };
  290. return this;
  291. }
  292. public LTDescr setRotateAround(){
  293. this.type = TweenAction.ROTATE_AROUND;
  294. this.initInternal = ()=>{
  295. this.fromInternal.x = 0f;
  296. this._optional.origRotation = trans.rotation;
  297. };
  298. this.easeInternal = ()=>{
  299. newVect = easeMethod();
  300. val = newVect.x;
  301. Vector3 origPos = trans.localPosition;
  302. Vector3 rotateAroundPt = (Vector3)trans.TransformPoint( this._optional.point );
  303. // Debug.Log("this._optional.point:"+this._optional.point);
  304. trans.RotateAround(rotateAroundPt, this._optional.axis, -this._optional.lastVal);
  305. Vector3 diff = origPos - trans.localPosition;
  306. 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
  307. trans.rotation = this._optional.origRotation;
  308. rotateAroundPt = (Vector3)trans.TransformPoint( this._optional.point );
  309. trans.RotateAround(rotateAroundPt, this._optional.axis, val);
  310. this._optional.lastVal = val;
  311. };
  312. return this;
  313. }
  314. public LTDescr setRotateAroundLocal(){
  315. this.type = TweenAction.ROTATE_AROUND_LOCAL;
  316. this.initInternal = ()=>{
  317. this.fromInternal.x = 0f;
  318. this._optional.origRotation = trans.localRotation;
  319. };
  320. this.easeInternal = ()=>{
  321. newVect = easeMethod();
  322. val = newVect.x;
  323. Vector3 origPos = trans.localPosition;
  324. trans.RotateAround((Vector3)trans.TransformPoint( this._optional.point ), trans.TransformDirection(this._optional.axis), -this._optional.lastVal);
  325. Vector3 diff = origPos - trans.localPosition;
  326. 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
  327. trans.localRotation = this._optional.origRotation;
  328. Vector3 rotateAroundPt = (Vector3)trans.TransformPoint( this._optional.point );
  329. trans.RotateAround(rotateAroundPt, trans.TransformDirection(this._optional.axis), val);
  330. this._optional.lastVal = val;
  331. };
  332. return this;
  333. }
  334. public LTDescr setAlpha(){
  335. this.type = TweenAction.ALPHA;
  336. this.initInternal = ()=>{
  337. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  338. 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; }}}
  339. this.easeInternal = this.alpha;
  340. break;
  341. #else
  342. SpriteRenderer ren = trans.gameObject.GetComponent<SpriteRenderer>();
  343. if(ren!=null){
  344. this.fromInternal.x = ren.color.a;
  345. }else{
  346. if(trans.gameObject.GetComponent<Renderer>()!=null && trans.gameObject.GetComponent<Renderer>().material.HasProperty("_Color")){
  347. this.fromInternal.x = trans.gameObject.GetComponent<Renderer>().material.color.a;
  348. }else if(trans.gameObject.GetComponent<Renderer>()!=null && trans.gameObject.GetComponent<Renderer>().material.HasProperty("_TintColor")){
  349. Color col = trans.gameObject.GetComponent<Renderer>().material.GetColor("_TintColor");
  350. this.fromInternal.x = col.a;
  351. }else if(trans.childCount>0){
  352. foreach (Transform child in trans) {
  353. if(child.gameObject.GetComponent<Renderer>()!=null){
  354. Color col = child.gameObject.GetComponent<Renderer>().material.color;
  355. this.fromInternal.x = col.a;
  356. break;
  357. }
  358. }
  359. }
  360. }
  361. #endif
  362. this.easeInternal = ()=>{
  363. val = easeMethod().x;
  364. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  365. alphaRecursive(this.trans, val, this.useRecursion);
  366. #else
  367. if(this.spriteRen!=null){
  368. this.spriteRen.color = new Color( this.spriteRen.color.r, this.spriteRen.color.g, this.spriteRen.color.b, val);
  369. alphaRecursiveSprite(this.trans, val);
  370. }else{
  371. alphaRecursive(this.trans, val, this.useRecursion);
  372. }
  373. #endif
  374. };
  375. };
  376. this.easeInternal = ()=>{
  377. newVect = easeMethod();
  378. val = newVect.x;
  379. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  380. alphaRecursive(this.trans, val, this.useRecursion);
  381. #else
  382. if(this.spriteRen!=null){
  383. this.spriteRen.color = new Color( this.spriteRen.color.r, this.spriteRen.color.g, this.spriteRen.color.b, val);
  384. alphaRecursiveSprite(this.trans, val);
  385. }else{
  386. alphaRecursive(this.trans, val, this.useRecursion);
  387. }
  388. #endif
  389. };
  390. return this;
  391. }
  392. public LTDescr setTextAlpha(){
  393. this.type = TweenAction.TEXT_ALPHA;
  394. this.initInternal = ()=>{
  395. this.uiText = trans.gameObject.GetComponent<UnityEngine.UI.Text>();
  396. this.fromInternal.x = this.uiText != null ? this.uiText.color.a : 1f;
  397. };
  398. this.easeInternal = ()=>{ textAlphaRecursive( trans, easeMethod().x, this.useRecursion ); };
  399. return this;
  400. }
  401. public LTDescr setAlphaVertex(){
  402. this.type = TweenAction.ALPHA_VERTEX;
  403. this.initInternal = ()=>{ this.fromInternal.x = trans.GetComponent<MeshFilter>().mesh.colors32[0].a; };
  404. this.easeInternal = ()=>{
  405. newVect = easeMethod();
  406. val = newVect.x;
  407. Mesh mesh = trans.GetComponent<MeshFilter>().mesh;
  408. Vector3[] vertices = mesh.vertices;
  409. Color32[] colors = new Color32[vertices.Length];
  410. if (colors.Length == 0){ //MaxFW fix: add vertex colors if the mesh doesn't have any
  411. Color32 transparentWhiteColor32 = new Color32(0xff, 0xff, 0xff, 0x00);
  412. colors = new Color32[mesh.vertices.Length];
  413. for (int k=0; k<colors.Length; k++)
  414. colors[k] = transparentWhiteColor32;
  415. mesh.colors32 = colors;
  416. }// fix end
  417. Color32 c = mesh.colors32[0];
  418. c = new Color( c.r, c.g, c.b, val);
  419. for (int k= 0; k < vertices.Length; k++)
  420. colors[k] = c;
  421. mesh.colors32 = colors;
  422. };
  423. return this;
  424. }
  425. public LTDescr setColor(){
  426. this.type = TweenAction.COLOR;
  427. this.initInternal = ()=>{
  428. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  429. if(trans.gameObject.renderer){
  430. this.setFromColor( trans.gameObject.renderer.material.color );
  431. }else if(trans.childCount>0){
  432. foreach (Transform child in trans) {
  433. if(child.gameObject.renderer!=null){
  434. this.setFromColor( child.gameObject.renderer.material.color );
  435. break;
  436. }
  437. }
  438. }
  439. #else
  440. SpriteRenderer renColor = trans.gameObject.GetComponent<SpriteRenderer>();
  441. if(renColor!=null){
  442. this.setFromColor( renColor.color );
  443. }else{
  444. if(trans.gameObject.GetComponent<Renderer>()!=null && trans.gameObject.GetComponent<Renderer>().material.HasProperty("_Color")){
  445. Color col = trans.gameObject.GetComponent<Renderer>().material.color;
  446. this.setFromColor( col );
  447. }else if(trans.gameObject.GetComponent<Renderer>()!=null && trans.gameObject.GetComponent<Renderer>().material.HasProperty("_TintColor")){
  448. Color col = trans.gameObject.GetComponent<Renderer>().material.GetColor ("_TintColor");
  449. this.setFromColor( col );
  450. }else if(trans.childCount>0){
  451. foreach (Transform child in trans) {
  452. if(child.gameObject.GetComponent<Renderer>()!=null){
  453. Color col = child.gameObject.GetComponent<Renderer>().material.color;
  454. this.setFromColor( col );
  455. break;
  456. }
  457. }
  458. }
  459. }
  460. #endif
  461. };
  462. this.easeInternal = ()=>{
  463. newVect = easeMethod();
  464. val = newVect.x;
  465. Color toColor = tweenColor(this, val);
  466. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  467. if(this.spriteRen!=null){
  468. this.spriteRen.color = toColor;
  469. colorRecursiveSprite( trans, toColor);
  470. }else{
  471. #endif
  472. // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
  473. if(this.type==TweenAction.COLOR)
  474. colorRecursive(trans, toColor, this.useRecursion);
  475. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  476. }
  477. #endif
  478. if(dt!=0f && this._optional.onUpdateColor!=null){
  479. this._optional.onUpdateColor(toColor);
  480. }else if(dt!=0f && this._optional.onUpdateColorObject!=null){
  481. this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
  482. }
  483. };
  484. return this;
  485. }
  486. public LTDescr setCallbackColor(){
  487. this.type = TweenAction.CALLBACK_COLOR;
  488. this.initInternal = ()=>{ this.diff = new Vector3(1.0f,0.0f,0.0f); };
  489. this.easeInternal = ()=>{
  490. newVect = easeMethod();
  491. val = newVect.x;
  492. Color toColor = tweenColor(this, val);
  493. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  494. if(this.spriteRen!=null){
  495. this.spriteRen.color = toColor;
  496. colorRecursiveSprite( trans, toColor);
  497. }else{
  498. #endif
  499. // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
  500. if(this.type==TweenAction.COLOR)
  501. colorRecursive(trans, toColor, this.useRecursion);
  502. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  503. }
  504. #endif
  505. if(dt!=0f && this._optional.onUpdateColor!=null){
  506. this._optional.onUpdateColor(toColor);
  507. }else if(dt!=0f && this._optional.onUpdateColorObject!=null){
  508. this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
  509. }
  510. };
  511. return this;
  512. }
  513. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  514. public LTDescr setTextColor(){
  515. this.type = TweenAction.TEXT_COLOR;
  516. this.initInternal = ()=>{
  517. this.uiText = trans.gameObject.GetComponent<UnityEngine.UI.Text>();
  518. this.setFromColor( this.uiText != null ? this.uiText.color : Color.white );
  519. };
  520. this.easeInternal = ()=>{
  521. newVect = easeMethod();
  522. val = newVect.x;
  523. Color toColor = tweenColor(this, val);
  524. this.uiText.color = toColor;
  525. if (dt!=0f && this._optional.onUpdateColor != null)
  526. this._optional.onUpdateColor(toColor);
  527. if(this.useRecursion && trans.childCount>0)
  528. textColorRecursive(this.trans, toColor);
  529. };
  530. return this;
  531. }
  532. public LTDescr setCanvasAlpha(){
  533. this.type = TweenAction.CANVAS_ALPHA;
  534. this.initInternal = ()=>{
  535. this.uiImage = trans.gameObject.GetComponent<UnityEngine.UI.Image>();
  536. if(this.uiImage!=null){
  537. this.fromInternal.x = this.uiImage.color.a;
  538. }else{
  539. this.rawImage = trans.gameObject.GetComponent<UnityEngine.UI.RawImage>();
  540. if(this.rawImage != null){
  541. this.fromInternal.x = this.rawImage.color.a;
  542. }else{
  543. this.fromInternal.x = 1f;
  544. }
  545. }
  546. };
  547. this.easeInternal = ()=>{
  548. newVect = easeMethod();
  549. val = newVect.x;
  550. if(this.uiImage!=null){
  551. Color c = this.uiImage.color; c.a = val; this.uiImage.color = c;
  552. }else if(this.rawImage!=null){
  553. Color c = this.rawImage.color; c.a = val; this.rawImage.color = c;
  554. }
  555. if(this.useRecursion){
  556. alphaRecursive( this.rectTransform, val, 0 );
  557. textAlphaRecursive( this.rectTransform, val);
  558. }
  559. };
  560. return this;
  561. }
  562. public LTDescr setCanvasGroupAlpha(){
  563. this.type = TweenAction.CANVASGROUP_ALPHA;
  564. this.initInternal = ()=>{this.fromInternal.x = trans.gameObject.GetComponent<CanvasGroup>().alpha;};
  565. this.easeInternal = ()=>{ this.trans.GetComponent<CanvasGroup>().alpha = easeMethod().x; };
  566. return this;
  567. }
  568. public LTDescr setCanvasColor(){
  569. this.type = TweenAction.CANVAS_COLOR;
  570. this.initInternal = ()=>{
  571. this.uiImage = trans.gameObject.GetComponent<UnityEngine.UI.Image>();
  572. if(this.uiImage==null){
  573. this.rawImage = trans.gameObject.GetComponent<UnityEngine.UI.RawImage>();
  574. this.setFromColor( this.rawImage!=null ? this.rawImage.color : Color.white );
  575. }else{
  576. this.setFromColor( this.uiImage.color );
  577. }
  578. };
  579. this.easeInternal = ()=>{
  580. newVect = easeMethod();
  581. val = newVect.x;
  582. Color toColor = tweenColor(this, val);
  583. if(this.uiImage!=null){
  584. this.uiImage.color = toColor;
  585. }else if(this.rawImage!=null){
  586. this.rawImage.color = toColor;
  587. }
  588. if (dt!=0f && this._optional.onUpdateColor != null)
  589. this._optional.onUpdateColor(toColor);
  590. if(this.useRecursion)
  591. colorRecursive(this.rectTransform, toColor);
  592. };
  593. return this;
  594. }
  595. public LTDescr setCanvasMoveX(){
  596. this.type = TweenAction.CANVAS_MOVE_X;
  597. this.initInternal = ()=>{ this.fromInternal.x = this.rectTransform.anchoredPosition3D.x; };
  598. this.easeInternal = ()=>{ Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(easeMethod().x, c.y, c.z); };
  599. return this;
  600. }
  601. public LTDescr setCanvasMoveY(){
  602. this.type = TweenAction.CANVAS_MOVE_Y;
  603. this.initInternal = ()=>{ this.fromInternal.x = this.rectTransform.anchoredPosition3D.y; };
  604. this.easeInternal = ()=>{ Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(c.x, easeMethod().x, c.z); };
  605. return this;
  606. }
  607. public LTDescr setCanvasMoveZ(){
  608. this.type = TweenAction.CANVAS_MOVE_Z;
  609. this.initInternal = ()=>{ this.fromInternal.x = this.rectTransform.anchoredPosition3D.z; };
  610. this.easeInternal = ()=>{ Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(c.x, c.y, easeMethod().x); };
  611. return this;
  612. }
  613. private void initCanvasRotateAround(){
  614. this.lastVal = 0.0f;
  615. this.fromInternal.x = 0.0f;
  616. this._optional.origRotation = this.rectTransform.rotation;
  617. }
  618. public LTDescr setCanvasRotateAround(){
  619. this.type = TweenAction.CANVAS_ROTATEAROUND;
  620. this.initInternal = this.initCanvasRotateAround;
  621. this.easeInternal = ()=>{
  622. newVect = easeMethod();
  623. val = newVect.x;
  624. RectTransform rect = this.rectTransform;
  625. Vector3 origPos = rect.localPosition;
  626. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), this._optional.axis, -val);
  627. Vector3 diff = origPos - rect.localPosition;
  628. 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
  629. rect.rotation = this._optional.origRotation;
  630. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), this._optional.axis, val);
  631. };
  632. return this;
  633. }
  634. public LTDescr setCanvasRotateAroundLocal(){
  635. this.type = TweenAction.CANVAS_ROTATEAROUND_LOCAL;
  636. this.initInternal = this.initCanvasRotateAround;
  637. this.easeInternal = ()=>{
  638. newVect = easeMethod();
  639. val = newVect.x;
  640. RectTransform rect = this.rectTransform;
  641. Vector3 origPos = rect.localPosition;
  642. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), rect.TransformDirection(this._optional.axis), -val);
  643. Vector3 diff = origPos - rect.localPosition;
  644. 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
  645. rect.rotation = this._optional.origRotation;
  646. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), rect.TransformDirection(this._optional.axis), val);
  647. };
  648. return this;
  649. }
  650. public LTDescr setCanvasPlaySprite(){
  651. this.type = TweenAction.CANVAS_PLAYSPRITE;
  652. this.initInternal = ()=>{
  653. this.uiImage = trans.gameObject.GetComponent<UnityEngine.UI.Image>();
  654. this.fromInternal.x = 0f;
  655. };
  656. this.easeInternal = ()=>{
  657. newVect = easeMethod();
  658. val = newVect.x;
  659. int frame = (int)Mathf.Round( val );
  660. this.uiImage.sprite = this.sprites[ frame ];
  661. };
  662. return this;
  663. }
  664. public LTDescr setCanvasMove(){
  665. this.type = TweenAction.CANVAS_MOVE;
  666. this.initInternal = ()=>{ this.fromInternal = this.rectTransform.anchoredPosition3D; };
  667. this.easeInternal = ()=>{ this.rectTransform.anchoredPosition3D = easeMethod(); };
  668. return this;
  669. }
  670. public LTDescr setCanvasScale(){
  671. this.type = TweenAction.CANVAS_SCALE;
  672. this.initInternal = ()=>{ this.from = this.rectTransform.localScale; };
  673. this.easeInternal = ()=>{ this.rectTransform.localScale = easeMethod(); };
  674. return this;
  675. }
  676. public LTDescr setCanvasSizeDelta(){
  677. this.type = TweenAction.CANVAS_SIZEDELTA;
  678. this.initInternal = ()=>{ this.from = this.rectTransform.sizeDelta; };
  679. this.easeInternal = ()=>{ this.rectTransform.sizeDelta = easeMethod(); };
  680. return this;
  681. }
  682. #endif
  683. private void callback(){ newVect = easeMethod(); val = newVect.x; }
  684. public LTDescr setCallback(){
  685. this.type = TweenAction.CALLBACK;
  686. this.initInternal = ()=>{};
  687. this.easeInternal = this.callback;
  688. return this;
  689. }
  690. public LTDescr setValue3(){
  691. this.type = TweenAction.VALUE3;
  692. this.initInternal = ()=>{};
  693. this.easeInternal = this.callback;
  694. return this;
  695. }
  696. public LTDescr setMove(){
  697. this.type = TweenAction.MOVE;
  698. this.initInternal = ()=>{ this.from = trans.position; };
  699. this.easeInternal = ()=>{
  700. newVect = easeMethod();
  701. trans.position = newVect;
  702. };
  703. return this;
  704. }
  705. public LTDescr setMoveLocal(){
  706. this.type = TweenAction.MOVE_LOCAL;
  707. this.initInternal = ()=>{ this.from = trans.localPosition; };
  708. this.easeInternal = ()=>{
  709. newVect = easeMethod();
  710. trans.localPosition = newVect;
  711. };
  712. return this;
  713. }
  714. public LTDescr setMoveToTransform(){
  715. this.type = TweenAction.MOVE_TO_TRANSFORM;
  716. this.initInternal = ()=>{ this.from = trans.position; };
  717. this.easeInternal = ()=>{
  718. this.to = this._optional.toTrans.position;
  719. this.diff = this.to - this.from;
  720. this.diffDiv2 = this.diff * 0.5f;
  721. newVect = easeMethod();
  722. this.trans.position = newVect;
  723. };
  724. return this;
  725. }
  726. public LTDescr setRotate(){
  727. this.type = TweenAction.ROTATE;
  728. 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)); };
  729. this.easeInternal = ()=>{
  730. newVect = easeMethod();
  731. trans.eulerAngles = newVect;
  732. };
  733. return this;
  734. }
  735. public LTDescr setRotateLocal(){
  736. this.type = TweenAction.ROTATE_LOCAL;
  737. 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)); };
  738. this.easeInternal = ()=>{
  739. newVect = easeMethod();
  740. trans.localEulerAngles = newVect;
  741. };
  742. return this;
  743. }
  744. public LTDescr setScale(){
  745. this.type = TweenAction.SCALE;
  746. this.initInternal = ()=>{ this.from = trans.localScale; };
  747. this.easeInternal = ()=>{
  748. newVect = easeMethod();
  749. trans.localScale = newVect;
  750. };
  751. return this;
  752. }
  753. public LTDescr setGUIMove(){
  754. this.type = TweenAction.GUI_MOVE;
  755. this.initInternal = ()=>{ this.from = new Vector3(this._optional.ltRect.rect.x, this._optional.ltRect.rect.y, 0); };
  756. 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); };
  757. return this;
  758. }
  759. public LTDescr setGUIMoveMargin(){
  760. this.type = TweenAction.GUI_MOVE_MARGIN;
  761. this.initInternal = ()=>{ this.from = new Vector2(this._optional.ltRect.margin.x, this._optional.ltRect.margin.y); };
  762. this.easeInternal = ()=>{ Vector3 v = easeMethod(); this._optional.ltRect.margin = new Vector2(v.x, v.y); };
  763. return this;
  764. }
  765. public LTDescr setGUIScale(){
  766. this.type = TweenAction.GUI_SCALE;
  767. this.initInternal = ()=>{ this.from = new Vector3(this._optional.ltRect.rect.width, this._optional.ltRect.rect.height, 0); };
  768. 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); };
  769. return this;
  770. }
  771. public LTDescr setGUIAlpha(){
  772. this.type = TweenAction.GUI_ALPHA;
  773. this.initInternal = ()=>{ this.fromInternal.x = this._optional.ltRect.alpha; };
  774. this.easeInternal = ()=>{ this._optional.ltRect.alpha = easeMethod().x; };
  775. return this;
  776. }
  777. public LTDescr setGUIRotate(){
  778. this.type = TweenAction.GUI_ROTATE;
  779. this.initInternal = ()=>{ if(this._optional.ltRect.rotateEnabled==false){
  780. this._optional.ltRect.rotateEnabled = true;
  781. this._optional.ltRect.resetForRotation();
  782. }
  783. this.fromInternal.x = this._optional.ltRect.rotation;
  784. };
  785. this.easeInternal = ()=>{ this._optional.ltRect.rotation = easeMethod().x; };
  786. return this;
  787. }
  788. public LTDescr setDelayedSound(){
  789. this.type = TweenAction.DELAYED_SOUND;
  790. this.initInternal = ()=>{ this.hasExtraOnCompletes = true; };
  791. this.easeInternal = this.callback;
  792. return this;
  793. }
  794. private void init(){
  795. this.hasInitiliazed = true;
  796. usesNormalDt = !(useEstimatedTime || useManualTime || useFrames); // only set this to true if it uses non of the other timing modes
  797. if (useFrames)
  798. this.optional.initFrameCount = Time.frameCount;
  799. if (this.time <= 0f) // avoid dividing by zero
  800. this.time = Mathf.Epsilon;
  801. this.initInternal();
  802. this.diff = this.to - this.from;
  803. this.diffDiv2 = this.diff * 0.5f;
  804. if (this._optional.onStart != null)
  805. this._optional.onStart();
  806. if(this.onCompleteOnStart)
  807. callOnCompletes();
  808. if(this.speed>=0){
  809. initSpeed();
  810. }
  811. }
  812. private void initSpeed(){
  813. if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){
  814. this.time = this._optional.path.distance / this.speed;
  815. }else if(this.type==TweenAction.MOVE_SPLINE || this.type==TweenAction.MOVE_SPLINE_LOCAL){
  816. this.time = this._optional.spline.distance/ this.speed;
  817. }else{
  818. this.time = (this.to - this.from).magnitude / this.speed;
  819. }
  820. }
  821. public static float val;
  822. public static float dt;
  823. public static Vector3 newVect;
  824. /**
  825. * If you need a tween to happen immediately instead of waiting for the next Update call, you can force it with this method
  826. *
  827. * @method updateNow
  828. * @return {LTDescr} LTDescr an object that distinguishes the tween
  829. * @example
  830. * LeanTween.moveX(gameObject, 5f, 0f ).updateNow();
  831. */
  832. public LTDescr updateNow(){
  833. updateInternal();
  834. return this;
  835. }
  836. public bool updateInternal(){
  837. float directionLocal = this.direction;
  838. if(this.usesNormalDt){
  839. dt = LeanTween.dtActual;
  840. }else if( this.useEstimatedTime ){
  841. dt = LeanTween.dtEstimated;
  842. }else if( this.useFrames ){
  843. dt = this.optional.initFrameCount==0 ? 0 : 1;
  844. this.optional.initFrameCount = Time.frameCount;
  845. }else if( this.useManualTime ){
  846. dt = LeanTween.dtManual;
  847. }
  848. // Debug.Log ("tween:" + this+ " dt:"+dt);
  849. if(this.delay<=0f && directionLocal!=0f){
  850. if(trans==null)
  851. return true;
  852. // initialize if has not done so yet
  853. if(!this.hasInitiliazed)
  854. this.init();
  855. dt = dt*directionLocal;
  856. this.passed += dt;
  857. this.ratioPassed = Mathf.Clamp01(this.passed / this.time); // need to clamp when finished so it will finish at the exact spot and not overshoot
  858. this.easeInternal();
  859. if(this.hasUpdateCallback)
  860. this._optional.callOnUpdate(val, this.ratioPassed);
  861. bool isTweenFinished = directionLocal>0f ? this.passed>=this.time : this.passed<=0f;
  862. // Debug.Log("lt "+this+" dt:"+dt+" fin:"+isTweenFinished);
  863. if(isTweenFinished){ // increment or flip tween
  864. this.loopCount--;
  865. if(this.loopType==LeanTweenType.pingPong){
  866. this.direction = 0.0f-directionLocal;
  867. }else{
  868. this.passed = Mathf.Epsilon;
  869. }
  870. isTweenFinished = this.loopCount == 0 || this.loopType == LeanTweenType.once; // only return true if it is fully complete
  871. if(isTweenFinished==false && this.onCompleteOnRepeat && this.hasExtraOnCompletes)
  872. callOnCompletes(); // this only gets called if onCompleteOnRepeat is set to true, otherwise LeanTween class takes care of calling it
  873. return isTweenFinished;
  874. }
  875. }else{
  876. this.delay -= dt;
  877. }
  878. return false;
  879. }
  880. public void callOnCompletes(){
  881. if(this.type==TweenAction.GUI_ROTATE)
  882. this._optional.ltRect.rotateFinished = true;
  883. if(this.type==TweenAction.DELAYED_SOUND){
  884. AudioSource.PlayClipAtPoint((AudioClip)this._optional.onCompleteParam, this.to, this.from.x);
  885. }
  886. if(this._optional.onComplete!=null){
  887. this._optional.onComplete();
  888. }else if(this._optional.onCompleteObject!=null){
  889. this._optional.onCompleteObject(this._optional.onCompleteParam);
  890. }
  891. }
  892. // Helper Methods
  893. public LTDescr setFromColor( Color col ){
  894. this.from = new Vector3(0.0f, col.a, 0.0f);
  895. this.diff = new Vector3(1.0f,0.0f,0.0f);
  896. this._optional.axis = new Vector3( col.r, col.g, col.b );
  897. return this;
  898. }
  899. private static void alphaRecursive( Transform transform, float val, bool useRecursion = true){
  900. Renderer renderer = transform.gameObject.GetComponent<Renderer>();
  901. if(renderer!=null){
  902. foreach(Material mat in renderer.materials){
  903. if(mat.HasProperty("_Color")){
  904. mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val);
  905. }else if(mat.HasProperty("_TintColor")){
  906. Color col = mat.GetColor ("_TintColor");
  907. mat.SetColor("_TintColor", new Color( col.r, col.g, col.b, val));
  908. }
  909. }
  910. }
  911. if(useRecursion && transform.childCount>0){
  912. foreach (Transform child in transform) {
  913. alphaRecursive(child, val);
  914. }
  915. }
  916. }
  917. private static void colorRecursive( Transform transform, Color toColor, bool useRecursion = true ){
  918. Renderer ren = transform.gameObject.GetComponent<Renderer>();
  919. if(ren!=null){
  920. foreach(Material mat in ren.materials){
  921. mat.color = toColor;
  922. }
  923. }
  924. if(useRecursion && transform.childCount>0){
  925. foreach (Transform child in transform) {
  926. colorRecursive(child, toColor);
  927. }
  928. }
  929. }
  930. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  931. private static void alphaRecursive( RectTransform rectTransform, float val, int recursiveLevel = 0){
  932. if(rectTransform.childCount>0){
  933. foreach (RectTransform child in rectTransform) {
  934. UnityEngine.UI.MaskableGraphic uiImage = child.GetComponent<UnityEngine.UI.Image>();
  935. if (uiImage != null) {
  936. Color c = uiImage.color; c.a = val; uiImage.color = c;
  937. } else {
  938. uiImage = child.GetComponent<UnityEngine.UI.RawImage>();
  939. if (uiImage != null) {
  940. Color c = uiImage.color; c.a = val; uiImage.color = c;
  941. }
  942. }
  943. alphaRecursive(child, val, recursiveLevel + 1);
  944. }
  945. }
  946. }
  947. private static void alphaRecursiveSprite( Transform transform, float val ){
  948. if(transform.childCount>0){
  949. foreach (Transform child in transform) {
  950. SpriteRenderer ren = child.GetComponent<SpriteRenderer>();
  951. if(ren!=null)
  952. ren.color = new Color( ren.color.r, ren.color.g, ren.color.b, val);
  953. alphaRecursiveSprite(child, val);
  954. }
  955. }
  956. }
  957. private static void colorRecursiveSprite( Transform transform, Color toColor ){
  958. if(transform.childCount>0){
  959. foreach (Transform child in transform) {
  960. SpriteRenderer ren = transform.gameObject.GetComponent<SpriteRenderer>();
  961. if(ren!=null)
  962. ren.color = toColor;
  963. colorRecursiveSprite(child, toColor);
  964. }
  965. }
  966. }
  967. private static void colorRecursive( RectTransform rectTransform, Color toColor ){
  968. if(rectTransform.childCount>0){
  969. foreach (RectTransform child in rectTransform) {
  970. UnityEngine.UI.MaskableGraphic uiImage = child.GetComponent<UnityEngine.UI.Image>();
  971. if (uiImage != null) {
  972. uiImage.color = toColor;
  973. } else {
  974. uiImage = child.GetComponent<UnityEngine.UI.RawImage>();
  975. if (uiImage != null)
  976. uiImage.color = toColor;
  977. }
  978. colorRecursive(child, toColor);
  979. }
  980. }
  981. }
  982. private static void textAlphaRecursive( Transform trans, float val, bool useRecursion = true ){
  983. UnityEngine.UI.Text uiText = trans.gameObject.GetComponent<UnityEngine.UI.Text>();
  984. if(uiText!=null){
  985. Color c = uiText.color;
  986. c.a = val;
  987. uiText.color = c;
  988. }
  989. if(useRecursion && trans.childCount>0){
  990. foreach (Transform child in trans) {
  991. textAlphaRecursive(child, val);
  992. }
  993. }
  994. }
  995. private static void textColorRecursive(Transform trans, Color toColor ){
  996. if(trans.childCount>0){
  997. foreach (Transform child in trans) {
  998. UnityEngine.UI.Text uiText = child.gameObject.GetComponent<UnityEngine.UI.Text>();
  999. if(uiText!=null){
  1000. uiText.color = toColor;
  1001. }
  1002. textColorRecursive(child, toColor);
  1003. }
  1004. }
  1005. }
  1006. #endif
  1007. private static Color tweenColor( LTDescr tween, float val ){
  1008. Vector3 diff3 = tween._optional.point - tween._optional.axis;
  1009. float diffAlpha = tween.to.y - tween.from.y;
  1010. 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);
  1011. }
  1012. /**
  1013. * Pause a tween
  1014. *
  1015. * @method pause
  1016. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1017. */
  1018. public LTDescr pause(){
  1019. if(this.direction != 0.0f){ // check if tween is already paused
  1020. this.directionLast = this.direction;
  1021. this.direction = 0.0f;
  1022. }
  1023. return this;
  1024. }
  1025. /**
  1026. * Resume a paused tween
  1027. *
  1028. * @method resume
  1029. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1030. */
  1031. public LTDescr resume(){
  1032. this.direction = this.directionLast;
  1033. return this;
  1034. }
  1035. public LTDescr setAxis( Vector3 axis ){
  1036. this._optional.axis = axis;
  1037. return this;
  1038. }
  1039. /**
  1040. * Delay the start of a tween
  1041. *
  1042. * @method setDelay
  1043. * @param {float} float time The time to complete the tween in
  1044. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1045. * @example
  1046. * LeanTween.moveX(gameObject, 5f, 2.0f ).setDelay( 1.5f );
  1047. */
  1048. public LTDescr setDelay( float delay ){
  1049. this.delay = delay;
  1050. return this;
  1051. }
  1052. /**
  1053. * Set the type of easing used for the tween. <br>
  1054. * <ul><li><a href="LeanTweenType.html">List of all the ease types</a>.</li>
  1055. * <li><a href="http://www.robertpenner.com/easing/easing_demo.html">This page helps visualize the different easing equations</a></li>
  1056. * </ul>
  1057. *
  1058. * @method setEase
  1059. * @param {LeanTweenType} easeType:LeanTweenType the easing type to use
  1060. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1061. * @example
  1062. * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce );
  1063. */
  1064. public LTDescr setEase( LeanTweenType easeType ){
  1065. switch( easeType ){
  1066. case LeanTweenType.linear:
  1067. setEaseLinear(); break;
  1068. case LeanTweenType.easeOutQuad:
  1069. setEaseOutQuad(); break;
  1070. case LeanTweenType.easeInQuad:
  1071. setEaseInQuad(); break;
  1072. case LeanTweenType.easeInOutQuad:
  1073. setEaseInOutQuad(); break;
  1074. case LeanTweenType.easeInCubic:
  1075. setEaseInCubic();break;
  1076. case LeanTweenType.easeOutCubic:
  1077. setEaseOutCubic(); break;
  1078. case LeanTweenType.easeInOutCubic:
  1079. setEaseInOutCubic(); break;
  1080. case LeanTweenType.easeInQuart:
  1081. setEaseInQuart(); break;
  1082. case LeanTweenType.easeOutQuart:
  1083. setEaseOutQuart(); break;
  1084. case LeanTweenType.easeInOutQuart:
  1085. setEaseInOutQuart(); break;
  1086. case LeanTweenType.easeInQuint:
  1087. setEaseInQuint(); break;
  1088. case LeanTweenType.easeOutQuint:
  1089. setEaseOutQuint(); break;
  1090. case LeanTweenType.easeInOutQuint:
  1091. setEaseInOutQuint(); break;
  1092. case LeanTweenType.easeInSine:
  1093. setEaseInSine(); break;
  1094. case LeanTweenType.easeOutSine:
  1095. setEaseOutSine(); break;
  1096. case LeanTweenType.easeInOutSine:
  1097. setEaseInOutSine(); break;
  1098. case LeanTweenType.easeInExpo:
  1099. setEaseInExpo(); break;
  1100. case LeanTweenType.easeOutExpo:
  1101. setEaseOutExpo(); break;
  1102. case LeanTweenType.easeInOutExpo:
  1103. setEaseInOutExpo(); break;
  1104. case LeanTweenType.easeInCirc:
  1105. setEaseInCirc(); break;
  1106. case LeanTweenType.easeOutCirc:
  1107. setEaseOutCirc(); break;
  1108. case LeanTweenType.easeInOutCirc:
  1109. setEaseInOutCirc(); break;
  1110. case LeanTweenType.easeInBounce:
  1111. setEaseInBounce(); break;
  1112. case LeanTweenType.easeOutBounce:
  1113. setEaseOutBounce(); break;
  1114. case LeanTweenType.easeInOutBounce:
  1115. setEaseInOutBounce(); break;
  1116. case LeanTweenType.easeInBack:
  1117. setEaseInBack(); break;
  1118. case LeanTweenType.easeOutBack:
  1119. setEaseOutBack(); break;
  1120. case LeanTweenType.easeInOutBack:
  1121. setEaseInOutBack(); break;
  1122. case LeanTweenType.easeInElastic:
  1123. setEaseInElastic(); break;
  1124. case LeanTweenType.easeOutElastic:
  1125. setEaseOutElastic(); break;
  1126. case LeanTweenType.easeInOutElastic:
  1127. setEaseInOutElastic(); break;
  1128. case LeanTweenType.punch:
  1129. setEasePunch(); break;
  1130. case LeanTweenType.easeShake:
  1131. setEaseShake(); break;
  1132. case LeanTweenType.easeSpring:
  1133. setEaseSpring(); break;
  1134. default:
  1135. setEaseLinear(); break;
  1136. }
  1137. return this;
  1138. }
  1139. public LTDescr setEaseLinear(){ this.tweenType = LeanTweenType.linear; this.easeMethod = this.easeLinear; return this; }
  1140. public LTDescr setEaseSpring(){ this.tweenType = LeanTweenType.easeSpring; this.easeMethod = this.easeSpring; return this; }
  1141. public LTDescr setEaseInQuad(){ this.tweenType = LeanTweenType.easeInQuad; this.easeMethod = this.easeInQuad; return this; }
  1142. public LTDescr setEaseOutQuad(){ this.tweenType = LeanTweenType.easeOutQuad; this.easeMethod = this.easeOutQuad; return this; }
  1143. public LTDescr setEaseInOutQuad(){ this.tweenType = LeanTweenType.easeInOutQuad; this.easeMethod = this.easeInOutQuad; return this;}
  1144. public LTDescr setEaseInCubic(){ this.tweenType = LeanTweenType.easeInCubic; this.easeMethod = this.easeInCubic; return this; }
  1145. public LTDescr setEaseOutCubic(){ this.tweenType = LeanTweenType.easeOutCubic; this.easeMethod = this.easeOutCubic; return this; }
  1146. public LTDescr setEaseInOutCubic(){ this.tweenType = LeanTweenType.easeInOutCubic; this.easeMethod = this.easeInOutCubic; return this; }
  1147. public LTDescr setEaseInQuart(){ this.tweenType = LeanTweenType.easeInQuart; this.easeMethod = this.easeInQuart; return this; }
  1148. public LTDescr setEaseOutQuart(){ this.tweenType = LeanTweenType.easeOutQuart; this.easeMethod = this.easeOutQuart; return this; }
  1149. public LTDescr setEaseInOutQuart(){ this.tweenType = LeanTweenType.easeInOutQuart; this.easeMethod = this.easeInOutQuart; return this; }
  1150. public LTDescr setEaseInQuint(){ this.tweenType = LeanTweenType.easeInQuint; this.easeMethod = this.easeInQuint; return this; }
  1151. public LTDescr setEaseOutQuint(){ this.tweenType = LeanTweenType.easeOutQuint; this.easeMethod = this.easeOutQuint; return this; }
  1152. public LTDescr setEaseInOutQuint(){ this.tweenType = LeanTweenType.easeInOutQuint; this.easeMethod = this.easeInOutQuint; return this; }
  1153. public LTDescr setEaseInSine(){ this.tweenType = LeanTweenType.easeInSine; this.easeMethod = this.easeInSine; return this; }
  1154. public LTDescr setEaseOutSine(){ this.tweenType = LeanTweenType.easeOutSine; this.easeMethod = this.easeOutSine; return this; }
  1155. public LTDescr setEaseInOutSine(){ this.tweenType = LeanTweenType.easeInOutSine; this.easeMethod = this.easeInOutSine; return this; }
  1156. public LTDescr setEaseInExpo(){ this.tweenType = LeanTweenType.easeInExpo; this.easeMethod = this.easeInExpo; return this; }
  1157. public LTDescr setEaseOutExpo(){ this.tweenType = LeanTweenType.easeOutExpo; this.easeMethod = this.easeOutExpo; return this; }
  1158. public LTDescr setEaseInOutExpo(){ this.tweenType = LeanTweenType.easeInOutExpo; this.easeMethod = this.easeInOutExpo; return this; }
  1159. public LTDescr setEaseInCirc(){ this.tweenType = LeanTweenType.easeInCirc; this.easeMethod = this.easeInCirc; return this; }
  1160. public LTDescr setEaseOutCirc(){ this.tweenType = LeanTweenType.easeOutCirc; this.easeMethod = this.easeOutCirc; return this; }
  1161. public LTDescr setEaseInOutCirc(){ this.tweenType = LeanTweenType.easeInOutCirc; this.easeMethod = this.easeInOutCirc; return this; }
  1162. public LTDescr setEaseInBounce(){ this.tweenType = LeanTweenType.easeInBounce; this.easeMethod = this.easeInBounce; return this; }
  1163. public LTDescr setEaseOutBounce(){ this.tweenType = LeanTweenType.easeOutBounce; this.easeMethod = this.easeOutBounce; return this; }
  1164. public LTDescr setEaseInOutBounce(){ this.tweenType = LeanTweenType.easeInOutBounce; this.easeMethod = this.easeInOutBounce; return this; }
  1165. public LTDescr setEaseInBack(){ this.tweenType = LeanTweenType.easeInBack; this.easeMethod = this.easeInBack; return this; }
  1166. public LTDescr setEaseOutBack(){ this.tweenType = LeanTweenType.easeOutBack; this.easeMethod = this.easeOutBack; return this; }
  1167. public LTDescr setEaseInOutBack(){ this.tweenType = LeanTweenType.easeInOutBack; this.easeMethod = this.easeInOutBack; return this; }
  1168. public LTDescr setEaseInElastic(){ this.tweenType = LeanTweenType.easeInElastic; this.easeMethod = this.easeInElastic; return this; }
  1169. public LTDescr setEaseOutElastic(){ this.tweenType = LeanTweenType.easeOutElastic; this.easeMethod = this.easeOutElastic; return this; }
  1170. public LTDescr setEaseInOutElastic(){ this.tweenType = LeanTweenType.easeInOutElastic; this.easeMethod = this.easeInOutElastic; return this; }
  1171. public LTDescr setEasePunch(){ this._optional.animationCurve = LeanTween.punch; this.toInternal.x = this.from.x + this.to.x; this.easeMethod = this.tweenOnCurve; return this; }
  1172. public LTDescr setEaseShake(){ this._optional.animationCurve = LeanTween.shake; this.toInternal.x = this.from.x + this.to.x; this.easeMethod = this.tweenOnCurve; return this; }
  1173. private Vector3 tweenOnCurve(){
  1174. return new Vector3(this.from.x + (this.diff.x) * this._optional.animationCurve.Evaluate(ratioPassed),
  1175. this.from.y + (this.diff.y) * this._optional.animationCurve.Evaluate(ratioPassed),
  1176. this.from.z + (this.diff.z) * this._optional.animationCurve.Evaluate(ratioPassed) );
  1177. }
  1178. // Vector3 Ease Methods
  1179. private Vector3 easeInOutQuad(){
  1180. val = this.ratioPassed * 2f;
  1181. if (val < 1f) {
  1182. val = val * val;
  1183. return new Vector3( this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1184. }
  1185. val = (1f-val) * (val - 3f) + 1f;
  1186. return new Vector3( this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1187. }
  1188. private Vector3 easeInQuad(){
  1189. val = ratioPassed * ratioPassed;
  1190. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1191. }
  1192. private Vector3 easeOutQuad(){
  1193. val = this.ratioPassed;
  1194. val = -val * (val - 2f);
  1195. return (this.diff * val + this.from);
  1196. }
  1197. private Vector3 easeLinear(){
  1198. val = this.ratioPassed;
  1199. return new Vector3(this.from.x+this.diff.x*val, this.from.y+this.diff.y*val, this.from.z+this.diff.z*val);
  1200. }
  1201. private Vector3 easeSpring(){
  1202. val = Mathf.Clamp01(this.ratioPassed);
  1203. 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) ));
  1204. return this.from + this.diff * val;
  1205. }
  1206. private Vector3 easeInCubic(){
  1207. val = this.ratioPassed * this.ratioPassed * this.ratioPassed;
  1208. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1209. }
  1210. private Vector3 easeOutCubic(){
  1211. val = this.ratioPassed - 1f;
  1212. val = (val * val * val + 1);
  1213. return new Vector3( this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z) ;
  1214. }
  1215. private Vector3 easeInOutCubic(){
  1216. val = this.ratioPassed * 2f;
  1217. if (val < 1f) {
  1218. val = val * val * val;
  1219. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1220. }
  1221. val -= 2f;
  1222. val = val * val * val + 2f;
  1223. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y,this.diffDiv2.z * val + this.from.z);
  1224. }
  1225. private Vector3 easeInQuart(){
  1226. val = this.ratioPassed * this.ratioPassed * this.ratioPassed * this.ratioPassed;
  1227. return diff * val + this.from;
  1228. }
  1229. private Vector3 easeOutQuart(){
  1230. val = this.ratioPassed - 1f;
  1231. val = -(val * val * val * val - 1);
  1232. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y,this.diff.z * val + this.from.z);
  1233. }
  1234. private Vector3 easeInOutQuart(){
  1235. val = this.ratioPassed * 2f;
  1236. if (val < 1f) {
  1237. val = val * val * val * val;
  1238. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1239. }
  1240. val -= 2f;
  1241. // val = (val * val * val * val - 2f);
  1242. return -this.diffDiv2 * (val * val * val * val - 2f) + this.from;
  1243. }
  1244. private Vector3 easeInQuint(){
  1245. val = this.ratioPassed;
  1246. val = val * val * val * val * val;
  1247. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1248. }
  1249. private Vector3 easeOutQuint(){
  1250. val = this.ratioPassed - 1f;
  1251. val = (val * val * val * val * val + 1f);
  1252. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1253. }
  1254. private Vector3 easeInOutQuint(){
  1255. val = this.ratioPassed * 2f;
  1256. if (val < 1f){
  1257. val = val * val * val * val * val;
  1258. return new Vector3(this.diffDiv2.x * val + this.from.x,this.diffDiv2.y * val + this.from.y,this.diffDiv2.z * val + this.from.z);
  1259. }
  1260. val -= 2f;
  1261. val = (val * val * val * val * val + 2f);
  1262. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1263. }
  1264. private Vector3 easeInSine(){
  1265. val = - Mathf.Cos(this.ratioPassed * LeanTween.PI_DIV2);
  1266. return new Vector3(this.diff.x * val + this.diff.x + this.from.x, this.diff.y * val + this.diff.y + this.from.y, this.diff.z * val + this.diff.z + this.from.z);
  1267. }
  1268. private Vector3 easeOutSine(){
  1269. val = Mathf.Sin(this.ratioPassed * LeanTween.PI_DIV2);
  1270. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y,this.diff.z * val + this.from.z);
  1271. }
  1272. private Vector3 easeInOutSine(){
  1273. val = -(Mathf.Cos(Mathf.PI * this.ratioPassed) - 1f);
  1274. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1275. }
  1276. private Vector3 easeInExpo(){
  1277. val = Mathf.Pow(2f, 10f * (this.ratioPassed - 1f));
  1278. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1279. }
  1280. private Vector3 easeOutExpo(){
  1281. val = (-Mathf.Pow(2f, -10f * this.ratioPassed) + 1f);
  1282. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1283. }
  1284. private Vector3 easeInOutExpo(){
  1285. val = this.ratioPassed * 2f;
  1286. val = Mathf.Pow(2f, 10f * (val - 1f));
  1287. if (val < 1f)
  1288. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1289. val--;
  1290. val = (-Mathf.Pow(2f, -10f * val) + 2f);
  1291. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1292. }
  1293. private Vector3 easeInCirc(){
  1294. val = -(Mathf.Sqrt(1f - this.ratioPassed * this.ratioPassed) - 1f);
  1295. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1296. }
  1297. private Vector3 easeOutCirc(){
  1298. val = this.ratioPassed - 1f;
  1299. val = Mathf.Sqrt(1f - val * val);
  1300. return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
  1301. }
  1302. private Vector3 easeInOutCirc(){
  1303. val = this.ratioPassed * 2f;
  1304. if (val < 1f){
  1305. val = -(Mathf.Sqrt(1f - val * val) - 1f);
  1306. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1307. }
  1308. val -= 2f;
  1309. val = (Mathf.Sqrt(1f - val * val) + 1f);
  1310. return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
  1311. }
  1312. private Vector3 easeInBounce(){
  1313. val = this.ratioPassed;
  1314. val = 1f - val;
  1315. return new Vector3(this.diff.x - LeanTween.easeOutBounce(0, this.diff.x, val) + this.from.x,
  1316. this.diff.y - LeanTween.easeOutBounce(0, this.diff.y, val) + this.from.y,
  1317. this.diff.z - LeanTween.easeOutBounce(0, this.diff.z, val) + this.from.z);
  1318. }
  1319. private Vector3 easeOutBounce(){
  1320. val = ratioPassed;
  1321. if (val < (1 / 2.75f)){
  1322. val = (7.5625f * val * val);
  1323. return this.diff * val + this.from;
  1324. }else if (val < (2 / 2.75f)){
  1325. val -= (1.5f / 2.75f);
  1326. val = (7.5625f * (val) * val + .75f);
  1327. return this.diff * val + this.from;
  1328. }else if (val < (2.5 / 2.75)){
  1329. val -= (2.25f / 2.75f);
  1330. val = (7.5625f * (val) * val + .9375f);
  1331. return this.diff * val + this.from;
  1332. }else{
  1333. val -= (2.625f / 2.75f);
  1334. val = 7.5625f * (val) * val + .984375f;
  1335. return this.diff * val + this.from;
  1336. }
  1337. }
  1338. private Vector3 easeInOutBounce(){
  1339. val = this.ratioPassed * 2f;
  1340. if (val < 1f){
  1341. return new Vector3(LeanTween.easeInBounce(0, this.diff.x, val) * 0.5f + this.from.x,
  1342. LeanTween.easeInBounce(0, this.diff.y, val) * 0.5f + this.from.y,
  1343. LeanTween.easeInBounce(0, this.diff.z, val) * 0.5f + this.from.z);
  1344. }else {
  1345. val = val - 1f;
  1346. return new Vector3(LeanTween.easeOutBounce(0, this.diff.x, val) * 0.5f + this.diffDiv2.x + this.from.x,
  1347. LeanTween.easeOutBounce(0, this.diff.y, val) * 0.5f + this.diffDiv2.y + this.from.y,
  1348. LeanTween.easeOutBounce(0, this.diff.z, val) * 0.5f + this.diffDiv2.z + this.from.z);
  1349. }
  1350. }
  1351. private Vector3 easeInBack(){
  1352. val = this.ratioPassed;
  1353. val /= 1;
  1354. float s = 1.70158f * this.overshoot;
  1355. return this.diff * (val) * val * ((s + 1) * val - s) + this.from;
  1356. }
  1357. private Vector3 easeOutBack(){
  1358. float s = 1.70158f * this.overshoot;
  1359. val = (this.ratioPassed / 1) - 1;
  1360. val = ((val) * val * ((s + 1) * val + s) + 1);
  1361. return this.diff * val + this.from;
  1362. }
  1363. private Vector3 easeInOutBack(){
  1364. float s = 1.70158f * this.overshoot;
  1365. val = this.ratioPassed * 2f;
  1366. if ((val) < 1){
  1367. s *= (1.525f) * overshoot;
  1368. return this.diffDiv2 * (val * val * (((s) + 1) * val - s)) + this.from;
  1369. }
  1370. val -= 2;
  1371. s *= (1.525f) * overshoot;
  1372. val = ((val) * val * (((s) + 1) * val + s) + 2);
  1373. return this.diffDiv2 * val + this.from;
  1374. }
  1375. private Vector3 easeInElastic(){
  1376. return new Vector3(LeanTween.easeInElastic(this.from.x,this.to.x,this.ratioPassed,this.overshoot,this.period),
  1377. LeanTween.easeInElastic(this.from.y,this.to.y,this.ratioPassed,this.overshoot,this.period),
  1378. LeanTween.easeInElastic(this.from.z,this.to.z,this.ratioPassed,this.overshoot,this.period));
  1379. }
  1380. private Vector3 easeOutElastic(){
  1381. return new Vector3(LeanTween.easeOutElastic(this.from.x,this.to.x,this.ratioPassed,this.overshoot,this.period),
  1382. LeanTween.easeOutElastic(this.from.y,this.to.y,this.ratioPassed,this.overshoot,this.period),
  1383. LeanTween.easeOutElastic(this.from.z,this.to.z,this.ratioPassed,this.overshoot,this.period));
  1384. }
  1385. private Vector3 easeInOutElastic()
  1386. {
  1387. return new Vector3(LeanTween.easeInOutElastic(this.from.x,this.to.x,this.ratioPassed,this.overshoot,this.period),
  1388. LeanTween.easeInOutElastic(this.from.y,this.to.y,this.ratioPassed,this.overshoot,this.period),
  1389. LeanTween.easeInOutElastic(this.from.z,this.to.z,this.ratioPassed,this.overshoot,this.period));
  1390. }
  1391. /**
  1392. * Set how far past a tween will overshoot for certain ease types (compatible: easeInBack, easeInOutBack, easeOutBack, easeOutElastic, easeInElastic, easeInOutElastic). <br>
  1393. * @method setOvershoot
  1394. * @param {float} overshoot:float how far past the destination it will go before settling in
  1395. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1396. * @example
  1397. * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutBack ).setOvershoot(2f);
  1398. */
  1399. public LTDescr setOvershoot( float overshoot ){
  1400. this.overshoot = overshoot;
  1401. return this;
  1402. }
  1403. /**
  1404. * Set how short the iterations are for certain ease types (compatible: easeOutElastic, easeInElastic, easeInOutElastic). <br>
  1405. * @method setPeriod
  1406. * @param {float} period:float how short the iterations are that the tween will animate at (default 0.3f)
  1407. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1408. * @example
  1409. * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutElastic ).setPeriod(0.3f);
  1410. */
  1411. public LTDescr setPeriod( float period ){
  1412. this.period = period;
  1413. return this;
  1414. }
  1415. /**
  1416. * Set how large the effect is for certain ease types (compatible: punch, shake, animation curves). <br>
  1417. * @method setScale
  1418. * @param {float} scale:float how much the ease will be multiplied by (default 1f)
  1419. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1420. * @example
  1421. * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.punch ).setScale(2f);
  1422. */
  1423. public LTDescr setScale( float scale ){
  1424. this.scale = scale;
  1425. return this;
  1426. }
  1427. /**
  1428. * Set the type of easing used for the tween with a custom curve. <br>
  1429. * @method setEase (AnimationCurve)
  1430. * @param {AnimationCurve} easeDefinition:AnimationCurve an <a href="http://docs.unity3d.com/Documentation/ScriptReference/AnimationCurve.html" target="_blank">AnimationCure</a> that describes the type of easing you want, this is great for when you want a unique type of movement
  1431. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1432. * @example
  1433. * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce );
  1434. */
  1435. public LTDescr setEase( AnimationCurve easeCurve ){
  1436. this._optional.animationCurve = easeCurve;
  1437. this.easeMethod = this.tweenOnCurve;
  1438. this.tweenType = LeanTweenType.animationCurve;
  1439. return this;
  1440. }
  1441. /**
  1442. * Set the end that the GameObject is tweening towards
  1443. * @method setTo
  1444. * @param {Vector3} to:Vector3 point at which you want the tween to reach
  1445. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1446. * @example
  1447. * LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setEase( LeanTweenType.easeInOutBounce );<br>
  1448. * // Later your want to change your destination or your destiation is constantly moving<br>
  1449. * descr.setTo( new Vector3(5f,10f,3f) );<br>
  1450. */
  1451. public LTDescr setTo( Vector3 to ){
  1452. if(this.hasInitiliazed){
  1453. this.to = to;
  1454. this.diff = to - this.from;
  1455. }else{
  1456. this.to = to;
  1457. }
  1458. return this;
  1459. }
  1460. public LTDescr setTo( Transform to ){
  1461. this._optional.toTrans = to;
  1462. return this;
  1463. }
  1464. /**
  1465. * Set the beginning of the tween
  1466. * @method setFrom
  1467. * @param {Vector3} from:Vector3 the point you would like the tween to start at
  1468. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1469. * @example
  1470. * LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setFrom( new Vector3(5f,10f,3f) );<br>
  1471. */
  1472. public LTDescr setFrom( Vector3 from ){
  1473. if(this.trans){
  1474. this.init();
  1475. }
  1476. this.from = from;
  1477. // this.hasInitiliazed = true; // this is set, so that the "from" value isn't overwritten later on when the tween starts
  1478. this.diff = this.to - this.from;
  1479. return this;
  1480. }
  1481. public LTDescr setFrom( float from ){
  1482. return setFrom( new Vector3(from, 0f, 0f) );
  1483. }
  1484. public LTDescr setDiff( Vector3 diff ){
  1485. this.diff = diff;
  1486. return this;
  1487. }
  1488. public LTDescr setHasInitialized( bool has ){
  1489. this.hasInitiliazed = has;
  1490. return this;
  1491. }
  1492. public LTDescr setId( uint id ){
  1493. this._id = id;
  1494. this.counter = global_counter;
  1495. // Debug.Log("Global counter:"+global_counter);
  1496. return this;
  1497. }
  1498. /**
  1499. * Set the finish time of the tween
  1500. * @method setTime
  1501. * @param {float} finishTime:float the length of time in seconds you wish the tween to complete in
  1502. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1503. * @example
  1504. * int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;<br>
  1505. * // Later<br>
  1506. * LTDescr descr = description( tweenId );<br>
  1507. * descr.setTime( 1f );<br>
  1508. */
  1509. public LTDescr setTime( float time ){
  1510. float passedTimeRatio = this.passed / this.time;
  1511. this.passed = time * passedTimeRatio;
  1512. this.time = time;
  1513. return this;
  1514. }
  1515. /**
  1516. * Set the finish time of the tween
  1517. * @method setSpeed
  1518. * @param {float} speed:float the speed in unity units per second you wish the object to travel (overrides the given time)
  1519. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1520. * @example
  1521. * LeanTween.moveLocalZ( gameObject, 10f, 1f).setSpeed(0.2f) // the given time is ignored when speed is set<br>
  1522. */
  1523. public LTDescr setSpeed( float speed ){
  1524. this.speed = speed;
  1525. if(this.hasInitiliazed)
  1526. initSpeed();
  1527. return this;
  1528. }
  1529. /**
  1530. * Set the tween to repeat a number of times.
  1531. * @method setRepeat
  1532. * @param {int} repeatNum:int the number of times to repeat the tween. -1 to repeat infinite times
  1533. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1534. * @example
  1535. * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 10 ).setLoopPingPong();
  1536. */
  1537. public LTDescr setRepeat( int repeat ){
  1538. this.loopCount = repeat;
  1539. if((repeat>1 && this.loopType == LeanTweenType.once) || (repeat < 0 && this.loopType == LeanTweenType.once)){
  1540. this.loopType = LeanTweenType.clamp;
  1541. }
  1542. if(this.type==TweenAction.CALLBACK || this.type==TweenAction.CALLBACK_COLOR){
  1543. this.setOnCompleteOnRepeat(true);
  1544. }
  1545. return this;
  1546. }
  1547. public LTDescr setLoopType( LeanTweenType loopType ){
  1548. this.loopType = loopType;
  1549. return this;
  1550. }
  1551. public LTDescr setUseEstimatedTime( bool useEstimatedTime ){
  1552. this.useEstimatedTime = useEstimatedTime;
  1553. this.usesNormalDt = false;
  1554. return this;
  1555. }
  1556. /**
  1557. * 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)
  1558. * @method setIgnoreTimeScale
  1559. * @param {bool} useUnScaledTime:bool whether to use the unscaled time or not
  1560. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1561. * @example
  1562. * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setIgnoreTimeScale( true );
  1563. */
  1564. public LTDescr setIgnoreTimeScale( bool useUnScaledTime ){
  1565. this.useEstimatedTime = useUnScaledTime;
  1566. this.usesNormalDt = false;
  1567. return this;
  1568. }
  1569. /**
  1570. * Use frames when tweening an object, when you don't want the animation to be time-frame independent...
  1571. * @method setUseFrames
  1572. * @param {bool} useFrames:bool whether to use estimated time or not
  1573. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1574. * @example
  1575. * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseFrames( true );
  1576. */
  1577. public LTDescr setUseFrames( bool useFrames ){
  1578. this.useFrames = useFrames;
  1579. this.usesNormalDt = false;
  1580. return this;
  1581. }
  1582. public LTDescr setUseManualTime( bool useManualTime ){
  1583. this.useManualTime = useManualTime;
  1584. this.usesNormalDt = false;
  1585. return this;
  1586. }
  1587. public LTDescr setLoopCount( int loopCount ){
  1588. this.loopType = LeanTweenType.clamp;
  1589. this.loopCount = loopCount;
  1590. return this;
  1591. }
  1592. /**
  1593. * No looping involved, just run once (the default)
  1594. * @method setLoopOnce
  1595. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1596. * @example
  1597. * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopOnce();
  1598. */
  1599. public LTDescr setLoopOnce(){ this.loopType = LeanTweenType.once; return this; }
  1600. /**
  1601. * When the animation gets to the end it starts back at where it began
  1602. * @method setLoopClamp
  1603. * @param {int} loops:int (defaults to -1) how many times you want the loop to happen (-1 for an infinite number of times)
  1604. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1605. * @example
  1606. * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopClamp( 2 );
  1607. */
  1608. public LTDescr setLoopClamp(){
  1609. this.loopType = LeanTweenType.clamp;
  1610. if(this.loopCount==0)
  1611. this.loopCount = -1;
  1612. return this;
  1613. }
  1614. public LTDescr setLoopClamp( int loops ){
  1615. this.loopCount = loops;
  1616. return this;
  1617. }
  1618. /**
  1619. * When the animation gets to the end it then tweens back to where it started (and on, and on)
  1620. * @method setLoopPingPong
  1621. * @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.
  1622. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1623. * @example
  1624. * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopPingPong( 2 );
  1625. */
  1626. public LTDescr setLoopPingPong(){
  1627. this.loopType = LeanTweenType.pingPong;
  1628. if(this.loopCount==0)
  1629. this.loopCount = -1;
  1630. return this;
  1631. }
  1632. public LTDescr setLoopPingPong( int loops ) {
  1633. this.loopType = LeanTweenType.pingPong;
  1634. this.loopCount = loops == -1 ? loops : loops * 2;
  1635. return this;
  1636. }
  1637. /**
  1638. * Have a method called when the tween finishes
  1639. * @method setOnComplete
  1640. * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished(){ }
  1641. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1642. * @example
  1643. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished );
  1644. */
  1645. public LTDescr setOnComplete( Action onComplete ){
  1646. this._optional.onComplete = onComplete;
  1647. this.hasExtraOnCompletes = true;
  1648. return this;
  1649. }
  1650. /**
  1651. * Have a method called when the tween finishes
  1652. * @method setOnComplete (object)
  1653. * @param {Action<object>} onComplete:Action<object> the method that should be called when the tween is finished ex: tweenFinished( object myObj ){ }
  1654. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1655. * @example
  1656. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished );
  1657. */
  1658. public LTDescr setOnComplete( Action<object> onComplete ){
  1659. this._optional.onCompleteObject = onComplete;
  1660. this.hasExtraOnCompletes = true;
  1661. return this;
  1662. }
  1663. public LTDescr setOnComplete( Action<object> onComplete, object onCompleteParam ){
  1664. this._optional.onCompleteObject = onComplete;
  1665. this.hasExtraOnCompletes = true;
  1666. if(onCompleteParam!=null)
  1667. this._optional.onCompleteParam = onCompleteParam;
  1668. return this;
  1669. }
  1670. /**
  1671. * Pass an object to along with the onComplete Function
  1672. * @method setOnCompleteParam
  1673. * @param {object} onComplete:object an object that
  1674. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1675. * @example
  1676. * LeanTween.delayedCall(1.5f, enterMiniGameStart).setOnCompleteParam( new object[]{""+5} );<br><br>
  1677. * void enterMiniGameStart( object val ){<br>
  1678. * &nbsp;object[] arr = (object [])val;<br>
  1679. * &nbsp;int lvl = int.Parse((string)arr[0]);<br>
  1680. * }<br>
  1681. */
  1682. public LTDescr setOnCompleteParam( object onCompleteParam ){
  1683. this._optional.onCompleteParam = onCompleteParam;
  1684. this.hasExtraOnCompletes = true;
  1685. return this;
  1686. }
  1687. /**
  1688. * Have a method called on each frame that the tween is being animated (passes a float value)
  1689. * @method setOnUpdate
  1690. * @param {Action<float>} onUpdate:Action<float> a method that will be called on every frame with the float value of the tweened object
  1691. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1692. * @example
  1693. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );<br>
  1694. * <br>
  1695. * void tweenMoved( float val ){ }<br>
  1696. */
  1697. public LTDescr setOnUpdate( Action<float> onUpdate ){
  1698. this._optional.onUpdateFloat = onUpdate;
  1699. this.hasUpdateCallback = true;
  1700. return this;
  1701. }
  1702. public LTDescr setOnUpdateRatio(Action<float,float> onUpdate)
  1703. {
  1704. this._optional.onUpdateFloatRatio = onUpdate;
  1705. this.hasUpdateCallback = true;
  1706. return this;
  1707. }
  1708. public LTDescr setOnUpdateObject( Action<float,object> onUpdate ){
  1709. this._optional.onUpdateFloatObject = onUpdate;
  1710. this.hasUpdateCallback = true;
  1711. return this;
  1712. }
  1713. public LTDescr setOnUpdateVector2( Action<Vector2> onUpdate ){
  1714. this._optional.onUpdateVector2 = onUpdate;
  1715. this.hasUpdateCallback = true;
  1716. return this;
  1717. }
  1718. public LTDescr setOnUpdateVector3( Action<Vector3> onUpdate ){
  1719. this._optional.onUpdateVector3 = onUpdate;
  1720. this.hasUpdateCallback = true;
  1721. return this;
  1722. }
  1723. public LTDescr setOnUpdateColor( Action<Color> onUpdate ){
  1724. this._optional.onUpdateColor = onUpdate;
  1725. this.hasUpdateCallback = true;
  1726. return this;
  1727. }
  1728. public LTDescr setOnUpdateColor( Action<Color,object> onUpdate ){
  1729. this._optional.onUpdateColorObject = onUpdate;
  1730. this.hasUpdateCallback = true;
  1731. return this;
  1732. }
  1733. #if !UNITY_FLASH
  1734. public LTDescr setOnUpdate( Action<Color> onUpdate ){
  1735. this._optional.onUpdateColor = onUpdate;
  1736. this.hasUpdateCallback = true;
  1737. return this;
  1738. }
  1739. public LTDescr setOnUpdate( Action<Color,object> onUpdate ){
  1740. this._optional.onUpdateColorObject = onUpdate;
  1741. this.hasUpdateCallback = true;
  1742. return this;
  1743. }
  1744. /**
  1745. * Have a method called on each frame that the tween is being animated (passes a float value and a object)
  1746. * @method setOnUpdate (object)
  1747. * @param {Action<float,object>} onUpdate:Action<float,object> 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
  1748. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1749. * @example
  1750. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );<br>
  1751. * <br>
  1752. * void tweenMoved( float val, object obj ){ }<br>
  1753. */
  1754. public LTDescr setOnUpdate( Action<float,object> onUpdate, object onUpdateParam = null ){
  1755. this._optional.onUpdateFloatObject = onUpdate;
  1756. this.hasUpdateCallback = true;
  1757. if(onUpdateParam!=null)
  1758. this._optional.onUpdateParam = onUpdateParam;
  1759. return this;
  1760. }
  1761. public LTDescr setOnUpdate( Action<Vector3,object> onUpdate, object onUpdateParam = null ){
  1762. this._optional.onUpdateVector3Object = onUpdate;
  1763. this.hasUpdateCallback = true;
  1764. if(onUpdateParam!=null)
  1765. this._optional.onUpdateParam = onUpdateParam;
  1766. return this;
  1767. }
  1768. public LTDescr setOnUpdate( Action<Vector2> onUpdate, object onUpdateParam = null ){
  1769. this._optional.onUpdateVector2 = onUpdate;
  1770. this.hasUpdateCallback = true;
  1771. if(onUpdateParam!=null)
  1772. this._optional.onUpdateParam = onUpdateParam;
  1773. return this;
  1774. }
  1775. /**
  1776. * Have a method called on each frame that the tween is being animated (passes a float value)
  1777. * @method setOnUpdate (Vector3)
  1778. * @param {Action<Vector3>} onUpdate:Action<Vector3> a method that will be called on every frame with the float value of the tweened object
  1779. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1780. * @example
  1781. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );<br>
  1782. * <br>
  1783. * void tweenMoved( Vector3 val ){ }<br>
  1784. */
  1785. public LTDescr setOnUpdate( Action<Vector3> onUpdate, object onUpdateParam = null ){
  1786. this._optional.onUpdateVector3 = onUpdate;
  1787. this.hasUpdateCallback = true;
  1788. if(onUpdateParam!=null)
  1789. this._optional.onUpdateParam = onUpdateParam;
  1790. return this;
  1791. }
  1792. #endif
  1793. /**
  1794. * Have an object passed along with the onUpdate method
  1795. * @method setOnUpdateParam
  1796. * @param {object} onUpdateParam:object an object that will be passed along with the onUpdate method
  1797. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1798. * @example
  1799. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );<br>
  1800. * <br>
  1801. * void tweenMoved( float val, object obj ){ }<br>
  1802. */
  1803. public LTDescr setOnUpdateParam( object onUpdateParam ){
  1804. this._optional.onUpdateParam = onUpdateParam;
  1805. return this;
  1806. }
  1807. /**
  1808. * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon
  1809. * @method setOrientToPath
  1810. * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along
  1811. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1812. * @example
  1813. * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);<br>
  1814. */
  1815. public LTDescr setOrientToPath( bool doesOrient ){
  1816. if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){
  1817. if(this._optional.path==null)
  1818. this._optional.path = new LTBezierPath();
  1819. this._optional.path.orientToPath = doesOrient;
  1820. }else{
  1821. this._optional.spline.orientToPath = doesOrient;
  1822. }
  1823. return this;
  1824. }
  1825. /**
  1826. * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon
  1827. * @method setOrientToPath2d
  1828. * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along
  1829. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1830. * @example
  1831. * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath2d(true).setAxis(Vector3.forward);<br>
  1832. */
  1833. public LTDescr setOrientToPath2d( bool doesOrient2d ){
  1834. setOrientToPath(doesOrient2d);
  1835. if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){
  1836. this._optional.path.orientToPath2d = doesOrient2d;
  1837. }else{
  1838. this._optional.spline.orientToPath2d = doesOrient2d;
  1839. }
  1840. return this;
  1841. }
  1842. public LTDescr setRect( LTRect rect ){
  1843. this._optional.ltRect = rect;
  1844. return this;
  1845. }
  1846. public LTDescr setRect( Rect rect ){
  1847. this._optional.ltRect = new LTRect(rect);
  1848. return this;
  1849. }
  1850. public LTDescr setPath( LTBezierPath path ){
  1851. this._optional.path = path;
  1852. return this;
  1853. }
  1854. /**
  1855. * Set the point at which the GameObject will be rotated around
  1856. * @method setPoint
  1857. * @param {Vector3} point:Vector3 point at which you want the object to rotate around (local space)
  1858. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1859. * @example
  1860. * LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ) .setPoint( new Vector3(1f,0f,0f) ) .setEase( LeanTweenType.easeInOutBounce );<br>
  1861. */
  1862. public LTDescr setPoint( Vector3 point ){
  1863. this._optional.point = point;
  1864. return this;
  1865. }
  1866. public LTDescr setDestroyOnComplete( bool doesDestroy ){
  1867. this.destroyOnComplete = doesDestroy;
  1868. return this;
  1869. }
  1870. public LTDescr setAudio( object audio ){
  1871. this._optional.onCompleteParam = audio;
  1872. return this;
  1873. }
  1874. /**
  1875. * Set the onComplete method to be called at the end of every loop cycle (also applies to the delayedCall method)
  1876. * @method setOnCompleteOnRepeat
  1877. * @param {bool} isOn:bool does call onComplete on every loop cycle
  1878. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1879. * @example
  1880. * LeanTween.delayedCall(gameObject,0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true);
  1881. */
  1882. public LTDescr setOnCompleteOnRepeat( bool isOn ){
  1883. this.onCompleteOnRepeat = isOn;
  1884. return this;
  1885. }
  1886. /**
  1887. * Set the onComplete method to be called at the beginning of the tween (it will still be called when it is completed as well)
  1888. * @method setOnCompleteOnStart
  1889. * @param {bool} isOn:bool does call onComplete at the start of the tween
  1890. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1891. * @example
  1892. * LeanTween.delayedCall(gameObject, 2f, ()=>{<br> // Flash an object 5 times
  1893. * &nbsp;LeanTween.alpha(gameObject, 0f, 1f);<br>
  1894. * &nbsp;LeanTween.alpha(gameObject, 1f, 0f).setDelay(1f);<br>
  1895. * }).setOnCompleteOnStart(true).setRepeat(5);<br>
  1896. */
  1897. public LTDescr setOnCompleteOnStart( bool isOn ){
  1898. this.onCompleteOnStart = isOn;
  1899. return this;
  1900. }
  1901. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  1902. public LTDescr setRect( RectTransform rect ){
  1903. this.rectTransform = rect;
  1904. return this;
  1905. }
  1906. public LTDescr setSprites( UnityEngine.Sprite[] sprites ){
  1907. this.sprites = sprites;
  1908. return this;
  1909. }
  1910. public LTDescr setFrameRate( float frameRate ){
  1911. this.time = this.sprites.Length / frameRate;
  1912. return this;
  1913. }
  1914. #endif
  1915. /**
  1916. * Have a method called when the tween starts
  1917. * @method setOnStart
  1918. * @param {Action<>} onStart:Action<> the method that should be called when the tween is starting ex: tweenStarted( ){ }
  1919. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1920. * @example
  1921. * <i>C#:</i><br>
  1922. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( ()=>{ Debug.Log("I started!"); });
  1923. * <i>Javascript:</i><br>
  1924. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( function(){ Debug.Log("I started!"); } );
  1925. */
  1926. public LTDescr setOnStart( Action onStart ){
  1927. this._optional.onStart = onStart;
  1928. return this;
  1929. }
  1930. /**
  1931. * Set the direction of a tween -1f for backwards 1f for forwards (currently only bezier and spline paths are supported)
  1932. * @method setDirection
  1933. * @param {float} direction:float the direction that the tween should run, -1f for backwards 1f for forwards
  1934. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1935. * @example
  1936. * 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);<br>
  1937. */
  1938. public LTDescr setDirection( float direction ){
  1939. if(this.direction!=-1f && this.direction!=1f){
  1940. Debug.LogWarning("You have passed an incorrect direction of '"+direction+"', direction must be -1f or 1f");
  1941. return this;
  1942. }
  1943. if(this.direction!=direction){
  1944. // Debug.Log("reverse path:"+this.path+" spline:"+this._optional.spline+" hasInitiliazed:"+this.hasInitiliazed);
  1945. if(this.hasInitiliazed){
  1946. this.direction = direction;
  1947. }else{
  1948. if(this._optional.path!=null){
  1949. this._optional.path = new LTBezierPath( LTUtility.reverse( this._optional.path.pts ) );
  1950. }else if(this._optional.spline!=null){
  1951. this._optional.spline = new LTSpline( LTUtility.reverse( this._optional.spline.pts ) );
  1952. }
  1953. // this.passed = this.time - this.passed;
  1954. }
  1955. }
  1956. return this;
  1957. }
  1958. /**
  1959. * Set whether or not the tween will recursively effect an objects children in the hierarchy
  1960. * @method setRecursive
  1961. * @param {bool} useRecursion:bool whether the tween will recursively effect an objects children in the hierarchy
  1962. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1963. * @example
  1964. * LeanTween.alpha(gameObject, 0f, 1f).setRecursive(true);<br>
  1965. */
  1966. public LTDescr setRecursive( bool useRecursion ){
  1967. this.useRecursion = useRecursion;
  1968. return this;
  1969. }
  1970. }
  1971. //}