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.

2285 lines
79 KiB

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