LTDescr.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283
  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. private LeanTweenType easeType;
  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. public override string ToString(){
  89. 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;
  90. }
  91. public LTDescr(){
  92. }
  93. [System.Obsolete("Use 'LeanTween.cancel( id )' instead")]
  94. public LTDescr cancel( GameObject gameObject ){
  95. // Debug.Log("canceling id:"+this._id+" this.uniqueId:"+this.uniqueId+" go:"+this.trans.gameObject);
  96. if(gameObject==this.trans.gameObject)
  97. LeanTween.removeTween((int)this._id, this.uniqueId);
  98. return this;
  99. }
  100. public int uniqueId{
  101. get{
  102. uint toId = _id | counter << 16;
  103. /*uint backId = toId & 0xFFFF;
  104. uint backCounter = toId >> 16;
  105. if(_id!=backId || backCounter!=counter){
  106. Debug.LogError("BAD CONVERSION toId:"+_id);
  107. }*/
  108. return (int)toId;
  109. }
  110. }
  111. public int id{
  112. get{
  113. return uniqueId;
  114. }
  115. }
  116. public LTDescrOptional optional{
  117. get{
  118. return _optional;
  119. }
  120. set{
  121. this._optional = optional;
  122. }
  123. }
  124. public void reset(){
  125. this.toggle = this.useRecursion = this.usesNormalDt = true;
  126. this.trans = null;
  127. this.spriteRen = 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.easeType = 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. }
  140. // Initialize and Internal Methods
  141. public LTDescr setMoveX(){
  142. this.type = TweenAction.MOVE_X;
  143. this.initInternal = ()=>{ this.fromInternal.x = trans.position.x; };
  144. this.easeInternal = ()=>{ trans.position=new Vector3( easeMethod().x,trans.position.y,trans.position.z); };
  145. return this;
  146. }
  147. public LTDescr setMoveY(){
  148. this.type = TweenAction.MOVE_Y;
  149. this.initInternal = ()=>{ this.fromInternal.x = trans.position.y; };
  150. this.easeInternal = ()=>{ trans.position=new Vector3( trans.position.x,easeMethod().x,trans.position.z); };
  151. return this;
  152. }
  153. public LTDescr setMoveZ(){
  154. this.type = TweenAction.MOVE_Z;
  155. this.initInternal = ()=>{ this.fromInternal.x = trans.position.z; };;
  156. this.easeInternal = ()=>{ trans.position=new Vector3( trans.position.x,trans.position.y,easeMethod().x); };
  157. return this;
  158. }
  159. public LTDescr setMoveLocalX(){
  160. this.type = TweenAction.MOVE_LOCAL_X;
  161. this.initInternal = ()=>{ this.fromInternal.x = trans.localPosition.x; };
  162. this.easeInternal = ()=>{ trans.localPosition=new Vector3( easeMethod().x,trans.localPosition.y,trans.localPosition.z); };
  163. return this;
  164. }
  165. public LTDescr setMoveLocalY(){
  166. this.type = TweenAction.MOVE_LOCAL_Y;
  167. this.initInternal = ()=>{ this.fromInternal.x = trans.localPosition.y; };
  168. this.easeInternal = ()=>{ trans.localPosition=new Vector3( trans.localPosition.x,easeMethod().x,trans.localPosition.z); };
  169. return this;
  170. }
  171. public LTDescr setMoveLocalZ(){
  172. this.type = TweenAction.MOVE_LOCAL_Z;
  173. this.initInternal = ()=>{ this.fromInternal.x = trans.localPosition.z; };
  174. this.easeInternal = ()=>{ trans.localPosition=new Vector3( trans.localPosition.x,trans.localPosition.y,easeMethod().x); };
  175. return this;
  176. }
  177. private void initFromInternal(){ this.fromInternal.x = 0; }
  178. public LTDescr setMoveCurved(){
  179. this.type = TweenAction.MOVE_CURVED;
  180. this.initInternal = this.initFromInternal;
  181. this.easeInternal = ()=>{
  182. newVect = easeMethod();
  183. val = newVect.x;
  184. if(this._optional.path.orientToPath){
  185. if(this._optional.path.orientToPath2d){
  186. this._optional.path.place2d( trans, val );
  187. }else{
  188. this._optional.path.place( trans, val );
  189. }
  190. }else{
  191. trans.position = this._optional.path.point( val );
  192. }
  193. };
  194. return this;
  195. }
  196. public LTDescr setMoveCurvedLocal(){
  197. this.type = TweenAction.MOVE_CURVED_LOCAL;
  198. this.initInternal = this.initFromInternal;
  199. this.easeInternal = ()=>{
  200. newVect = easeMethod();
  201. val = newVect.x;
  202. if(this._optional.path.orientToPath){
  203. if(this._optional.path.orientToPath2d){
  204. this._optional.path.placeLocal2d( trans, val );
  205. }else{
  206. this._optional.path.placeLocal( trans, val );
  207. }
  208. }else{
  209. trans.localPosition = this._optional.path.point( val );
  210. }
  211. };
  212. return this;
  213. }
  214. public LTDescr setMoveSpline(){
  215. this.type = TweenAction.MOVE_SPLINE;
  216. this.initInternal = this.initFromInternal;
  217. this.easeInternal = ()=>{
  218. newVect = easeMethod();
  219. val = newVect.x;
  220. if(this._optional.spline.orientToPath){
  221. if(this._optional.spline.orientToPath2d){
  222. this._optional.spline.place2d( trans, val );
  223. }else{
  224. this._optional.spline.place( trans, val );
  225. }
  226. }else{
  227. trans.position = this._optional.spline.point( val );
  228. }
  229. };
  230. return this;
  231. }
  232. public LTDescr setMoveSplineLocal(){
  233. this.type = TweenAction.MOVE_SPLINE_LOCAL;
  234. this.initInternal = this.initFromInternal;
  235. this.easeInternal = ()=>{
  236. newVect = easeMethod();
  237. val = newVect.x;
  238. if(this._optional.spline.orientToPath){
  239. if(this._optional.spline.orientToPath2d){
  240. this._optional.spline.placeLocal2d( trans, val );
  241. }else{
  242. this._optional.spline.placeLocal( trans, val );
  243. }
  244. }else{
  245. trans.localPosition = this._optional.spline.point( val );
  246. }
  247. };
  248. return this;
  249. }
  250. public LTDescr setScaleX(){
  251. this.type = TweenAction.SCALE_X;
  252. this.initInternal = ()=>{ this.fromInternal.x = trans.localScale.x; };
  253. this.easeInternal = ()=>{ trans.localScale = new Vector3( easeMethod().x,trans.localScale.y,trans.localScale.z); };
  254. return this;
  255. }
  256. public LTDescr setScaleY(){
  257. this.type = TweenAction.SCALE_Y;
  258. this.initInternal = ()=>{ this.fromInternal.x = trans.localScale.y; };
  259. this.easeInternal = ()=>{ trans.localScale=new Vector3( trans.localScale.x,easeMethod().x,trans.localScale.z); };
  260. return this;
  261. }
  262. public LTDescr setScaleZ(){
  263. this.type = TweenAction.SCALE_Z;
  264. this.initInternal = ()=>{ this.fromInternal.x = trans.localScale.z; };
  265. this.easeInternal = ()=>{ trans.localScale=new Vector3( trans.localScale.x,trans.localScale.y,easeMethod().x); };
  266. return this;
  267. }
  268. public LTDescr setRotateX(){
  269. this.type = TweenAction.ROTATE_X;
  270. this.initInternal = ()=>{ this.fromInternal.x = trans.eulerAngles.x; this.toInternal.x = LeanTween.closestRot( this.fromInternal.x, this.toInternal.x);};
  271. this.easeInternal = ()=>{ trans.eulerAngles=new Vector3(easeMethod().x,trans.eulerAngles.y,trans.eulerAngles.z); };
  272. return this;
  273. }
  274. public LTDescr setRotateY(){
  275. this.type = TweenAction.ROTATE_Y;
  276. this.initInternal = ()=>{ this.fromInternal.x = trans.eulerAngles.y; this.toInternal.x = LeanTween.closestRot( this.fromInternal.x, this.toInternal.x);};
  277. this.easeInternal = ()=>{ trans.eulerAngles=new Vector3(trans.eulerAngles.x,easeMethod().x,trans.eulerAngles.z); };
  278. return this;
  279. }
  280. public LTDescr setRotateZ(){
  281. this.type = TweenAction.ROTATE_Z;
  282. this.initInternal = ()=>{
  283. this.fromInternal.x = trans.eulerAngles.z;
  284. this.toInternal.x = LeanTween.closestRot( this.fromInternal.x, this.toInternal.x);
  285. };
  286. this.easeInternal = ()=>{ trans.eulerAngles=new Vector3(trans.eulerAngles.x,trans.eulerAngles.y,easeMethod().x); };
  287. return this;
  288. }
  289. public LTDescr setRotateAround(){
  290. this.type = TweenAction.ROTATE_AROUND;
  291. this.initInternal = ()=>{
  292. this.fromInternal.x = 0f;
  293. this._optional.origRotation = trans.rotation;
  294. };
  295. this.easeInternal = ()=>{
  296. newVect = easeMethod();
  297. val = newVect.x;
  298. Vector3 origPos = trans.localPosition;
  299. Vector3 rotateAroundPt = (Vector3)trans.TransformPoint( this._optional.point );
  300. // Debug.Log("this._optional.point:"+this._optional.point);
  301. trans.RotateAround(rotateAroundPt, this._optional.axis, -this._optional.lastVal);
  302. Vector3 diff = origPos - trans.localPosition;
  303. 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
  304. trans.rotation = this._optional.origRotation;
  305. rotateAroundPt = (Vector3)trans.TransformPoint( this._optional.point );
  306. trans.RotateAround(rotateAroundPt, this._optional.axis, val);
  307. this._optional.lastVal = val;
  308. };
  309. return this;
  310. }
  311. public LTDescr setRotateAroundLocal(){
  312. this.type = TweenAction.ROTATE_AROUND_LOCAL;
  313. this.initInternal = ()=>{
  314. this.fromInternal.x = 0f;
  315. this._optional.origRotation = trans.localRotation;
  316. };
  317. this.easeInternal = ()=>{
  318. newVect = easeMethod();
  319. val = newVect.x;
  320. Vector3 origPos = trans.localPosition;
  321. trans.RotateAround((Vector3)trans.TransformPoint( this._optional.point ), trans.TransformDirection(this._optional.axis), -this._optional.lastVal);
  322. Vector3 diff = origPos - trans.localPosition;
  323. 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
  324. trans.localRotation = this._optional.origRotation;
  325. Vector3 rotateAroundPt = (Vector3)trans.TransformPoint( this._optional.point );
  326. trans.RotateAround(rotateAroundPt, trans.TransformDirection(this._optional.axis), val);
  327. this._optional.lastVal = val;
  328. };
  329. return this;
  330. }
  331. public LTDescr setAlpha(){
  332. this.type = TweenAction.ALPHA;
  333. this.initInternal = ()=>{
  334. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  335. 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; }}}
  336. this.easeInternal = this.alpha;
  337. break;
  338. #else
  339. SpriteRenderer ren = trans.GetComponent<SpriteRenderer>();
  340. if(ren!=null){
  341. this.fromInternal.x = ren.color.a;
  342. }else{
  343. if(trans.GetComponent<Renderer>()!=null && trans.GetComponent<Renderer>().material.HasProperty("_Color")){
  344. this.fromInternal.x = trans.GetComponent<Renderer>().material.color.a;
  345. }else if(trans.GetComponent<Renderer>()!=null && trans.GetComponent<Renderer>().material.HasProperty("_TintColor")){
  346. Color col = trans.GetComponent<Renderer>().material.GetColor("_TintColor");
  347. this.fromInternal.x = col.a;
  348. }else if(trans.childCount>0){
  349. foreach (Transform child in trans) {
  350. if(child.gameObject.GetComponent<Renderer>()!=null){
  351. Color col = child.gameObject.GetComponent<Renderer>().material.color;
  352. this.fromInternal.x = col.a;
  353. break;
  354. }
  355. }
  356. }
  357. }
  358. #endif
  359. this.easeInternal = ()=>{
  360. val = easeMethod().x;
  361. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  362. alphaRecursive(this.trans, val, this.useRecursion);
  363. #else
  364. if(this.spriteRen!=null){
  365. this.spriteRen.color = new Color( this.spriteRen.color.r, this.spriteRen.color.g, this.spriteRen.color.b, val);
  366. alphaRecursiveSprite(this.trans, val);
  367. }else{
  368. alphaRecursive(this.trans, val, this.useRecursion);
  369. }
  370. #endif
  371. };
  372. };
  373. this.easeInternal = ()=>{
  374. newVect = easeMethod();
  375. val = newVect.x;
  376. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  377. alphaRecursive(this.trans, val, this.useRecursion);
  378. #else
  379. if(this.spriteRen!=null){
  380. this.spriteRen.color = new Color( this.spriteRen.color.r, this.spriteRen.color.g, this.spriteRen.color.b, val);
  381. alphaRecursiveSprite(this.trans, val);
  382. }else{
  383. alphaRecursive(this.trans, val, this.useRecursion);
  384. }
  385. #endif
  386. };
  387. return this;
  388. }
  389. public LTDescr setTextAlpha(){
  390. this.type = TweenAction.TEXT_ALPHA;
  391. this.initInternal = ()=>{
  392. this.uiText = trans.GetComponent<UnityEngine.UI.Text>();
  393. this.fromInternal.x = this.uiText != null ? this.uiText.color.a : 1f;
  394. };
  395. this.easeInternal = ()=>{ textAlphaRecursive( trans, easeMethod().x, this.useRecursion ); };
  396. return this;
  397. }
  398. public LTDescr setAlphaVertex(){
  399. this.type = TweenAction.ALPHA_VERTEX;
  400. this.initInternal = ()=>{ this.fromInternal.x = trans.GetComponent<MeshFilter>().mesh.colors32[0].a; };
  401. this.easeInternal = ()=>{
  402. newVect = easeMethod();
  403. val = newVect.x;
  404. Mesh mesh = trans.GetComponent<MeshFilter>().mesh;
  405. Vector3[] vertices = mesh.vertices;
  406. Color32[] colors = new Color32[vertices.Length];
  407. if (colors.Length == 0){ //MaxFW fix: add vertex colors if the mesh doesn't have any
  408. Color32 transparentWhiteColor32 = new Color32(0xff, 0xff, 0xff, 0x00);
  409. colors = new Color32[mesh.vertices.Length];
  410. for (int k=0; k<colors.Length; k++)
  411. colors[k] = transparentWhiteColor32;
  412. mesh.colors32 = colors;
  413. }// fix end
  414. Color32 c = mesh.colors32[0];
  415. c = new Color( c.r, c.g, c.b, val);
  416. for (int k= 0; k < vertices.Length; k++)
  417. colors[k] = c;
  418. mesh.colors32 = colors;
  419. };
  420. return this;
  421. }
  422. public LTDescr setColor(){
  423. this.type = TweenAction.COLOR;
  424. this.initInternal = ()=>{
  425. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
  426. if(trans.gameObject.renderer){
  427. this.setFromColor( trans.gameObject.renderer.material.color );
  428. }else if(trans.childCount>0){
  429. foreach (Transform child in trans) {
  430. if(child.gameObject.renderer!=null){
  431. this.setFromColor( child.gameObject.renderer.material.color );
  432. break;
  433. }
  434. }
  435. }
  436. #else
  437. SpriteRenderer renColor = trans.GetComponent<SpriteRenderer>();
  438. if(renColor!=null){
  439. this.setFromColor( renColor.color );
  440. }else{
  441. if(trans.GetComponent<Renderer>()!=null && trans.GetComponent<Renderer>().material.HasProperty("_Color")){
  442. Color col = trans.GetComponent<Renderer>().material.color;
  443. this.setFromColor( col );
  444. }else if(trans.GetComponent<Renderer>()!=null && trans.GetComponent<Renderer>().material.HasProperty("_TintColor")){
  445. Color col = trans.GetComponent<Renderer>().material.GetColor ("_TintColor");
  446. this.setFromColor( col );
  447. }else if(trans.childCount>0){
  448. foreach (Transform child in trans) {
  449. if(child.gameObject.GetComponent<Renderer>()!=null){
  450. Color col = child.gameObject.GetComponent<Renderer>().material.color;
  451. this.setFromColor( col );
  452. break;
  453. }
  454. }
  455. }
  456. }
  457. #endif
  458. };
  459. this.easeInternal = ()=>{
  460. newVect = easeMethod();
  461. val = newVect.x;
  462. Color toColor = tweenColor(this, val);
  463. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  464. if(this.spriteRen!=null){
  465. this.spriteRen.color = toColor;
  466. colorRecursiveSprite( trans, toColor);
  467. }else{
  468. #endif
  469. // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
  470. if(this.type==TweenAction.COLOR)
  471. colorRecursive(trans, toColor, this.useRecursion);
  472. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  473. }
  474. #endif
  475. if(dt!=0f && this._optional.onUpdateColor!=null){
  476. this._optional.onUpdateColor(toColor);
  477. }else if(dt!=0f && this._optional.onUpdateColorObject!=null){
  478. this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
  479. }
  480. };
  481. return this;
  482. }
  483. public LTDescr setCallbackColor(){
  484. this.type = TweenAction.CALLBACK_COLOR;
  485. this.initInternal = ()=>{ this.diff = new Vector3(1.0f,0.0f,0.0f); };
  486. this.easeInternal = ()=>{
  487. newVect = easeMethod();
  488. val = newVect.x;
  489. Color toColor = tweenColor(this, val);
  490. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  491. if(this.spriteRen!=null){
  492. this.spriteRen.color = toColor;
  493. colorRecursiveSprite( trans, toColor);
  494. }else{
  495. #endif
  496. // Debug.Log("val:"+val+" tween:"+tween+" tween.diff:"+tween.diff);
  497. if(this.type==TweenAction.COLOR)
  498. colorRecursive(trans, toColor, this.useRecursion);
  499. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  500. }
  501. #endif
  502. if(dt!=0f && this._optional.onUpdateColor!=null){
  503. this._optional.onUpdateColor(toColor);
  504. }else if(dt!=0f && this._optional.onUpdateColorObject!=null){
  505. this._optional.onUpdateColorObject(toColor, this._optional.onUpdateParam);
  506. }
  507. };
  508. return this;
  509. }
  510. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  511. public LTDescr setTextColor(){
  512. this.type = TweenAction.TEXT_COLOR;
  513. this.initInternal = ()=>{
  514. this.uiText = trans.GetComponent<UnityEngine.UI.Text>();
  515. this.setFromColor( this.uiText != null ? this.uiText.color : Color.white );
  516. };
  517. this.easeInternal = ()=>{
  518. newVect = easeMethod();
  519. val = newVect.x;
  520. Color toColor = tweenColor(this, val);
  521. this.uiText.color = toColor;
  522. if (dt!=0f && this._optional.onUpdateColor != null)
  523. this._optional.onUpdateColor(toColor);
  524. if(this.useRecursion && trans.childCount>0)
  525. textColorRecursive(this.trans, toColor);
  526. };
  527. return this;
  528. }
  529. public LTDescr setCanvasAlpha(){
  530. this.type = TweenAction.CANVAS_ALPHA;
  531. this.initInternal = ()=>{
  532. this.uiImage = trans.GetComponent<UnityEngine.UI.Image>();
  533. if(this.uiImage!=null){
  534. this.fromInternal.x = this.uiImage.color.a;
  535. }else{
  536. this.rawImage = trans.GetComponent<UnityEngine.UI.RawImage>();
  537. if(this.rawImage != null){
  538. this.fromInternal.x = this.rawImage.color.a;
  539. }else{
  540. this.fromInternal.x = 1f;
  541. }
  542. }
  543. };
  544. this.easeInternal = ()=>{
  545. newVect = easeMethod();
  546. val = newVect.x;
  547. if(this.uiImage!=null){
  548. Color c = this.uiImage.color; c.a = val; this.uiImage.color = c;
  549. }else if(this.rawImage!=null){
  550. Color c = this.rawImage.color; c.a = val; this.rawImage.color = c;
  551. }
  552. if(this.useRecursion){
  553. alphaRecursive( this.rectTransform, val, 0 );
  554. textAlphaChildrenRecursive( this.rectTransform, val);
  555. }
  556. };
  557. return this;
  558. }
  559. public LTDescr setCanvasGroupAlpha(){
  560. this.type = TweenAction.CANVASGROUP_ALPHA;
  561. this.initInternal = ()=>{this.fromInternal.x = trans.GetComponent<CanvasGroup>().alpha;};
  562. this.easeInternal = ()=>{ this.trans.GetComponent<CanvasGroup>().alpha = easeMethod().x; };
  563. return this;
  564. }
  565. public LTDescr setCanvasColor(){
  566. this.type = TweenAction.CANVAS_COLOR;
  567. this.initInternal = ()=>{
  568. this.uiImage = trans.GetComponent<UnityEngine.UI.Image>();
  569. if(this.uiImage==null){
  570. this.rawImage = trans.GetComponent<UnityEngine.UI.RawImage>();
  571. this.setFromColor( this.rawImage!=null ? this.rawImage.color : Color.white );
  572. }else{
  573. this.setFromColor( this.uiImage.color );
  574. }
  575. };
  576. this.easeInternal = ()=>{
  577. newVect = easeMethod();
  578. val = newVect.x;
  579. Color toColor = tweenColor(this, val);
  580. if(this.uiImage!=null){
  581. this.uiImage.color = toColor;
  582. }else if(this.rawImage!=null){
  583. this.rawImage.color = toColor;
  584. }
  585. if (dt!=0f && this._optional.onUpdateColor != null)
  586. this._optional.onUpdateColor(toColor);
  587. if(this.useRecursion)
  588. colorRecursive(this.rectTransform, toColor);
  589. };
  590. return this;
  591. }
  592. public LTDescr setCanvasMoveX(){
  593. this.type = TweenAction.CANVAS_MOVE_X;
  594. this.initInternal = ()=>{ this.fromInternal.x = this.rectTransform.anchoredPosition3D.x; };
  595. this.easeInternal = ()=>{ Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(easeMethod().x, c.y, c.z); };
  596. return this;
  597. }
  598. public LTDescr setCanvasMoveY(){
  599. this.type = TweenAction.CANVAS_MOVE_Y;
  600. this.initInternal = ()=>{ this.fromInternal.x = this.rectTransform.anchoredPosition3D.y; };
  601. this.easeInternal = ()=>{ Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(c.x, easeMethod().x, c.z); };
  602. return this;
  603. }
  604. public LTDescr setCanvasMoveZ(){
  605. this.type = TweenAction.CANVAS_MOVE_Z;
  606. this.initInternal = ()=>{ this.fromInternal.x = this.rectTransform.anchoredPosition3D.z; };
  607. this.easeInternal = ()=>{ Vector3 c = this.rectTransform.anchoredPosition3D; this.rectTransform.anchoredPosition3D = new Vector3(c.x, c.y, easeMethod().x); };
  608. return this;
  609. }
  610. private void initCanvasRotateAround(){
  611. this.lastVal = 0.0f;
  612. this.fromInternal.x = 0.0f;
  613. this._optional.origRotation = this.rectTransform.rotation;
  614. }
  615. public LTDescr setCanvasRotateAround(){
  616. this.type = TweenAction.CANVAS_ROTATEAROUND;
  617. this.initInternal = this.initCanvasRotateAround;
  618. this.easeInternal = ()=>{
  619. newVect = easeMethod();
  620. val = newVect.x;
  621. RectTransform rect = this.rectTransform;
  622. Vector3 origPos = rect.localPosition;
  623. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), this._optional.axis, -val);
  624. Vector3 diff = origPos - rect.localPosition;
  625. 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
  626. rect.rotation = this._optional.origRotation;
  627. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), this._optional.axis, val);
  628. };
  629. return this;
  630. }
  631. public LTDescr setCanvasRotateAroundLocal(){
  632. this.type = TweenAction.CANVAS_ROTATEAROUND_LOCAL;
  633. this.initInternal = this.initCanvasRotateAround;
  634. this.easeInternal = ()=>{
  635. newVect = easeMethod();
  636. val = newVect.x;
  637. RectTransform rect = this.rectTransform;
  638. Vector3 origPos = rect.localPosition;
  639. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), rect.TransformDirection(this._optional.axis), -val);
  640. Vector3 diff = origPos - rect.localPosition;
  641. 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
  642. rect.rotation = this._optional.origRotation;
  643. rect.RotateAround((Vector3)rect.TransformPoint( this._optional.point ), rect.TransformDirection(this._optional.axis), val);
  644. };
  645. return this;
  646. }
  647. public LTDescr setCanvasPlaySprite(){
  648. this.type = TweenAction.CANVAS_PLAYSPRITE;
  649. this.initInternal = ()=>{
  650. this.uiImage = trans.GetComponent<UnityEngine.UI.Image>();
  651. this.fromInternal.x = 0f;
  652. };
  653. this.easeInternal = ()=>{
  654. newVect = easeMethod();
  655. val = newVect.x;
  656. int frame = (int)Mathf.Round( val );
  657. this.uiImage.sprite = this.sprites[ frame ];
  658. };
  659. return this;
  660. }
  661. public LTDescr setCanvasMove(){
  662. this.type = TweenAction.CANVAS_MOVE;
  663. this.initInternal = ()=>{ this.fromInternal = this.rectTransform.anchoredPosition3D; };
  664. this.easeInternal = ()=>{ this.rectTransform.anchoredPosition3D = easeMethod(); };
  665. return this;
  666. }
  667. public LTDescr setCanvasScale(){
  668. this.type = TweenAction.CANVAS_SCALE;
  669. this.initInternal = ()=>{ this.from = this.rectTransform.localScale; };
  670. this.easeInternal = ()=>{ this.rectTransform.localScale = easeMethod(); };
  671. return this;
  672. }
  673. public LTDescr setCanvasSizeDelta(){
  674. this.type = TweenAction.CANVAS_SIZEDELTA;
  675. this.initInternal = ()=>{ this.from = this.rectTransform.sizeDelta; };
  676. this.easeInternal = ()=>{ this.rectTransform.sizeDelta = easeMethod(); };
  677. return this;
  678. }
  679. #endif
  680. private void callback(){ newVect = easeMethod(); val = newVect.x; }
  681. public LTDescr setCallback(){
  682. this.type = TweenAction.CALLBACK;
  683. this.initInternal = ()=>{};
  684. this.easeInternal = this.callback;
  685. return this;
  686. }
  687. public LTDescr setValue3(){
  688. this.type = TweenAction.VALUE3;
  689. this.initInternal = ()=>{};
  690. this.easeInternal = this.callback;
  691. return this;
  692. }
  693. public LTDescr setMove(){
  694. this.type = TweenAction.MOVE;
  695. this.initInternal = ()=>{ this.from = trans.position; };
  696. this.easeInternal = ()=>{
  697. newVect = easeMethod();
  698. trans.position = newVect;
  699. };
  700. return this;
  701. }
  702. public LTDescr setMoveLocal(){
  703. this.type = TweenAction.MOVE_LOCAL;
  704. this.initInternal = ()=>{ this.from = trans.localPosition; };
  705. this.easeInternal = ()=>{
  706. newVect = easeMethod();
  707. trans.localPosition = newVect;
  708. };
  709. return this;
  710. }
  711. public LTDescr setMoveToTransform(){
  712. this.type = TweenAction.MOVE_TO_TRANSFORM;
  713. this.initInternal = ()=>{ this.from = trans.position; };
  714. this.easeInternal = ()=>{
  715. this.to = this._optional.toTrans.position;
  716. this.diff = this.to - this.from;
  717. this.diffDiv2 = this.diff * 0.5f;
  718. newVect = easeMethod();
  719. this.trans.position = newVect;
  720. };
  721. return this;
  722. }
  723. public LTDescr setRotate(){
  724. this.type = TweenAction.ROTATE;
  725. 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)); };
  726. this.easeInternal = ()=>{
  727. newVect = easeMethod();
  728. trans.eulerAngles = newVect;
  729. };
  730. return this;
  731. }
  732. public LTDescr setRotateLocal(){
  733. this.type = TweenAction.ROTATE_LOCAL;
  734. 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)); };
  735. this.easeInternal = ()=>{
  736. newVect = easeMethod();
  737. trans.localEulerAngles = newVect;
  738. };
  739. return this;
  740. }
  741. public LTDescr setScale(){
  742. this.type = TweenAction.SCALE;
  743. this.initInternal = ()=>{ this.from = trans.localScale; };
  744. this.easeInternal = ()=>{
  745. newVect = easeMethod();
  746. trans.localScale = newVect;
  747. };
  748. return this;
  749. }
  750. public LTDescr setGUIMove(){
  751. this.type = TweenAction.GUI_MOVE;
  752. this.initInternal = ()=>{ this.from = new Vector3(this._optional.ltRect.rect.x, this._optional.ltRect.rect.y, 0); };
  753. 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); };
  754. return this;
  755. }
  756. public LTDescr setGUIMoveMargin(){
  757. this.type = TweenAction.GUI_MOVE_MARGIN;
  758. this.initInternal = ()=>{ this.from = new Vector2(this._optional.ltRect.margin.x, this._optional.ltRect.margin.y); };
  759. this.easeInternal = ()=>{ Vector3 v = easeMethod(); this._optional.ltRect.margin = new Vector2(v.x, v.y); };
  760. return this;
  761. }
  762. public LTDescr setGUIScale(){
  763. this.type = TweenAction.GUI_SCALE;
  764. this.initInternal = ()=>{ this.from = new Vector3(this._optional.ltRect.rect.width, this._optional.ltRect.rect.height, 0); };
  765. 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); };
  766. return this;
  767. }
  768. public LTDescr setGUIAlpha(){
  769. this.type = TweenAction.GUI_ALPHA;
  770. this.initInternal = ()=>{ this.fromInternal.x = this._optional.ltRect.alpha; };
  771. this.easeInternal = ()=>{ this._optional.ltRect.alpha = easeMethod().x; };
  772. return this;
  773. }
  774. public LTDescr setGUIRotate(){
  775. this.type = TweenAction.GUI_ROTATE;
  776. this.initInternal = ()=>{ if(this._optional.ltRect.rotateEnabled==false){
  777. this._optional.ltRect.rotateEnabled = true;
  778. this._optional.ltRect.resetForRotation();
  779. }
  780. this.fromInternal.x = this._optional.ltRect.rotation;
  781. };
  782. this.easeInternal = ()=>{ this._optional.ltRect.rotation = easeMethod().x; };
  783. return this;
  784. }
  785. public LTDescr setDelayedSound(){
  786. this.type = TweenAction.DELAYED_SOUND;
  787. this.initInternal = ()=>{ this.hasExtraOnCompletes = true; };
  788. this.easeInternal = this.callback;
  789. return this;
  790. }
  791. private void init(){
  792. this.hasInitiliazed = true;
  793. usesNormalDt = !(useEstimatedTime || useManualTime || useFrames); // only set this to true if it uses non of the other timing modes
  794. if (useFrames)
  795. this.optional.initFrameCount = Time.frameCount;
  796. if (this.time <= 0f) // avoid dividing by zero
  797. this.time = Mathf.Epsilon;
  798. this.initInternal();
  799. this.diff = this.to - this.from;
  800. this.diffDiv2 = this.diff * 0.5f;
  801. if (this._optional.onStart != null)
  802. this._optional.onStart();
  803. if(this.onCompleteOnStart)
  804. callOnCompletes();
  805. if(this.speed>=0){
  806. initSpeed();
  807. }
  808. }
  809. private void initSpeed(){
  810. if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){
  811. this.time = this._optional.path.distance / this.speed;
  812. }else if(this.type==TweenAction.MOVE_SPLINE || this.type==TweenAction.MOVE_SPLINE_LOCAL){
  813. this.time = this._optional.spline.distance/ this.speed;
  814. }else{
  815. this.time = (this.to - this.from).magnitude / this.speed;
  816. }
  817. }
  818. public static float val;
  819. public static float dt;
  820. public static Vector3 newVect;
  821. /**
  822. * If you need a tween to happen immediately instead of waiting for the next Update call, you can force it with this method
  823. *
  824. * @method updateNow
  825. * @return {LTDescr} LTDescr an object that distinguishes the tween
  826. * @example
  827. * LeanTween.moveX(gameObject, 5f, 0f ).updateNow();
  828. */
  829. public LTDescr updateNow(){
  830. updateInternal();
  831. return this;
  832. }
  833. public bool updateInternal(){
  834. float directionLocal = this.direction;
  835. if(this.usesNormalDt){
  836. dt = LeanTween.dtActual;
  837. }else if( this.useEstimatedTime ){
  838. dt = LeanTween.dtEstimated;
  839. }else if( this.useFrames ){
  840. dt = this.optional.initFrameCount==0 ? 0 : 1;
  841. this.optional.initFrameCount = Time.frameCount;
  842. }else if( this.useManualTime ){
  843. dt = LeanTween.dtManual;
  844. }
  845. // Debug.Log ("tween:" + this+ " dt:"+dt);
  846. if(this.delay<=0f && directionLocal!=0f){
  847. if(trans==null)
  848. return true;
  849. // initialize if has not done so yet
  850. if(!this.hasInitiliazed)
  851. this.init();
  852. dt = dt*directionLocal;
  853. this.passed += dt;
  854. this.ratioPassed = Mathf.Clamp01(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. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished );
  1691. */
  1692. public LTDescr setOnComplete( Action<object> onComplete ){
  1693. this._optional.onCompleteObject = onComplete;
  1694. this.hasExtraOnCompletes = true;
  1695. return this;
  1696. }
  1697. public LTDescr setOnComplete( Action<object> onComplete, object onCompleteParam ){
  1698. this._optional.onCompleteObject = onComplete;
  1699. this.hasExtraOnCompletes = true;
  1700. if(onCompleteParam!=null)
  1701. this._optional.onCompleteParam = onCompleteParam;
  1702. return this;
  1703. }
  1704. /**
  1705. * Pass an object to along with the onComplete Function
  1706. * @method setOnCompleteParam
  1707. * @param {object} onComplete:object an object that
  1708. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1709. * @example
  1710. * LeanTween.delayedCall(1.5f, enterMiniGameStart).setOnCompleteParam( new object[]{""+5} );<br><br>
  1711. * void enterMiniGameStart( object val ){<br>
  1712. * &nbsp;object[] arr = (object [])val;<br>
  1713. * &nbsp;int lvl = int.Parse((string)arr[0]);<br>
  1714. * }<br>
  1715. */
  1716. public LTDescr setOnCompleteParam( object onCompleteParam ){
  1717. this._optional.onCompleteParam = onCompleteParam;
  1718. this.hasExtraOnCompletes = true;
  1719. return this;
  1720. }
  1721. /**
  1722. * Have a method called on each frame that the tween is being animated (passes a float value)
  1723. * @method setOnUpdate
  1724. * @param {Action<float>} onUpdate:Action<float> a method that will be called on every frame with the float value of the tweened object
  1725. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1726. * @example
  1727. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );<br>
  1728. * <br>
  1729. * void tweenMoved( float val ){ }<br>
  1730. */
  1731. public LTDescr setOnUpdate( Action<float> onUpdate ){
  1732. this._optional.onUpdateFloat = onUpdate;
  1733. this.hasUpdateCallback = true;
  1734. return this;
  1735. }
  1736. public LTDescr setOnUpdateRatio(Action<float,float> onUpdate)
  1737. {
  1738. this._optional.onUpdateFloatRatio = onUpdate;
  1739. this.hasUpdateCallback = true;
  1740. return this;
  1741. }
  1742. public LTDescr setOnUpdateObject( Action<float,object> onUpdate ){
  1743. this._optional.onUpdateFloatObject = onUpdate;
  1744. this.hasUpdateCallback = true;
  1745. return this;
  1746. }
  1747. public LTDescr setOnUpdateVector2( Action<Vector2> onUpdate ){
  1748. this._optional.onUpdateVector2 = onUpdate;
  1749. this.hasUpdateCallback = true;
  1750. return this;
  1751. }
  1752. public LTDescr setOnUpdateVector3( Action<Vector3> onUpdate ){
  1753. this._optional.onUpdateVector3 = onUpdate;
  1754. this.hasUpdateCallback = true;
  1755. return this;
  1756. }
  1757. public LTDescr setOnUpdateColor( Action<Color> onUpdate ){
  1758. this._optional.onUpdateColor = onUpdate;
  1759. this.hasUpdateCallback = true;
  1760. return this;
  1761. }
  1762. public LTDescr setOnUpdateColor( Action<Color,object> onUpdate ){
  1763. this._optional.onUpdateColorObject = onUpdate;
  1764. this.hasUpdateCallback = true;
  1765. return this;
  1766. }
  1767. #if !UNITY_FLASH
  1768. public LTDescr setOnUpdate( Action<Color> onUpdate ){
  1769. this._optional.onUpdateColor = onUpdate;
  1770. this.hasUpdateCallback = true;
  1771. return this;
  1772. }
  1773. public LTDescr setOnUpdate( Action<Color,object> onUpdate ){
  1774. this._optional.onUpdateColorObject = onUpdate;
  1775. this.hasUpdateCallback = true;
  1776. return this;
  1777. }
  1778. /**
  1779. * Have a method called on each frame that the tween is being animated (passes a float value and a object)
  1780. * @method setOnUpdate (object)
  1781. * @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
  1782. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1783. * @example
  1784. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );<br>
  1785. * <br>
  1786. * void tweenMoved( float val, object obj ){ }<br>
  1787. */
  1788. public LTDescr setOnUpdate( Action<float,object> onUpdate, object onUpdateParam = null ){
  1789. this._optional.onUpdateFloatObject = onUpdate;
  1790. this.hasUpdateCallback = true;
  1791. if(onUpdateParam!=null)
  1792. this._optional.onUpdateParam = onUpdateParam;
  1793. return this;
  1794. }
  1795. public LTDescr setOnUpdate( Action<Vector3,object> onUpdate, object onUpdateParam = null ){
  1796. this._optional.onUpdateVector3Object = onUpdate;
  1797. this.hasUpdateCallback = true;
  1798. if(onUpdateParam!=null)
  1799. this._optional.onUpdateParam = onUpdateParam;
  1800. return this;
  1801. }
  1802. public LTDescr setOnUpdate( Action<Vector2> onUpdate, object onUpdateParam = null ){
  1803. this._optional.onUpdateVector2 = onUpdate;
  1804. this.hasUpdateCallback = true;
  1805. if(onUpdateParam!=null)
  1806. this._optional.onUpdateParam = onUpdateParam;
  1807. return this;
  1808. }
  1809. /**
  1810. * Have a method called on each frame that the tween is being animated (passes a float value)
  1811. * @method setOnUpdate (Vector3)
  1812. * @param {Action<Vector3>} onUpdate:Action<Vector3> a method that will be called on every frame with the float value of the tweened object
  1813. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1814. * @example
  1815. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );<br>
  1816. * <br>
  1817. * void tweenMoved( Vector3 val ){ }<br>
  1818. */
  1819. public LTDescr setOnUpdate( Action<Vector3> onUpdate, object onUpdateParam = null ){
  1820. this._optional.onUpdateVector3 = onUpdate;
  1821. this.hasUpdateCallback = true;
  1822. if(onUpdateParam!=null)
  1823. this._optional.onUpdateParam = onUpdateParam;
  1824. return this;
  1825. }
  1826. #endif
  1827. /**
  1828. * Have an object passed along with the onUpdate method
  1829. * @method setOnUpdateParam
  1830. * @param {object} onUpdateParam:object an object that will be passed along with the onUpdate method
  1831. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1832. * @example
  1833. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );<br>
  1834. * <br>
  1835. * void tweenMoved( float val, object obj ){ }<br>
  1836. */
  1837. public LTDescr setOnUpdateParam( object onUpdateParam ){
  1838. this._optional.onUpdateParam = onUpdateParam;
  1839. return this;
  1840. }
  1841. /**
  1842. * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon
  1843. * @method setOrientToPath
  1844. * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along
  1845. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1846. * @example
  1847. * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setAxis(Vector3.forward);<br>
  1848. */
  1849. public LTDescr setOrientToPath( bool doesOrient ){
  1850. if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){
  1851. if(this._optional.path==null)
  1852. this._optional.path = new LTBezierPath();
  1853. this._optional.path.orientToPath = doesOrient;
  1854. }else{
  1855. this._optional.spline.orientToPath = doesOrient;
  1856. }
  1857. return this;
  1858. }
  1859. /**
  1860. * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon
  1861. * @method setOrientToPath2d
  1862. * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along
  1863. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1864. * @example
  1865. * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath2d(true).setAxis(Vector3.forward);<br>
  1866. */
  1867. public LTDescr setOrientToPath2d( bool doesOrient2d ){
  1868. setOrientToPath(doesOrient2d);
  1869. if(this.type==TweenAction.MOVE_CURVED || this.type==TweenAction.MOVE_CURVED_LOCAL){
  1870. this._optional.path.orientToPath2d = doesOrient2d;
  1871. }else{
  1872. this._optional.spline.orientToPath2d = doesOrient2d;
  1873. }
  1874. return this;
  1875. }
  1876. public LTDescr setRect( LTRect rect ){
  1877. this._optional.ltRect = rect;
  1878. return this;
  1879. }
  1880. public LTDescr setRect( Rect rect ){
  1881. this._optional.ltRect = new LTRect(rect);
  1882. return this;
  1883. }
  1884. public LTDescr setPath( LTBezierPath path ){
  1885. this._optional.path = path;
  1886. return this;
  1887. }
  1888. /**
  1889. * Set the point at which the GameObject will be rotated around
  1890. * @method setPoint
  1891. * @param {Vector3} point:Vector3 point at which you want the object to rotate around (local space)
  1892. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1893. * @example
  1894. * LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ) .setPoint( new Vector3(1f,0f,0f) ) .setEase( LeanTweenType.easeInOutBounce );<br>
  1895. */
  1896. public LTDescr setPoint( Vector3 point ){
  1897. this._optional.point = point;
  1898. return this;
  1899. }
  1900. public LTDescr setDestroyOnComplete( bool doesDestroy ){
  1901. this.destroyOnComplete = doesDestroy;
  1902. return this;
  1903. }
  1904. public LTDescr setAudio( object audio ){
  1905. this._optional.onCompleteParam = audio;
  1906. return this;
  1907. }
  1908. /**
  1909. * Set the onComplete method to be called at the end of every loop cycle (also applies to the delayedCall method)
  1910. * @method setOnCompleteOnRepeat
  1911. * @param {bool} isOn:bool does call onComplete on every loop cycle
  1912. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1913. * @example
  1914. * LeanTween.delayedCall(gameObject,0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true);
  1915. */
  1916. public LTDescr setOnCompleteOnRepeat( bool isOn ){
  1917. this.onCompleteOnRepeat = isOn;
  1918. return this;
  1919. }
  1920. /**
  1921. * Set the onComplete method to be called at the beginning of the tween (it will still be called when it is completed as well)
  1922. * @method setOnCompleteOnStart
  1923. * @param {bool} isOn:bool does call onComplete at the start of the tween
  1924. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1925. * @example
  1926. * LeanTween.delayedCall(gameObject, 2f, ()=>{<br> // Flash an object 5 times
  1927. * &nbsp;LeanTween.alpha(gameObject, 0f, 1f);<br>
  1928. * &nbsp;LeanTween.alpha(gameObject, 1f, 0f).setDelay(1f);<br>
  1929. * }).setOnCompleteOnStart(true).setRepeat(5);<br>
  1930. */
  1931. public LTDescr setOnCompleteOnStart( bool isOn ){
  1932. this.onCompleteOnStart = isOn;
  1933. return this;
  1934. }
  1935. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  1936. public LTDescr setRect( RectTransform rect ){
  1937. this.rectTransform = rect;
  1938. return this;
  1939. }
  1940. public LTDescr setSprites( UnityEngine.Sprite[] sprites ){
  1941. this.sprites = sprites;
  1942. return this;
  1943. }
  1944. public LTDescr setFrameRate( float frameRate ){
  1945. this.time = this.sprites.Length / frameRate;
  1946. return this;
  1947. }
  1948. #endif
  1949. /**
  1950. * Have a method called when the tween starts
  1951. * @method setOnStart
  1952. * @param {Action<>} onStart:Action<> the method that should be called when the tween is starting ex: tweenStarted( ){ }
  1953. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1954. * @example
  1955. * <i>C#:</i><br>
  1956. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( ()=>{ Debug.Log("I started!"); });
  1957. * <i>Javascript:</i><br>
  1958. * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnStart( function(){ Debug.Log("I started!"); } );
  1959. */
  1960. public LTDescr setOnStart( Action onStart ){
  1961. this._optional.onStart = onStart;
  1962. return this;
  1963. }
  1964. /**
  1965. * Set the direction of a tween -1f for backwards 1f for forwards (currently only bezier and spline paths are supported)
  1966. * @method setDirection
  1967. * @param {float} direction:float the direction that the tween should run, -1f for backwards 1f for forwards
  1968. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1969. * @example
  1970. * 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>
  1971. */
  1972. public LTDescr setDirection( float direction ){
  1973. if(this.direction!=-1f && this.direction!=1f){
  1974. Debug.LogWarning("You have passed an incorrect direction of '"+direction+"', direction must be -1f or 1f");
  1975. return this;
  1976. }
  1977. if(this.direction!=direction){
  1978. // Debug.Log("reverse path:"+this.path+" spline:"+this._optional.spline+" hasInitiliazed:"+this.hasInitiliazed);
  1979. if(this.hasInitiliazed){
  1980. this.direction = direction;
  1981. }else{
  1982. if(this._optional.path!=null){
  1983. this._optional.path = new LTBezierPath( LTUtility.reverse( this._optional.path.pts ) );
  1984. }else if(this._optional.spline!=null){
  1985. this._optional.spline = new LTSpline( LTUtility.reverse( this._optional.spline.pts ) );
  1986. }
  1987. // this.passed = this.time - this.passed;
  1988. }
  1989. }
  1990. return this;
  1991. }
  1992. /**
  1993. * Set whether or not the tween will recursively effect an objects children in the hierarchy
  1994. * @method setRecursive
  1995. * @param {bool} useRecursion:bool whether the tween will recursively effect an objects children in the hierarchy
  1996. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1997. * @example
  1998. * LeanTween.alpha(gameObject, 0f, 1f).setRecursive(true);<br>
  1999. */
  2000. public LTDescr setRecursive( bool useRecursion ){
  2001. this.useRecursion = useRecursion;
  2002. return this;
  2003. }
  2004. }
  2005. //}