LTDescr.cs 80 KB

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