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

3709 lines
152 KiB

4 years ago
  1. //namespace DentedPixel{
  2. // LeanTween version 2.46 - http://dentedpixel.com/developer-diary/
  3. //
  4. // The MIT License (MIT)
  5. //
  6. // Copyright (c) 2017 Russell Savage - Dented Pixel
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in all
  16. // copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. // SOFTWARE.
  25. /*
  26. TERMS OF USE - EASING EQUATIONS#
  27. Open source under the BSD License.
  28. Copyright (c)2001 Robert Penner
  29. All rights reserved.
  30. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  31. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  32. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  33. Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  34. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. /**
  37. * Pass this to the "ease" parameter, to get a different easing behavior<br /><br />
  38. * <strong>Example: </strong><br />LeanTween.rotateX(gameObject, 270.0f, 1.5f).setEase(LeanTweenType.easeInBack);
  39. *
  40. * @class LeanTweenType
  41. */
  42. /**
  43. * @property {integer} linear
  44. */
  45. /**
  46. * @property {integer} easeOutQuad
  47. */
  48. /**
  49. * @property {integer} easeInQuad
  50. */
  51. /**
  52. * @property {integer} easeInOutQuad
  53. */
  54. /**
  55. * @property {integer} easeInCubic
  56. */
  57. /**
  58. * @property {integer} easeOutCubic
  59. */
  60. /**
  61. * @property {integer} easeInOutCubic
  62. */
  63. /**
  64. * @property {integer} easeInQuart
  65. */
  66. /**
  67. * @property {integer} easeOutQuart
  68. */
  69. /**
  70. * @property {integer} easeInOutQuart
  71. */
  72. /**
  73. * @property {integer} easeInQuint
  74. */
  75. /**
  76. * @property {integer} easeOutQuint
  77. */
  78. /**
  79. * @property {integer} easeInOutQuint
  80. */
  81. /**
  82. * @property {integer} easeInSine
  83. */
  84. /**
  85. * @property {integer} easeOutSine
  86. */
  87. /**
  88. * @property {integer} easeInOutSine
  89. */
  90. /**
  91. * @property {integer} easeInExpo
  92. */
  93. /**
  94. * @property {integer} easeOutExpo
  95. */
  96. /**
  97. * @property {integer} easeInOutExpo
  98. */
  99. /**
  100. * @property {integer} easeInCirc
  101. */
  102. /**
  103. * @property {integer} easeOutCirc
  104. */
  105. /**
  106. * @property {integer} easeInOutCirc
  107. */
  108. /**
  109. * @property {integer} easeInBounce
  110. */
  111. /**
  112. * @property {integer} easeOutBounce
  113. */
  114. /**
  115. * @property {integer} easeInOutBounce
  116. */
  117. /**
  118. * @property {integer} easeInBack
  119. */
  120. /**
  121. * @property {integer} easeOutBack
  122. */
  123. /**
  124. * @property {integer} easeInOutBack
  125. */
  126. /**
  127. * @property {integer} easeInElastic
  128. */
  129. /**
  130. * @property {integer} easeOutElastic
  131. */
  132. /**
  133. * @property {integer} easeInOutElastic
  134. */
  135. /**
  136. * @property {integer} punch
  137. */
  138. using UnityEngine;
  139. using System;
  140. using System.Collections.Generic;
  141. public enum TweenAction{
  142. MOVE_X,
  143. MOVE_Y,
  144. MOVE_Z,
  145. MOVE_LOCAL_X,
  146. MOVE_LOCAL_Y,
  147. MOVE_LOCAL_Z,
  148. MOVE_CURVED,
  149. MOVE_CURVED_LOCAL,
  150. MOVE_SPLINE,
  151. MOVE_SPLINE_LOCAL,
  152. SCALE_X,
  153. SCALE_Y,
  154. SCALE_Z,
  155. ROTATE_X,
  156. ROTATE_Y,
  157. ROTATE_Z,
  158. ROTATE_AROUND,
  159. ROTATE_AROUND_LOCAL,
  160. CANVAS_ROTATEAROUND,
  161. CANVAS_ROTATEAROUND_LOCAL,
  162. CANVAS_PLAYSPRITE,
  163. ALPHA,
  164. TEXT_ALPHA,
  165. CANVAS_ALPHA,
  166. CANVASGROUP_ALPHA,
  167. ALPHA_VERTEX,
  168. COLOR,
  169. CALLBACK_COLOR,
  170. TEXT_COLOR,
  171. CANVAS_COLOR,
  172. CANVAS_MOVE_X,
  173. CANVAS_MOVE_Y,
  174. CANVAS_MOVE_Z,
  175. CALLBACK,
  176. MOVE,
  177. MOVE_LOCAL,
  178. MOVE_TO_TRANSFORM,
  179. ROTATE,
  180. ROTATE_LOCAL,
  181. SCALE,
  182. VALUE3,
  183. GUI_MOVE,
  184. GUI_MOVE_MARGIN,
  185. GUI_SCALE,
  186. GUI_ALPHA,
  187. GUI_ROTATE,
  188. DELAYED_SOUND,
  189. CANVAS_MOVE,
  190. CANVAS_SCALE,
  191. CANVAS_SIZEDELTA,
  192. }
  193. public enum LeanTweenType{
  194. notUsed, linear, easeOutQuad, easeInQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart,
  195. easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc,
  196. easeInBounce, easeOutBounce, easeInOutBounce, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeSpring, easeShake, punch, once, clamp, pingPong, animationCurve
  197. }
  198. /**
  199. * LeanTween is an efficient tweening engine for Unity3d<br /><br />
  200. * <a href="#index">Index of All Methods</a> | <a href="LTDescr.html">Optional Paramaters that can be passed</a><br /><br />
  201. * <strong id='optional'>Optional Parameters</strong> are passed at the end of every method<br />
  202. * <br />
  203. * <i>Example:</i><br />
  204. * LeanTween.moveX( gameObject, 1f, 1f).setEase( <a href="LeanTweenType.html">LeanTweenType</a>.easeInQuad ).setDelay(1f);<br />
  205. * <br />
  206. * You can pass the optional parameters in any order, and chain on as many as you wish!<br /><br />
  207. * You can also modify this tween later, just save the unique id of the tween.<br />
  208. * <h4>Example:</h4>
  209. * int id = LeanTween.moveX(gameObject, 1f, 1f).id;<br />
  210. * <a href="LTDescr.html">LTDescr</a> d = LeanTween.<a href="#method_LeanTween.descr">descr</a>( id );<br /><br />
  211. * if(d!=null){ <span style="color:gray">// if the tween has already finished it will return null</span><br />
  212. * <span style="color:gray">&#160;&#160; // change some parameters</span><br />
  213. * &#160;&#160; d.setOnComplete( onCompleteFunc ).setEase( <a href="LeanTweenType.html">LeanTweenType</a>.easeInOutBack );<br />
  214. * }
  215. *
  216. * @class LeanTween
  217. */
  218. public class LeanTween : MonoBehaviour {
  219. public static bool throwErrors = true;
  220. public static float tau = Mathf.PI*2.0f;
  221. public static float PI_DIV2 = Mathf.PI / 2.0f;
  222. private static LTSeq[] sequences;
  223. private static LTDescr[] tweens;
  224. private static int[] tweensFinished;
  225. private static int[] tweensFinishedIds;
  226. private static LTDescr tween;
  227. private static int tweenMaxSearch = -1;
  228. private static int maxTweens = 400;
  229. private static int maxSequences = 400;
  230. private static int frameRendered= -1;
  231. private static GameObject _tweenEmpty;
  232. public static float dtEstimated = -1f;
  233. public static float dtManual;
  234. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
  235. private static float previousRealTime;
  236. #endif
  237. public static float dtActual;
  238. private static uint global_counter = 0;
  239. private static int i;
  240. private static int j;
  241. private static int finishedCnt;
  242. public static AnimationCurve punch = new AnimationCurve( new Keyframe(0.0f, 0.0f ), new Keyframe(0.112586f, 0.9976035f ), new Keyframe(0.3120486f, -0.1720615f ), new Keyframe(0.4316337f, 0.07030682f ), new Keyframe(0.5524869f, -0.03141804f ), new Keyframe(0.6549395f, 0.003909959f ), new Keyframe(0.770987f, -0.009817753f ), new Keyframe(0.8838775f, 0.001939224f ), new Keyframe(1.0f, 0.0f ) );
  243. public static AnimationCurve shake = new AnimationCurve( new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(0.75f, -1f), new Keyframe(1f, 0f) ) ;
  244. public static void init(){
  245. init(maxTweens);
  246. }
  247. public static int maxSearch{
  248. get{
  249. return tweenMaxSearch;
  250. }
  251. }
  252. public static int maxSimulataneousTweens{
  253. get {
  254. return maxTweens;
  255. }
  256. }
  257. /**
  258. * Find out how many tweens you have animating at a given time <summary>Find out how many tweens you have animating at a given time</summary>
  259. *
  260. * @method LeanTween.tweensRunning
  261. * @example
  262. * Debug.Log("I have "+LeanTween.tweensRunning+" animating!");
  263. */
  264. public static int tweensRunning{
  265. get{
  266. int count = 0;
  267. for (int i = 0; i <= tweenMaxSearch; i++){
  268. if (tweens[i].toggle){
  269. count++;
  270. }
  271. }
  272. return count;
  273. }
  274. }
  275. /**
  276. * This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400). This must be called before any use of LeanTween is made for it to be effective. <summary>This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400). This must be called before any use of LeanTween is made for it to be effective. </summary>
  277. *
  278. * @method LeanTween.init
  279. * @param {integer} maxSimultaneousTweens:int The maximum number of tweens you will use, make sure you don't go over this limit, otherwise the code will throw an error
  280. * @example
  281. * LeanTween.init( 800 );
  282. */
  283. public static void init(int maxSimultaneousTweens ){
  284. init(maxSimultaneousTweens, maxSequences);
  285. }
  286. public static void init(int maxSimultaneousTweens, int maxSimultaneousSequences){
  287. if(tweens==null){
  288. maxTweens = maxSimultaneousTweens;
  289. tweens = new LTDescr[maxTweens];
  290. tweensFinished = new int[maxTweens];
  291. tweensFinishedIds = new int[maxTweens];
  292. _tweenEmpty = new GameObject();
  293. _tweenEmpty.name = "~LeanTween";
  294. _tweenEmpty.AddComponent(typeof(LeanTween));
  295. _tweenEmpty.isStatic = true;
  296. #if !UNITY_EDITOR
  297. _tweenEmpty.hideFlags = HideFlags.HideAndDontSave;
  298. #endif
  299. #if UNITY_EDITOR
  300. if(Application.isPlaying)
  301. DontDestroyOnLoad( _tweenEmpty );
  302. #else
  303. DontDestroyOnLoad( _tweenEmpty );
  304. #endif
  305. for(int i = 0; i < maxTweens; i++){
  306. tweens[i] = new LTDescr();
  307. }
  308. #if UNITY_5_4_OR_NEWER
  309. UnityEngine.SceneManagement.SceneManager.sceneLoaded += onLevelWasLoaded54;
  310. #endif
  311. sequences = new LTSeq[ maxSimultaneousSequences ];
  312. for(int i = 0; i < maxSimultaneousSequences; i++){
  313. sequences[i] = new LTSeq();
  314. }
  315. }
  316. }
  317. public static void reset(){
  318. if(tweens!=null){
  319. for (int i = 0; i <= tweenMaxSearch; i++){
  320. if(tweens[i]!=null)
  321. tweens[i].toggle = false;
  322. }
  323. }
  324. tweens = null;
  325. Destroy(_tweenEmpty);
  326. }
  327. public void Update(){
  328. LeanTween.update();
  329. }
  330. #if UNITY_5_4_OR_NEWER
  331. private static void onLevelWasLoaded54( UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode ){ internalOnLevelWasLoaded( scene.buildIndex ); }
  332. #else
  333. public void OnLevelWasLoaded( int lvl ){ internalOnLevelWasLoaded( lvl ); }
  334. #endif
  335. private static void internalOnLevelWasLoaded( int lvl ){
  336. // Debug.Log("reseting gui");
  337. LTGUI.reset();
  338. }
  339. private static int maxTweenReached;
  340. public static void update() {
  341. if(frameRendered != Time.frameCount){ // make sure update is only called once per frame
  342. init();
  343. #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
  344. dtEstimated = Time.realtimeSinceStartup - previousRealTime;
  345. if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large
  346. dtEstimated = 0.2f;
  347. previousRealTime = Time.realtimeSinceStartup;
  348. #else
  349. dtEstimated = dtEstimated<0f ? 0f : dtEstimated = Time.unscaledDeltaTime;
  350. // Debug.Log("Time.unscaledDeltaTime:"+Time.unscaledDeltaTime);
  351. #endif
  352. dtActual = Time.deltaTime;
  353. maxTweenReached = 0;
  354. finishedCnt = 0;
  355. // if(tweenMaxSearch>1500)
  356. // Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
  357. for( int i = 0; i <= tweenMaxSearch && i < maxTweens; i++){
  358. tween = tweens[i];
  359. // if(i==0 && tweens[i].toggle)
  360. // Debug.Log("tweens["+i+"]"+tweens[i]);
  361. if(tween.toggle){
  362. maxTweenReached = i;
  363. if (tween.updateInternal()) { // returns true if the tween is finished with it's loop
  364. tweensFinished[finishedCnt] = i;
  365. tweensFinishedIds[finishedCnt] = tweens[i].id;
  366. finishedCnt++;
  367. }
  368. }
  369. }
  370. // Debug.Log("maxTweenReached:"+maxTweenReached);
  371. tweenMaxSearch = maxTweenReached;
  372. frameRendered = Time.frameCount;
  373. for(int i = 0; i < finishedCnt; i++){
  374. j = tweensFinished[i];
  375. tween = tweens[ j ];
  376. if (tween.id == tweensFinishedIds[i]){
  377. // Debug.Log("removing tween:"+tween);
  378. removeTween(j);
  379. if(tween.hasExtraOnCompletes && tween.trans!=null)
  380. tween.callOnCompletes();
  381. }
  382. }
  383. }
  384. }
  385. public static void removeTween( int i, int uniqueId){ // Only removes the tween if the unique id matches <summary>Move a GameObject to a certain location</summary>
  386. if(tweens[i].uniqueId==uniqueId){
  387. removeTween( i );
  388. }
  389. }
  390. // This method is only used internally! Do not call this from your scripts. To cancel a tween use LeanTween.cancel
  391. public static void removeTween( int i ){
  392. if(tweens[i].toggle){
  393. tweens[i].toggle = false;
  394. tweens[i].counter = uint.MaxValue;
  395. //logError("Removing tween["+i+"]:"+tweens[i]);
  396. if(tweens[i].destroyOnComplete){
  397. // Debug.Log("destroying tween.type:"+tween.type+" ltRect"+(tweens[i]._optional.ltRect==null));
  398. if(tweens[i]._optional.ltRect!=null){
  399. // Debug.Log("destroy i:"+i+" id:"+tweens[i].ltRect.id);
  400. LTGUI.destroy( tweens[i]._optional.ltRect.id );
  401. }else{ // check if equal to tweenEmpty
  402. if(tweens[i].trans!=null && tweens[i].trans.gameObject!=_tweenEmpty){
  403. Destroy(tweens[i].trans.gameObject);
  404. }
  405. }
  406. }
  407. //tweens[i].optional = null;
  408. startSearch = i;
  409. //Debug.Log("start search reset:"+startSearch + " i:"+i+" tweenMaxSearch:"+tweenMaxSearch);
  410. if(i+1>=tweenMaxSearch){
  411. //Debug.Log("reset to zero");
  412. startSearch = 0;
  413. //tweenMaxSearch--;
  414. }
  415. }
  416. }
  417. public static Vector3[] add(Vector3[] a, Vector3 b){
  418. Vector3[] c = new Vector3[ a.Length ];
  419. for(i=0; i<a.Length; i++){
  420. c[i] = a[i] + b;
  421. }
  422. return c;
  423. }
  424. public static float closestRot( float from, float to ){
  425. float minusWhole = 0 - (360 - to);
  426. float plusWhole = 360 + to;
  427. float toDiffAbs = Mathf.Abs( to-from );
  428. float minusDiff = Mathf.Abs(minusWhole-from);
  429. float plusDiff = Mathf.Abs(plusWhole-from);
  430. if( toDiffAbs < minusDiff && toDiffAbs < plusDiff ){
  431. return to;
  432. }else {
  433. if(minusDiff < plusDiff){
  434. return minusWhole;
  435. }else{
  436. return plusWhole;
  437. }
  438. }
  439. }
  440. /**
  441. * Cancels all tweens <summary>Cancels all tweens</summary>
  442. *
  443. * @method LeanTween.cancelAll
  444. * @param {bool} callComplete:bool (optional) if true, then the all onCompletes will run before canceling
  445. * @example LeanTween.cancelAll(true); <br />
  446. */
  447. public static void cancelAll(){
  448. cancelAll(false);
  449. }
  450. public static void cancelAll(bool callComplete){
  451. init();
  452. for (int i = 0; i <= tweenMaxSearch; i++)
  453. {
  454. if (tweens[i].trans != null){
  455. if (callComplete && tweens[i].optional.onComplete != null)
  456. tweens[i].optional.onComplete();
  457. removeTween(i);
  458. }
  459. }
  460. }
  461. /**
  462. * Cancel all tweens that are currently targeting the gameObject<summary>Cancel all tweens that are currently targeting the gameObject</summary>
  463. *
  464. * @method LeanTween.cancel
  465. * @param {GameObject} gameObject:GameObject gameObject whose tweens you wish to cancel
  466. * @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling
  467. * @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f); <br />
  468. * LeanTween.cancel( gameObject );
  469. */
  470. public static void cancel( GameObject gameObject ){
  471. cancel( gameObject, false);
  472. }
  473. public static void cancel( GameObject gameObject, bool callOnComplete ){
  474. init();
  475. Transform trans = gameObject.transform;
  476. for(int i = 0; i <= tweenMaxSearch; i++){
  477. if(tweens[i].toggle && tweens[i].trans==trans){
  478. if (callOnComplete && tweens[i].optional.onComplete != null)
  479. tweens[i].optional.onComplete();
  480. removeTween(i);
  481. }
  482. }
  483. }
  484. public static void cancel( RectTransform rect ){
  485. cancel( rect.gameObject, false);
  486. }
  487. // public static void cancel( GameObject gameObject, int uniqueId ){
  488. // if(uniqueId>=0){
  489. // init();
  490. // int backId = uniqueId & 0xFFFF;
  491. // int backCounter = uniqueId >> 16;
  492. // // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tweens[backId].counter + " tweens[id].type:"+tweens[backId].type);
  493. // if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter))
  494. // removeTween((int)backId);
  495. // }
  496. // }
  497. public static void cancel( GameObject gameObject, int uniqueId, bool callOnComplete = false ){
  498. if(uniqueId>=0){
  499. init();
  500. int backId = uniqueId & 0xFFFF;
  501. int backCounter = uniqueId >> 16;
  502. // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tw eens[backId].counter + " tweens[id].type:"+tweens[backId].type);
  503. if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter)) {
  504. if (callOnComplete && tweens[backId].optional.onComplete != null)
  505. tweens[backId].optional.onComplete();
  506. removeTween((int)backId);
  507. }
  508. }
  509. }
  510. public static void cancel( LTRect ltRect, int uniqueId ){
  511. if(uniqueId>=0){
  512. init();
  513. int backId = uniqueId & 0xFFFF;
  514. int backCounter = uniqueId >> 16;
  515. // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
  516. if(tweens[backId]._optional.ltRect == ltRect && tweens[backId].counter==backCounter)
  517. removeTween((int)backId);
  518. }
  519. }
  520. /**
  521. * Cancel a specific tween with the provided id <summary>Cancel a specific tween with the provided id</summary>
  522. *
  523. * @method LeanTween.cancel
  524. * @param {int} id:int unique id that represents that tween
  525. * @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling
  526. * @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).id; <br />
  527. * LeanTween.cancel( id );
  528. */
  529. public static void cancel( int uniqueId ){
  530. cancel( uniqueId, false);
  531. }
  532. public static void cancel( int uniqueId, bool callOnComplete ){
  533. if(uniqueId>=0){
  534. init();
  535. int backId = uniqueId & 0xFFFF;
  536. int backCounter = uniqueId >> 16;
  537. if (backId > tweens.Length - 1) { // sequence
  538. int sequenceId = backId - tweens.Length;
  539. LTSeq seq = sequences[sequenceId];
  540. for (int i = 0; i < maxSequences; i++) {
  541. if (seq.current.tween != null) {
  542. int tweenId = seq.current.tween.uniqueId;
  543. int tweenIndex = tweenId & 0xFFFF;
  544. removeTween(tweenIndex);
  545. }
  546. if (seq.previous == null)
  547. break;
  548. seq.current = seq.previous;
  549. }
  550. } else { // tween
  551. // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
  552. if (tweens[backId].counter == backCounter) {
  553. if (callOnComplete && tweens[backId].optional.onComplete != null)
  554. tweens[backId].optional.onComplete();
  555. removeTween((int)backId);
  556. }
  557. }
  558. }
  559. }
  560. /**
  561. * Retrieve a tweens LTDescr object to modify <summary>Retrieve a tweens LTDescr object to modify</summary>
  562. *
  563. * @method LeanTween.descr
  564. * @param {int} id:int unique id that represents that tween
  565. * @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod ).id; <br /><br />
  566. * <div style="color:gray">// later I want decide I want to change onComplete method </div>
  567. * LTDescr descr = LeanTween.descr( id );<br />
  568. * if(descr!=null) <span style="color:gray">// if the tween has already finished it will come back null</span><br />
  569. * &#160;&#160;descr.setOnComplete( newMethod );<br />
  570. */
  571. public static LTDescr descr( int uniqueId ){
  572. init();
  573. int backId = uniqueId & 0xFFFF;
  574. int backCounter = uniqueId >> 16;
  575. // Debug.Log("backId:" + backId+" backCounter:"+backCounter);
  576. if (tweens[backId] != null && tweens[backId].uniqueId == uniqueId && tweens[backId].counter == backCounter) {
  577. // Debug.Log("tween count:" + tweens[backId].counter);
  578. return tweens[backId];
  579. }
  580. for(int i = 0; i <= tweenMaxSearch; i++){
  581. if (tweens[i].uniqueId == uniqueId && tweens[i].counter == backCounter) {
  582. return tweens[i];
  583. }
  584. }
  585. return null;
  586. }
  587. public static LTDescr description( int uniqueId ){
  588. return descr( uniqueId );
  589. }
  590. /**
  591. * Retrieve a tweens LTDescr object(s) to modify <summary>Retrieve a tweens LTDescr object(s) to modifyn</summary>
  592. *
  593. * @method LeanTween.descriptions
  594. * @param {GameObject} id:GameObject object whose tween descriptions you want to retrieve
  595. * @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod ); <br /><br />
  596. * <div style="color:gray">// later I want decide I want to change onComplete method </div>
  597. * LTDescr[] descr = LeanTween.descriptions( gameObject );<br />
  598. * if(descr.Length>0) <span style="color:gray">// make sure there is a valid description for this target</span><br />
  599. * &#160;&#160;descr[0].setOnComplete( newMethod );<span style="color:gray">// in this case we only ever expect there to be one tween on this object</span><br />
  600. */
  601. public static LTDescr[] descriptions(GameObject gameObject = null) {
  602. if (gameObject == null) return null;
  603. List<LTDescr> descrs = new List<LTDescr>();
  604. Transform trans = gameObject.transform;
  605. for (int i = 0; i <= tweenMaxSearch; i++) {
  606. if (tweens[i].toggle && tweens[i].trans == trans)
  607. descrs.Add( tweens[i] );
  608. }
  609. return descrs.ToArray();
  610. }
  611. [System.Obsolete("Use 'pause( id )' instead")]
  612. public static void pause( GameObject gameObject, int uniqueId ){
  613. pause( uniqueId );
  614. }
  615. /**
  616. * Pause all tweens for a GameObject <summary>Pause all tweens for a GameObject</summary>
  617. *
  618. * @method LeanTween.pause
  619. * @param {int} id:int Id of the tween you want to pause
  620. * @example
  621. * int id = LeanTween.moveX(gameObject, 5, 1.0).id<br />
  622. * LeanTween.pause( id );<br />
  623. * // Later....<br />
  624. * LeanTween.resume( id );
  625. */
  626. public static void pause( int uniqueId ){
  627. int backId = uniqueId & 0xFFFF;
  628. int backCounter = uniqueId >> 16;
  629. if(tweens[backId].counter==backCounter){
  630. tweens[backId].pause();
  631. }
  632. }
  633. /**
  634. * Pause all tweens for a GameObject <summary>Pause all tweens for a GameObject</summary>
  635. *
  636. * @method LeanTween.pause
  637. * @param {GameObject} gameObject:GameObject GameObject whose tweens you want to pause
  638. */
  639. public static void pause( GameObject gameObject ){
  640. Transform trans = gameObject.transform;
  641. for(int i = 0; i <= tweenMaxSearch; i++){
  642. if(tweens[i].trans==trans){
  643. tweens[i].pause();
  644. }
  645. }
  646. }
  647. /**
  648. * Pause all active tweens <summary>Pause all active tweens</summary>
  649. *
  650. * @method LeanTween.pauseAll
  651. */
  652. public static void pauseAll(){
  653. init();
  654. for (int i = 0; i <= tweenMaxSearch; i++){
  655. tweens[i].pause();
  656. }
  657. }
  658. /**
  659. * Resume all active tweens <summary>Resume all active tweens</summary>
  660. *
  661. * @method LeanTween.resumeAll
  662. */
  663. public static void resumeAll(){
  664. init();
  665. for (int i = 0; i <= tweenMaxSearch; i++){
  666. tweens[i].resume();
  667. }
  668. }
  669. [System.Obsolete("Use 'resume( id )' instead")]
  670. public static void resume( GameObject gameObject, int uniqueId ){
  671. resume( uniqueId );
  672. }
  673. /**
  674. * Resume a specific tween <summary>Resume a specific tween</summary>
  675. *
  676. * @method LeanTween.resume
  677. * @param {int} id:int Id of the tween you want to resume
  678. * @example
  679. * int id = LeanTween.moveX(gameObject, 5, 1.0).id<br />
  680. * LeanTween.pause( id );<br />
  681. * // Later....<br />
  682. * LeanTween.resume( id );
  683. */
  684. public static void resume( int uniqueId ){
  685. int backId = uniqueId & 0xFFFF;
  686. int backCounter = uniqueId >> 16;
  687. if(tweens[backId].counter==backCounter){
  688. tweens[backId].resume();
  689. }
  690. }
  691. /**
  692. * Resume all the tweens on a GameObject <summary>Resume all the tweens on a GameObject</summary>
  693. *
  694. * @method LeanTween.resume
  695. * @param {GameObject} gameObject:GameObject GameObject whose tweens you want to resume
  696. */
  697. public static void resume( GameObject gameObject ){
  698. Transform trans = gameObject.transform;
  699. for(int i = 0; i <= tweenMaxSearch; i++){
  700. if(tweens[i].trans==trans)
  701. tweens[i].resume();
  702. }
  703. }
  704. /**
  705. * Test whether or not a tween is active on a GameObject <summary>Test whether or not a tween is active on a GameObject</summary>
  706. *
  707. * @method LeanTween.isTweening
  708. * @param {GameObject} gameObject:GameObject GameObject that you want to test if it is tweening
  709. */
  710. public static bool isTweening( GameObject gameObject = null ){
  711. if(gameObject==null){
  712. for(int i = 0; i <= tweenMaxSearch; i++){
  713. if(tweens[i].toggle)
  714. return true;
  715. }
  716. return false;
  717. }
  718. Transform trans = gameObject.transform;
  719. for(int i = 0; i <= tweenMaxSearch; i++){
  720. if(tweens[i].toggle && tweens[i].trans==trans)
  721. return true;
  722. }
  723. return false;
  724. }
  725. public static bool isTweening( RectTransform rect ){
  726. return isTweening(rect.gameObject);
  727. }
  728. /**
  729. * Test whether or not a tween is active or not <summary>Test whether or not a tween is active or not</summary>
  730. *
  731. * @method LeanTween.isTweening
  732. * @param {GameObject} id:int id of the tween that you want to test if it is tweening
  733. * @example
  734. * int id = LeanTween.moveX(gameObject, 1f, 3f).id;<br />
  735. * if(LeanTween.isTweening( id ))<br />
  736. * &#160;&#160; &#160;&#160;Debug.Log("I am tweening!");<br />
  737. */
  738. public static bool isTweening( int uniqueId ){
  739. int backId = uniqueId & 0xFFFF;
  740. int backCounter = uniqueId >> 16;
  741. if (backId < 0 || backId >= maxTweens) return false;
  742. // Debug.Log("tweens[backId].counter:"+tweens[backId].counter+" backCounter:"+backCounter +" toggle:"+tweens[backId].toggle);
  743. if(tweens[backId].counter==backCounter && tweens[backId].toggle){
  744. return true;
  745. }
  746. return false;
  747. }
  748. public static bool isTweening( LTRect ltRect ){
  749. for( int i = 0; i <= tweenMaxSearch; i++){
  750. if(tweens[i].toggle && tweens[i]._optional.ltRect==ltRect)
  751. return true;
  752. }
  753. return false;
  754. }
  755. public static void drawBezierPath(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float arrowSize = 0.0f, Transform arrowTransform = null){
  756. Vector3 last = a;
  757. Vector3 p;
  758. Vector3 aa = (-a + 3*(b-c) + d);
  759. Vector3 bb = 3*(a+c) - 6*b;
  760. Vector3 cc = 3*(b-a);
  761. float t;
  762. if(arrowSize>0.0f){
  763. Vector3 beforePos = arrowTransform.position;
  764. Quaternion beforeQ = arrowTransform.rotation;
  765. float distanceTravelled = 0f;
  766. for(float k = 1.0f; k <= 120.0f; k++){
  767. t = k / 120.0f;
  768. p = ((aa* t + (bb))* t + cc)* t + a;
  769. Gizmos.DrawLine(last, p);
  770. distanceTravelled += (p-last).magnitude;
  771. if(distanceTravelled>1f){
  772. distanceTravelled = distanceTravelled - 1f;
  773. /*float deltaY = p.y - last.y;
  774. float deltaX = p.x - last.x;
  775. float ang = Mathf.Atan(deltaY / deltaX);
  776. Vector3 arrow = p + new Vector3( Mathf.Cos(ang+2.5f), Mathf.Sin(ang+2.5f), 0f)*0.5f;
  777. Gizmos.DrawLine(p, arrow);
  778. arrow = p + new Vector3( Mathf.Cos(ang+-2.5f), Mathf.Sin(ang+-2.5f), 0f)*0.5f;
  779. Gizmos.DrawLine(p, arrow);*/
  780. arrowTransform.position = p;
  781. arrowTransform.LookAt( last, Vector3.forward );
  782. Vector3 to = arrowTransform.TransformDirection(Vector3.right);
  783. // Debug.Log("to:"+to+" tweenEmpty.transform.position:"+arrowTransform.position);
  784. Vector3 back = (last-p);
  785. back = back.normalized;
  786. Gizmos.DrawLine(p, p + (to + back)*arrowSize);
  787. to = arrowTransform.TransformDirection(-Vector3.right);
  788. Gizmos.DrawLine(p, p + (to + back)*arrowSize);
  789. }
  790. last = p;
  791. }
  792. arrowTransform.position = beforePos;
  793. arrowTransform.rotation = beforeQ;
  794. }else{
  795. for(float k = 1.0f; k <= 30.0f; k++){
  796. t = k / 30.0f;
  797. p = ((aa* t + (bb))* t + cc)* t + a;
  798. Gizmos.DrawLine(last, p);
  799. last = p;
  800. }
  801. }
  802. }
  803. public static object logError( string error ){
  804. if(throwErrors) Debug.LogError(error); else Debug.Log(error);
  805. return null;
  806. }
  807. public static LTDescr options(LTDescr seed){ Debug.LogError("error this function is no longer used"); return null; }
  808. public static LTDescr options(){
  809. init();
  810. bool found = false;
  811. // Debug.Log("Search start");
  812. for(j=0, i = startSearch; j <= maxTweens; i++){
  813. if(j >= maxTweens)
  814. return logError("LeanTween - You have run out of available spaces for tweening. To avoid this error increase the number of spaces to available for tweening when you initialize the LeanTween class ex: LeanTween.init( "+(maxTweens*2)+" );") as LTDescr;
  815. if(i>=maxTweens)
  816. i = 0;
  817. // Debug.Log("searching i:"+i);
  818. if(tweens[i].toggle==false){
  819. if(i+1>tweenMaxSearch)
  820. tweenMaxSearch = i+1;
  821. startSearch = i + 1;
  822. found = true;
  823. break;
  824. }
  825. j++;
  826. }
  827. if(found==false)
  828. logError("no available tween found!");
  829. // Debug.Log("new tween with i:"+i+" counter:"+tweens[i].counter+" tweenMaxSearch:"+tweenMaxSearch+" tween:"+tweens[i]);
  830. tweens[i].reset();
  831. global_counter++;
  832. if(global_counter>0x8000)
  833. global_counter = 0;
  834. tweens[i].setId( (uint)i, global_counter );
  835. return tweens[i];
  836. }
  837. public static GameObject tweenEmpty{
  838. get{
  839. init(maxTweens);
  840. return _tweenEmpty;
  841. }
  842. }
  843. public static int startSearch = 0;
  844. public static LTDescr d;
  845. private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float time, LTDescr tween ){
  846. init(maxTweens);
  847. if(gameObject==null || tween==null)
  848. return null;
  849. tween.trans = gameObject.transform;
  850. tween.to = to;
  851. tween.time = time;
  852. if (tween.time <= 0f)
  853. tween.updateInternal();
  854. //tween.hasPhysics = gameObject.rigidbody!=null;
  855. return tween;
  856. }
  857. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  858. /**
  859. * Play a sequence of images on a Unity UI Object <summary>Play a sequence of images on a Unity UI Object</summary>
  860. *
  861. * @method LeanTween.play
  862. * @param {RectTransform} rectTransform:RectTransform RectTransform that you want to play the sequence of sprites on
  863. * @param {Sprite[]} sprites:Sprite[] Sequence of sprites to be played
  864. * @return {LTDescr} LTDescr an object that distinguishes the tween <br />
  865. * @example
  866. * LeanTween.play(gameObject.GetComponent&lt;RectTransform&gt;(), sprites).setLoopPingPong();
  867. */
  868. public static LTDescr play(RectTransform rectTransform, UnityEngine.Sprite[] sprites){
  869. float defaultFrameRate = 0.25f;
  870. float time = defaultFrameRate * sprites.Length;
  871. return pushNewTween(rectTransform.gameObject, new Vector3((float)sprites.Length - 1.0f,0,0), time, options().setCanvasPlaySprite().setSprites( sprites ).setRepeat(-1));
  872. }
  873. #endif
  874. /**
  875. * Fade a gameobject's material to a certain alpha value. The material's shader needs to support alpha. <a href="http://owlchemylabs.com/content/">Owl labs has some excellent efficient shaders</a>. <summary>Fade a gameobject's material to a certain alpha value.</summary>
  876. *
  877. * @method LeanTween.alpha
  878. * @param {GameObject} gameObject:GameObject Gameobject that you wish to fade
  879. * @param {float} to:float the final alpha value (0-1)
  880. * @param {float} time:float The time with which to fade the object
  881. * @return {LTDescr} LTDescr an object that distinguishes the tween
  882. * @example
  883. * LeanTween.alpha(gameObject, 1f, 1f) .setDelay(1f);
  884. */
  885. public static LTDescr alpha(GameObject gameObject, float to, float time){
  886. LTDescr lt = pushNewTween( gameObject, new Vector3(to,0,0), time, options().setAlpha() );
  887. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  888. SpriteRenderer ren = gameObject.GetComponent<SpriteRenderer>();
  889. lt.spriteRen = ren;
  890. #endif
  891. return lt;
  892. }
  893. /**
  894. * Retrieve a sequencer object where you can easily chain together tweens and methods one after another <summary>Retrieve a sequencer object where you can easily chain together tweens and methods one after another</summary>
  895. *
  896. * @method LeanTween.sequence
  897. * @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
  898. * @example
  899. * var seq = LeanTween.sequence();<br />
  900. * seq.add(1f); // delay everything one second<br />
  901. * seq.add( () => { // fire an event before start<br />
  902. * &#160;Debug.Log("I have started");<br />
  903. * });<br />
  904. * seq.add( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br />
  905. * seq.add( () => { // fire event after tween<br />
  906. * &#160;Debug.Log("We are done now");<br />
  907. * });;<br />
  908. */
  909. public static LTSeq sequence( bool initSequence = true){
  910. init(maxTweens);
  911. // Loop through and find available sequence
  912. for (int i = 0; i < sequences.Length; i++) {
  913. // Debug.Log("i:" + i + " sequences[i]:" + sequences[i]);
  914. if (sequences[i].tween==null || sequences[i].tween.toggle == false) {
  915. if (sequences[i].toggle == false) {
  916. LTSeq seq = sequences[i];
  917. if (initSequence) {
  918. seq.init((uint)(i + tweens.Length), global_counter);
  919. global_counter++;
  920. if (global_counter > 0x8000)
  921. global_counter = 0;
  922. } else {
  923. seq.reset();
  924. }
  925. return seq;
  926. }
  927. }
  928. }
  929. return null;
  930. }
  931. /**
  932. * Fade a GUI Object <summary>Fade a GUI Object</summary>
  933. *
  934. * @method LeanTween.alpha
  935. * @param {LTRect} ltRect:LTRect LTRect that you wish to fade
  936. * @param {float} to:float the final alpha value (0-1)
  937. * @param {float} time:float The time with which to fade the object
  938. * @return {LTDescr} LTDescr an object that distinguishes the tween
  939. * @example
  940. * LeanTween.alpha(ltRect, 1f, 1f) .setEase(LeanTweenType.easeInCirc);
  941. */
  942. public static LTDescr alpha(LTRect ltRect, float to, float time){
  943. ltRect.alphaEnabled = true;
  944. return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, options().setGUIAlpha().setRect( ltRect ) );
  945. }
  946. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  947. /**
  948. * Fade a Unity UI Object <summary>Fade a Unity UI Object</summary>
  949. *
  950. * @method LeanTween.alphaText
  951. * @param {RectTransform} rectTransform:RectTransform RectTransform associated with the Text Component you wish to fade
  952. * @param {float} to:float the final alpha value (0-1)
  953. * @param {float} time:float The time with which to fade the object
  954. * @return {LTDescr} LTDescr an object that distinguishes the tween
  955. * @example
  956. * LeanTween.alphaText(gameObject.GetComponent&lt;RectTransform&gt;(), 1f, 1f) .setEase(LeanTweenType.easeInCirc);
  957. */
  958. public static LTDescr textAlpha(RectTransform rectTransform, float to, float time){
  959. return pushNewTween(rectTransform.gameObject, new Vector3(to,0,0), time, options().setTextAlpha());
  960. }
  961. public static LTDescr alphaText(RectTransform rectTransform, float to, float time){
  962. return pushNewTween(rectTransform.gameObject, new Vector3(to,0,0), time, options().setTextAlpha());
  963. }
  964. /**
  965. * Fade a Unity UI Canvas Group <summary>Fade a Unity UI Canvas Group</summary>
  966. *
  967. * @method LeanTween.alphaCanvas
  968. * @param {RectTransform} rectTransform:RectTransform RectTransform that the CanvasGroup is attached to
  969. * @param {float} to:float the final alpha value (0-1)
  970. * @param {float} time:float The time with which to fade the object
  971. * @return {LTDescr} LTDescr an object that distinguishes the tween
  972. * @example
  973. * LeanTween.alphaCanvas(gameObject.GetComponent&lt;RectTransform&gt;(), 0f, 1f) .setLoopPingPong();
  974. */
  975. public static LTDescr alphaCanvas(CanvasGroup canvasGroup, float to, float time){
  976. return pushNewTween(canvasGroup.gameObject, new Vector3(to,0,0), time, options().setCanvasGroupAlpha());
  977. }
  978. #endif
  979. /**
  980. * This works by tweening the vertex colors directly.<br /> <summary>This works by tweening the vertex colors directly</summary>
  981. <br />
  982. Vertex-based coloring is useful because you avoid making a copy of your
  983. object's material for each instance that needs a different color.<br />
  984. <br />
  985. A shader that supports vertex colors is required for it to work
  986. (for example the shaders in Mobile/Particles/)
  987. *
  988. * @method LeanTween.alphaVertex
  989. * @param {GameObject} gameObject:GameObject Gameobject that you wish to alpha
  990. * @param {float} to:float The alpha value you wish to tween to
  991. * @param {float} time:float The time with which to delay before calling the function
  992. * @return {LTDescr} LTDescr an object that distinguishes the tween
  993. */
  994. public static LTDescr alphaVertex(GameObject gameObject, float to, float time){
  995. return pushNewTween( gameObject, new Vector3(to,0f,0f), time, options().setAlphaVertex() );
  996. }
  997. /**
  998. * Change a gameobject's material to a certain color value. The material's shader needs to support color tinting. <a href="http://owlchemylabs.com/content/">Owl labs has some excellent efficient shaders</a>. <summary>Change a gameobject's material to a certain color value</summary>
  999. *
  1000. * @method LeanTween.color
  1001. * @param {GameObject} gameObject:GameObject Gameobject that you wish to change the color
  1002. * @param {Color} to:Color the final color value ex: Color.Red, new Color(1.0f,1.0f,0.0f,0.8f)
  1003. * @param {float} time:float The time with which to fade the object
  1004. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1005. * @example
  1006. * LeanTween.color(gameObject, Color.yellow, 1f) .setDelay(1f);
  1007. */
  1008. public static LTDescr color(GameObject gameObject, Color to, float time){
  1009. LTDescr lt = pushNewTween( gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setColor().setPoint( new Vector3(to.r, to.g, to.b) ) );
  1010. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  1011. SpriteRenderer ren = gameObject.GetComponent<SpriteRenderer>();
  1012. lt.spriteRen = ren;
  1013. #endif
  1014. return lt;
  1015. }
  1016. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  1017. /**
  1018. * Change the color a Unity UI Object <summary>Change the color a Unity UI Object</summary>
  1019. *
  1020. * @method LeanTween.colorText
  1021. * @param {RectTransform} rectTransform:RectTransform RectTransform attached to the Text Component whose color you want to change
  1022. * @param {Color} to:Color the final alpha value ex: Color.Red, new Color(1.0f,1.0f,0.0f,0.8f)
  1023. * @param {float} time:float The time with which to fade the object
  1024. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1025. * @example
  1026. * LeanTween.colorText(gameObject.GetComponent&lt;RectTransform&gt;(), Color.yellow, 1f) .setDelay(1f);
  1027. */
  1028. public static LTDescr textColor(RectTransform rectTransform, Color to, float time){
  1029. return pushNewTween(rectTransform.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
  1030. }
  1031. public static LTDescr colorText(RectTransform rectTransform, Color to, float time){
  1032. return pushNewTween(rectTransform.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
  1033. }
  1034. #endif
  1035. /**
  1036. * Call a method after a specified amount of time <summary>Call a method after a specified amount of time</summary>
  1037. *
  1038. * @method LeanTween.delayedCall
  1039. * @param {GameObject} gameObject:GameObject Gameobject that you wish to associate with this delayed call
  1040. * @param {float} time:float delay The time you wish to pass before the method is called
  1041. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1042. * @example LeanTween.delayedCall(gameObject, 1f, ()=>{ <br />Debug.Log("I am called one second later!");<br /> }));
  1043. */
  1044. public static LTDescr delayedCall( float delayTime, Action callback){
  1045. return pushNewTween( tweenEmpty, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
  1046. }
  1047. public static LTDescr delayedCall( float delayTime, Action<object> callback){
  1048. return pushNewTween( tweenEmpty, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
  1049. }
  1050. public static LTDescr delayedCall( GameObject gameObject, float delayTime, Action callback){
  1051. return pushNewTween( gameObject, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
  1052. }
  1053. public static LTDescr delayedCall( GameObject gameObject, float delayTime, Action<object> callback){
  1054. return pushNewTween( gameObject, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
  1055. }
  1056. public static LTDescr destroyAfter( LTRect rect, float delayTime){
  1057. return pushNewTween( tweenEmpty, Vector3.zero, delayTime, options().setCallback().setRect( rect ).setDestroyOnComplete(true) );
  1058. }
  1059. /*public static LTDescr delayedCall(GameObject gameObject, float delayTime, string callback){
  1060. return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete( callback ) );
  1061. }*/
  1062. /**
  1063. * Move a GameObject to a certain location <summary>Move a GameObject to a certain location</summary>
  1064. *
  1065. * @method LeanTween.move
  1066. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1067. * @param {Vector3} vec:Vector3 to The final positin with which to move to
  1068. * @param {float} time:float time The time to complete the tween in
  1069. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1070. * @example LeanTween.move(gameObject, new Vector3(0f,-3f,5f), 2.0f) .setEase( LeanTweenType.easeOutQuad );
  1071. */
  1072. public static LTDescr move(GameObject gameObject, Vector3 to, float time){
  1073. return pushNewTween( gameObject, to, time, options().setMove() );
  1074. }
  1075. public static LTDescr move(GameObject gameObject, Vector2 to, float time){
  1076. return pushNewTween( gameObject, new Vector3(to.x, to.y, gameObject.transform.position.z), time, options().setMove() );
  1077. }
  1078. /**
  1079. * Move a GameObject along a set of bezier curves <summary>Move a GameObject along a set of bezier curves</summary>
  1080. *
  1081. * @method LeanTween.move
  1082. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1083. * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle2,Handle1,Point2,...
  1084. * @param {float} time:float The time to complete the tween in
  1085. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1086. * @example
  1087. * <i>Javascript:</i><br />
  1088. * LeanTween.move(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
  1089. * <i>C#:</i><br />
  1090. * LeanTween.move(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).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);;<br />
  1091. */
  1092. public static LTDescr move(GameObject gameObject, Vector3[] to, float time){
  1093. d = options().setMoveCurved();
  1094. if(d.optional.path==null)
  1095. d.optional.path = new LTBezierPath( to );
  1096. else
  1097. d.optional.path.setPoints( to );
  1098. return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
  1099. }
  1100. public static LTDescr move(GameObject gameObject, LTBezierPath to, float time) {
  1101. d = options().setMoveCurved();
  1102. d.optional.path = to;
  1103. return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
  1104. }
  1105. public static LTDescr move(GameObject gameObject, LTSpline to, float time) {
  1106. d = options().setMoveSpline();
  1107. d.optional.spline = to;
  1108. return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
  1109. }
  1110. /**
  1111. * Move a GameObject through a set of points <summary>Move a GameObject through a set of points</summary>
  1112. *
  1113. * @method LeanTween.moveSpline
  1114. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1115. * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd<br />Note: The first and last item just define the angle of the end points, they are not actually used in the spline path itself. If you do not care about the angle you can jus set the first two items and last two items as the same value.
  1116. * @param {float} time:float The time to complete the tween in
  1117. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1118. * @example
  1119. * <i>Javascript:</i><br />
  1120. * LeanTween.moveSpline(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
  1121. * <i>C#:</i><br />
  1122. * 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).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
  1123. */
  1124. public static LTDescr moveSpline(GameObject gameObject, Vector3[] to, float time){
  1125. d = options().setMoveSpline();
  1126. d.optional.spline = new LTSpline( to );
  1127. return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
  1128. }
  1129. /**
  1130. * Move a GameObject through a set of points <summary>Move a GameObject through a set of points</summary>
  1131. *
  1132. * @method LeanTween.moveSpline
  1133. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1134. * @param {LTSpline} spline:LTSpline pass a pre-existing LTSpline for the object to move along
  1135. * @param {float} time:float The time to complete the tween in
  1136. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1137. * @example
  1138. * <i>Javascript:</i><br />
  1139. * LeanTween.moveSpline(gameObject, ltSpline, 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
  1140. * <i>C#:</i><br />
  1141. * LeanTween.moveSpline(gameObject, ltSpline, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
  1142. */
  1143. public static LTDescr moveSpline(GameObject gameObject, LTSpline to, float time){
  1144. d = options().setMoveSpline();
  1145. d.optional.spline = to;
  1146. return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
  1147. }
  1148. /**
  1149. * Move a GameObject through a set of points, in local space <summary>Move a GameObject through a set of points, in local space</summary>
  1150. *
  1151. * @method LeanTween.moveSplineLocal
  1152. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1153. * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
  1154. * @param {float} time:float The time to complete the tween in
  1155. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1156. * @example
  1157. * <i>Javascript:</i><br />
  1158. * LeanTween.moveSpline(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
  1159. * <i>C#:</i><br />
  1160. * 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).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
  1161. */
  1162. public static LTDescr moveSplineLocal(GameObject gameObject, Vector3[] to, float time){
  1163. d = options().setMoveSplineLocal();
  1164. d.optional.spline = new LTSpline( to );
  1165. return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
  1166. }
  1167. /**
  1168. * Move a GUI Element to a certain location <summary>Move a GUI Element to a certain location</summary>
  1169. *
  1170. * @method LeanTween.move (GUI)
  1171. * @param {LTRect} ltRect:LTRect ltRect LTRect object that you wish to move
  1172. * @param {Vector2} vec:Vector2 to The final position with which to move to (pixel coordinates)
  1173. * @param {float} time:float time The time to complete the tween in
  1174. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1175. */
  1176. public static LTDescr move(LTRect ltRect, Vector2 to, float time){
  1177. return pushNewTween( tweenEmpty, to, time, options().setGUIMove().setRect( ltRect ) );
  1178. }
  1179. public static LTDescr moveMargin(LTRect ltRect, Vector2 to, float time){
  1180. return pushNewTween( tweenEmpty, to, time, options().setGUIMoveMargin().setRect( ltRect ) );
  1181. }
  1182. /**
  1183. * Move a GameObject along the x-axis <summary>Move a GameObject along the x-axis</summary>
  1184. *
  1185. * @method LeanTween.moveX
  1186. * @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to move
  1187. * @param {float} to:float to The final position with which to move to
  1188. * @param {float} time:float time The time to complete the move in
  1189. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1190. */
  1191. public static LTDescr moveX(GameObject gameObject, float to, float time){
  1192. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveX() );
  1193. }
  1194. /**
  1195. * Move a GameObject along the y-axis <summary>Move a GameObject along the y-axis</summary>
  1196. *
  1197. * @method LeanTween.moveY
  1198. * @param {GameObject} GameObject gameObject Gameobject that you wish to move
  1199. * @param {float} float to The final position with which to move to
  1200. * @param {float} float time The time to complete the move in
  1201. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1202. */
  1203. public static LTDescr moveY(GameObject gameObject, float to, float time){
  1204. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveY() );
  1205. }
  1206. /**
  1207. * Move a GameObject along the z-axis <summary>Move a GameObject along the z-axis</summary>
  1208. *
  1209. * @method LeanTween.moveZ
  1210. * @param {GameObject} GameObject gameObject Gameobject that you wish to move
  1211. * @param {float} float to The final position with which to move to
  1212. * @param {float} float time The time to complete the move in
  1213. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1214. */
  1215. public static LTDescr moveZ(GameObject gameObject, float to, float time){
  1216. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveZ() );
  1217. }
  1218. /**
  1219. * Move a GameObject to a certain location relative to the parent transform. <summary>Move a GameObject to a certain location relative to the parent transform.</summary>
  1220. *
  1221. * @method LeanTween.moveLocal
  1222. * @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
  1223. * @param {Vector3} Vector3 to The final positin with which to move to
  1224. * @param {float} float time The time to complete the tween in
  1225. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1226. */
  1227. public static LTDescr moveLocal(GameObject gameObject, Vector3 to, float time){
  1228. return pushNewTween( gameObject, to, time, options().setMoveLocal() );
  1229. }
  1230. /**
  1231. * Move a GameObject along a set of bezier curves, in local space <summary>Move a GameObject along a set of bezier curves, in local space</summary>
  1232. *
  1233. * @method LeanTween.moveLocal
  1234. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1235. * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,...
  1236. * @param {float} time:float The time to complete the tween in
  1237. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1238. * @example
  1239. * <i>Javascript:</i><br />
  1240. * LeanTween.moveLocal(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br /><br />
  1241. * <i>C#:</i><br />
  1242. * LeanTween.moveLocal(gameObject, new Vector3[]{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);<br />
  1243. */
  1244. public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time){
  1245. d = options().setMoveCurvedLocal();
  1246. if(d.optional.path==null)
  1247. d.optional.path = new LTBezierPath( to );
  1248. else
  1249. d.optional.path.setPoints( to );
  1250. return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
  1251. }
  1252. public static LTDescr moveLocalX(GameObject gameObject, float to, float time){
  1253. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveLocalX() );
  1254. }
  1255. public static LTDescr moveLocalY(GameObject gameObject, float to, float time){
  1256. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveLocalY() );
  1257. }
  1258. public static LTDescr moveLocalZ(GameObject gameObject, float to, float time){
  1259. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveLocalZ() );
  1260. }
  1261. public static LTDescr moveLocal(GameObject gameObject, LTBezierPath to, float time) {
  1262. d = options().setMoveCurvedLocal();
  1263. d.optional.path = to;
  1264. return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
  1265. }
  1266. public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time) {
  1267. d = options().setMoveSplineLocal();
  1268. d.optional.spline = to;
  1269. return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
  1270. }
  1271. /**
  1272. * Move a GameObject to another transform <summary>Move a GameObject to another transform</summary>
  1273. *
  1274. * @method LeanTween.move
  1275. * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
  1276. * @param {Transform} destination:Transform Transform whose position the tween will finally end on
  1277. * @param {float} time:float time The time to complete the tween in
  1278. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1279. * @example LeanTween.move(gameObject, anotherTransform, 2.0f) .setEase( LeanTweenType.easeOutQuad );
  1280. */
  1281. public static LTDescr move(GameObject gameObject, Transform to, float time){
  1282. return pushNewTween(gameObject, Vector3.zero, time, options().setTo(to).setMoveToTransform() );
  1283. }
  1284. /**
  1285. * Rotate a GameObject, to values are in passed in degrees <summary>Rotate a GameObject, to values are in passed in degrees</summary>
  1286. *
  1287. * @method LeanTween.rotate
  1288. * @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
  1289. * @param {Vector3} Vector3 to The final rotation with which to rotate to
  1290. * @param {float} float time The time to complete the tween in
  1291. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1292. * @example LeanTween.rotate(cube, new Vector3(180f,30f,0f), 1.5f);
  1293. */
  1294. public static LTDescr rotate(GameObject gameObject, Vector3 to, float time){
  1295. return pushNewTween( gameObject, to, time, options().setRotate() );
  1296. }
  1297. /**
  1298. * Rotate a GUI element (using an LTRect object), to a value that is in degrees <summary>Rotate a GUI element (using an LTRect object), to a value that is in degrees</summary>
  1299. *
  1300. * @method LeanTween.rotate
  1301. * @param {LTRect} ltRect:LTRect LTRect that you wish to rotate
  1302. * @param {float} to:float The final rotation with which to rotate to
  1303. * @param {float} time:float The time to complete the tween in
  1304. * @param {Array} optional:Array Object Array where you can pass <a href="#optional">optional items</a>.
  1305. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1306. * @example
  1307. * if(GUI.Button(buttonRect.rect, "Rotate"))<br />
  1308. * LeanTween.rotate( buttonRect4, 150.0f, 1.0f).setEase(LeanTweenType.easeOutElastic);<br />
  1309. * GUI.matrix = Matrix4x4.identity;<br />
  1310. */
  1311. public static LTDescr rotate(LTRect ltRect, float to, float time){
  1312. return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, options().setGUIRotate().setRect( ltRect ) );
  1313. }
  1314. /**
  1315. * Rotate a GameObject in the objects local space (on the transforms localEulerAngles object) <summary>Rotate a GameObject in the objects local space (on the transforms localEulerAngles object)</summary>
  1316. *
  1317. * @method LeanTween.rotateLocal
  1318. * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
  1319. * @param {Vector3} to:Vector3 The final rotation with which to rotate to
  1320. * @param {float} time:float The time to complete the rotation in
  1321. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1322. */
  1323. public static LTDescr rotateLocal(GameObject gameObject, Vector3 to, float time){
  1324. return pushNewTween( gameObject, to, time, options().setRotateLocal() );
  1325. }
  1326. /**
  1327. * Rotate a GameObject only on the X axis <summary>Rotate a GameObject only on the X axis</summary>
  1328. *
  1329. * @method LeanTween.rotateX
  1330. * @param {GameObject} GameObject Gameobject that you wish to rotate
  1331. * @param {float} to:float The final x-axis rotation with which to rotate
  1332. * @param {float} time:float The time to complete the rotation in
  1333. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1334. */
  1335. public static LTDescr rotateX(GameObject gameObject, float to, float time){
  1336. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setRotateX() );
  1337. }
  1338. /**
  1339. * Rotate a GameObject only on the Y axis <summary>Rotate a GameObject only on the Y axis</summary>
  1340. *
  1341. * @method LeanTween.rotateY
  1342. * @param {GameObject} GameObject Gameobject that you wish to rotate
  1343. * @param {float} to:float The final y-axis rotation with which to rotate
  1344. * @param {float} time:float The time to complete the rotation in
  1345. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1346. */
  1347. public static LTDescr rotateY(GameObject gameObject, float to, float time){
  1348. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setRotateY() );
  1349. }
  1350. /**
  1351. * Rotate a GameObject only on the Z axis <summary>Rotate a GameObject only on the Z axis</summary>
  1352. *
  1353. * @method LeanTween.rotateZ
  1354. * @param {GameObject} GameObject Gameobject that you wish to rotate
  1355. * @param {float} to:float The final z-axis rotation with which to rotate
  1356. * @param {float} time:float The time to complete the rotation in
  1357. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1358. */
  1359. public static LTDescr rotateZ(GameObject gameObject, float to, float time){
  1360. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setRotateZ() );
  1361. }
  1362. /**
  1363. * Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees) <summary>Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees)</summary>
  1364. *
  1365. * @method LeanTween.rotateAround
  1366. * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
  1367. * @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
  1368. * @param {float} degrees:float the degrees in which to rotate
  1369. * @param {float} time:float time The time to complete the rotation in
  1370. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1371. * @example
  1372. * <i>Example:</i><br />
  1373. * LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
  1374. */
  1375. public static LTDescr rotateAround(GameObject gameObject, Vector3 axis, float add, float time){
  1376. return pushNewTween( gameObject, new Vector3(add,0f,0f), time, options().setAxis(axis).setRotateAround() );
  1377. }
  1378. /**
  1379. * Rotate a GameObject around a certain Axis in Local Space (the best method to use when you want to rotate beyond 180 degrees) <summary>Rotate a GameObject around a certain Axis in Local Space (the best method to use when you want to rotate beyond 180 degrees) </summary>
  1380. *
  1381. * @method LeanTween.rotateAroundLocal
  1382. * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
  1383. * @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
  1384. * @param {float} degrees:float the degrees in which to rotate
  1385. * @param {float} time:float time The time to complete the rotation in
  1386. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1387. * @example
  1388. * <i>Example:</i><br />
  1389. * LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
  1390. */
  1391. public static LTDescr rotateAroundLocal(GameObject gameObject, Vector3 axis, float add, float time){
  1392. return pushNewTween( gameObject, new Vector3(add,0f,0f), time, options().setRotateAroundLocal().setAxis(axis) );
  1393. }
  1394. /**
  1395. * Scale a GameObject to a certain size <summary>Scale a GameObject to a certain size</summary>
  1396. *
  1397. * @method LeanTween.scale
  1398. * @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to scale
  1399. * @param {Vector3} vec:Vector3 to The size with which to tween to
  1400. * @param {float} time:float time The time to complete the tween in
  1401. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1402. */
  1403. public static LTDescr scale(GameObject gameObject, Vector3 to, float time){
  1404. return pushNewTween( gameObject, to, time, options().setScale() );
  1405. }
  1406. /**
  1407. * Scale a GUI Element to a certain width and height <summary>Scale a GUI Element to a certain width and height</summary>
  1408. *
  1409. * @method LeanTween.scale (GUI)
  1410. * @param {LTRect} LTRect ltRect LTRect object that you wish to move
  1411. * @param {Vector2} Vector2 to The final width and height to scale to (pixel based)
  1412. * @param {float} float time The time to complete the tween in
  1413. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1414. * @example
  1415. * <i>Example Javascript: </i><br />
  1416. * var bRect:LTRect = new LTRect( 0, 0, 100, 50 );<br />
  1417. * LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 ).setEase(LeanTweenType.easeOutBounce);<br />
  1418. * function OnGUI(){<br />
  1419. * &#160; if(GUI.Button(bRect.rect, "Scale")){ }<br />
  1420. * }<br />
  1421. * <br />
  1422. * <i>Example C#: </i> <br />
  1423. * LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );<br />
  1424. * LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f ).setEase(LeanTweenType.easeOutBounce);<br />
  1425. * void OnGUI(){<br />
  1426. * &#160; if(GUI.Button(bRect.rect, "Scale")){ }<br />
  1427. * }<br />
  1428. */
  1429. public static LTDescr scale(LTRect ltRect, Vector2 to, float time){
  1430. return pushNewTween( tweenEmpty, to, time, options().setGUIScale().setRect( ltRect ) );
  1431. }
  1432. /**
  1433. * Scale a GameObject to a certain size along the x-axis only <summary>Scale a GameObject to a certain size along the x-axis only</summary>
  1434. *
  1435. * @method LeanTween.scaleX
  1436. * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
  1437. * @param {float} scaleTo:float the size with which to scale to
  1438. * @param {float} time:float the time to complete the tween in
  1439. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1440. */
  1441. public static LTDescr scaleX(GameObject gameObject, float to, float time){
  1442. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setScaleX() );
  1443. }
  1444. /**
  1445. * Scale a GameObject to a certain size along the y-axis only <summary>Scale a GameObject to a certain size along the y-axis only</summary>
  1446. *
  1447. * @method LeanTween.scaleY
  1448. * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
  1449. * @param {float} scaleTo:float the size with which to scale to
  1450. * @param {float} time:float the time to complete the tween in
  1451. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1452. */
  1453. public static LTDescr scaleY(GameObject gameObject, float to, float time){
  1454. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setScaleY() );
  1455. }
  1456. /**
  1457. * Scale a GameObject to a certain size along the z-axis only <summary>Scale a GameObject to a certain size along the z-axis only</summary>
  1458. *
  1459. * @method LeanTween.scaleZ
  1460. * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
  1461. * @param {float} scaleTo:float the size with which to scale to
  1462. * @param {float} time:float the time to complete the tween in
  1463. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1464. */
  1465. public static LTDescr scaleZ(GameObject gameObject, float to, float time){
  1466. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setScaleZ());
  1467. }
  1468. /**
  1469. * Tween any particular value (float) <summary>Tween any particular value (float)</summary>
  1470. *
  1471. * @method LeanTween.value (float)
  1472. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1473. * @param {float} from:float The original value to start the tween from
  1474. * @param {Vector3} to:float The final float with which to tween to
  1475. * @param {float} time:float The time to complete the tween in
  1476. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1477. * @example
  1478. * <i>Example Javascript: </i><br />
  1479. * LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( function( val:float ){ <br />
  1480. * &#160;Debug.Log("tweened val:"+val);<br />
  1481. * } );<br />
  1482. * <br />
  1483. * <i>Example C#: </i> <br />
  1484. * LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( (float val)=>{ <br />
  1485. * &#160;Debug.Log("tweened val:"+val);<br />
  1486. * } );<br />
  1487. */
  1488. public static LTDescr value(GameObject gameObject, float from, float to, float time){
  1489. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setCallback().setFrom( new Vector3(from,0,0) ) );
  1490. }
  1491. public static LTDescr value(float from, float to, float time){
  1492. return pushNewTween( tweenEmpty, new Vector3(to,0,0), time, options().setCallback().setFrom( new Vector3(from,0,0) ) );
  1493. }
  1494. /**
  1495. * Tween any particular value (Vector2)
  1496. *
  1497. * @method LeanTween.value (Vector2)
  1498. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1499. * @param {Vector2} from:Vector2 The original value to start the tween from
  1500. * @param {Vector3} to:Vector2 The final Vector2 with which to tween to
  1501. * @param {float} time:float The time to complete the tween in
  1502. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1503. * @example
  1504. * <i>Example Javascript: </i><br />
  1505. * LeanTween.value( gameObject, new Vector2(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( function( val:Vector2 ){ <br />
  1506. * &#160;Debug.Log("tweened val:"+val);<br />
  1507. * } );<br />
  1508. * <br />
  1509. * <i>Example C#: </i> <br />
  1510. * LeanTween.value( gameObject, new Vector3(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( (Vector2 val)=>{ <br />
  1511. * &#160;Debug.Log("tweened val:"+val);<br />
  1512. * } );<br />
  1513. */
  1514. public static LTDescr value(GameObject gameObject, Vector2 from, Vector2 to, float time){
  1515. return pushNewTween( gameObject, new Vector3(to.x,to.y,0), time, options().setValue3().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0) ) );
  1516. }
  1517. /**
  1518. * Tween any particular value (Vector3)
  1519. *
  1520. * @method LeanTween.value (Vector3)
  1521. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1522. * @param {Vector3} from:Vector3 The original value to start the tween from
  1523. * @param {Vector3} to:Vector3 The final Vector3 with which to tween to
  1524. * @param {float} time:float The time to complete the tween in
  1525. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1526. * @example
  1527. * <i>Example Javascript: </i><br />
  1528. * LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( function( val:Vector3 ){ <br />
  1529. * &#160;Debug.Log("tweened val:"+val);<br />
  1530. * } );<br />
  1531. * <br />
  1532. * <i>Example C#: </i> <br />
  1533. * LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( (Vector3 val)=>{ <br />
  1534. * &#160;Debug.Log("tweened val:"+val);<br />
  1535. * } );<br />
  1536. */
  1537. public static LTDescr value(GameObject gameObject, Vector3 from, Vector3 to, float time){
  1538. return pushNewTween( gameObject, to, time, options().setValue3().setFrom( from ) );
  1539. }
  1540. /**
  1541. * Tween any particular value (Color)
  1542. *
  1543. * @method LeanTween.value (Color)
  1544. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1545. * @param {Color} from:Color The original value to start the tween from
  1546. * @param {Color} to:Color The final Color with which to tween to
  1547. * @param {float} time:float The time to complete the tween in
  1548. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1549. * @example
  1550. * <i>Example Javascript: </i><br />
  1551. * LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( function( val:Color ){ <br />
  1552. * &#160;Debug.Log("tweened val:"+val);<br />
  1553. * } );<br />
  1554. * <br />
  1555. * <i>Example C#: </i> <br />
  1556. * LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( (Color val)=>{ <br />
  1557. * &#160;Debug.Log("tweened val:"+val);<br />
  1558. * } );<br />
  1559. */
  1560. public static LTDescr value(GameObject gameObject, Color from, Color to, float time){
  1561. LTDescr lt = pushNewTween( gameObject, new Vector3(1f, to.a, 0f), time, options().setCallbackColor().setPoint( new Vector3(to.r, to.g, to.b) )
  1562. .setFromColor(from).setHasInitialized(false) );
  1563. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
  1564. SpriteRenderer ren = gameObject.GetComponent<SpriteRenderer>();
  1565. lt.spriteRen = ren;
  1566. #endif
  1567. return lt;
  1568. }
  1569. /**
  1570. * Tween any particular value, it does not need to be tied to any particular type or GameObject
  1571. *
  1572. * @method LeanTween.value (float)
  1573. * @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject
  1574. * @param {Action<float>} callOnUpdate:Action<float> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( float val ){ }
  1575. * @param {float} float from The original value to start the tween from
  1576. * @param {float} float to The value to end the tween on
  1577. * @param {float} float time The time to complete the tween in
  1578. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1579. * @example
  1580. * <i>Example Javascript: </i><br />
  1581. * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
  1582. * function updateValueExampleCallback( val:float ){<br />
  1583. * &#160; Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");<br />
  1584. * }<br />
  1585. * <br />
  1586. * <i>Example C#: </i> <br />
  1587. * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
  1588. * void updateValueExampleCallback( float val ){<br />
  1589. * &#160; Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");<br />
  1590. * }<br />
  1591. */
  1592. public static LTDescr value(GameObject gameObject, Action<float> callOnUpdate, float from, float to, float time){
  1593. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setCallback().setTo( new Vector3(to,0,0) ).setFrom( new Vector3(from,0,0) ).setOnUpdate(callOnUpdate) );
  1594. }
  1595. /**
  1596. * Tweens any float value, it does not need to be tied to any particular type or GameObject
  1597. *
  1598. * @method LeanTween.value (float)
  1599. * @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject
  1600. * @param {Action<float, float>} callOnUpdateRatio:Action<float,float> Function that's called every Update frame. It must accept two float values ex: function updateValue( float val, float ratio){ }
  1601. * @param {float} float from The original value to start the tween from
  1602. * @param {float} float to The value to end the tween on
  1603. * @param {float} float time The time to complete the tween in
  1604. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1605. * @example
  1606. * <i>Example Javascript: </i><br />
  1607. * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
  1608. * function updateValueExampleCallback( val:float, ratio:float ){<br />
  1609. * &#160; Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);<br />
  1610. * }<br />
  1611. * <br />
  1612. * <i>Example C#: </i> <br />
  1613. * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);<br />
  1614. * void updateValueExampleCallback( float val, float ratio ){<br />
  1615. * &#160; Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);<br />
  1616. * }<br />
  1617. */
  1618. public static LTDescr value(GameObject gameObject, Action<float, float> callOnUpdateRatio, float from, float to, float time) {
  1619. return pushNewTween(gameObject, new Vector3(to, 0, 0), time, options().setCallback().setTo(new Vector3(to, 0, 0)).setFrom(new Vector3(from, 0, 0)).setOnUpdateRatio(callOnUpdateRatio));
  1620. }
  1621. /**
  1622. * Tween from one color to another
  1623. *
  1624. * @method LeanTween.value (Color)
  1625. * @param {GameObject} GameObject gameObject GameObject with which to tie the tweening with. This is only used when you need to cancel this tween, it does not actually perform any operations on this gameObject
  1626. * @param {Action<Color>} callOnUpdate:Action<Color> The function that is called on every Update frame, this function needs to accept a color value ex: function updateValue( Color val ){ }
  1627. * @param {Color} Color from The original value to start the tween from
  1628. * @param {Color} Color to The value to end the tween on
  1629. * @param {Color} Color time The time to complete the tween in
  1630. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1631. * @example
  1632. * <i>Example Javascript: </i><br />
  1633. * LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);<br />
  1634. * function updateValueExampleCallback( val:Color ){<br />
  1635. * &#160; Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");<br />
  1636. * }<br />
  1637. * <br />
  1638. * <i>Example C#: </i> <br />
  1639. * LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);<br />
  1640. * void updateValueExampleCallback( Color val ){<br />
  1641. * &#160; Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");<br />
  1642. * }<br />
  1643. */
  1644. public static LTDescr value(GameObject gameObject, Action<Color> callOnUpdate, Color from, Color to, float time){
  1645. return pushNewTween( gameObject, new Vector3(1.0f,to.a,0.0f), time, options().setCallbackColor().setPoint( new Vector3(to.r, to.g, to.b) )
  1646. .setAxis( new Vector3(from.r, from.g, from.b) ).setFrom( new Vector3(0.0f, from.a, 0.0f) ).setHasInitialized(false).setOnUpdateColor(callOnUpdate) );
  1647. }
  1648. public static LTDescr value(GameObject gameObject, Action<Color,object> callOnUpdate, Color from, Color to, float time){
  1649. return pushNewTween( gameObject, new Vector3(1.0f,to.a,0.0f), time, options().setCallbackColor().setPoint( new Vector3(to.r, to.g, to.b) )
  1650. .setAxis( new Vector3(from.r, from.g, from.b) ).setFrom( new Vector3(0.0f, from.a, 0.0f) ).setHasInitialized(false).setOnUpdateColor(callOnUpdate) );
  1651. }
  1652. /**
  1653. * Tween any particular value (Vector2), this could be used to tween an arbitrary value like offset property
  1654. *
  1655. * @method LeanTween.value (Vector2)
  1656. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1657. * @param {Action<Vector2>} callOnUpdate:Action<Vector2> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
  1658. * @param {float} from:Vector2 The original value to start the tween from
  1659. * @param {Vector2} to:Vector2 The final Vector3 with which to tween to
  1660. * @param {float} time:float The time to complete the tween in
  1661. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1662. */
  1663. public static LTDescr value(GameObject gameObject, Action<Vector2> callOnUpdate, Vector2 from, Vector2 to, float time){
  1664. return pushNewTween( gameObject, new Vector3(to.x,to.y,0f), time, options().setValue3().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0f) ).setOnUpdateVector2(callOnUpdate) );
  1665. }
  1666. /**
  1667. * Tween any particular value (Vector3), this could be used to tween an arbitrary property that uses a Vector
  1668. *
  1669. * @method LeanTween.value (Vector3)
  1670. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1671. * @param {Action<Vector3>} callOnUpdate:Action<Vector3> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
  1672. * @param {float} from:Vector3 The original value to start the tween from
  1673. * @param {Vector3} to:Vector3 The final Vector3 with which to tween to
  1674. * @param {float} time:float The time to complete the tween in
  1675. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1676. */
  1677. public static LTDescr value(GameObject gameObject, Action<Vector3> callOnUpdate, Vector3 from, Vector3 to, float time){
  1678. return pushNewTween( gameObject, to, time, options().setValue3().setTo( to ).setFrom( from ).setOnUpdateVector3(callOnUpdate) );
  1679. }
  1680. /**
  1681. * Tween any particular value (float)
  1682. *
  1683. * @method LeanTween.value (float,object)
  1684. * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
  1685. * @param {Action<float,object>} callOnUpdate:Action<float,object> The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val, object obj ){ }
  1686. * @param {float} from:float The original value to start the tween from
  1687. * @param {Vector3} to:float The final Vector3 with which to tween to
  1688. * @param {float} time:float The time to complete the tween in
  1689. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1690. */
  1691. public static LTDescr value(GameObject gameObject, Action<float,object> callOnUpdate, float from, float to, float time){
  1692. return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setCallback().setTo( new Vector3(to,0,0) ).setFrom( new Vector3(from,0,0) ).setOnUpdate(callOnUpdate, gameObject) );
  1693. }
  1694. public static LTDescr delayedSound( AudioClip audio, Vector3 pos, float volume ){
  1695. //Debug.LogError("Delay sound??");
  1696. return pushNewTween( tweenEmpty, pos, 0f, options().setDelayedSound().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) );
  1697. }
  1698. public static LTDescr delayedSound( GameObject gameObject, AudioClip audio, Vector3 pos, float volume ){
  1699. //Debug.LogError("Delay sound??");
  1700. return pushNewTween( gameObject, pos, 0f, options().setDelayedSound().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) );
  1701. }
  1702. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  1703. /**
  1704. * Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1705. *
  1706. * @method LeanTween.move (RectTransform)
  1707. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1708. * @param {Vector3} to:Vector3 The final Vector3 with which to tween to
  1709. * @param {float} time:float The time to complete the tween in
  1710. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1711. * @example LeanTween.move(gameObject.GetComponent&lt;RectTransform&gt;(), new Vector3(200f,-100f,0f), 1f).setDelay(1f);
  1712. */
  1713. public static LTDescr move(RectTransform rectTrans, Vector3 to, float time){
  1714. return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasMove().setRect( rectTrans ) );
  1715. }
  1716. /**
  1717. * Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1718. *
  1719. * @method LeanTween.moveX (RectTransform)
  1720. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1721. * @param {float} to:float The final x location with which to tween to
  1722. * @param {float} time:float The time to complete the tween in
  1723. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1724. * @example LeanTween.moveX(gameObject.GetComponent&lt;RectTransform&gt;(), 200f, 1f).setDelay(1f);
  1725. */
  1726. public static LTDescr moveX(RectTransform rectTrans, float to, float time){
  1727. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasMoveX().setRect( rectTrans ) );
  1728. }
  1729. /**
  1730. * Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1731. *
  1732. * @method LeanTween.moveY (RectTransform)
  1733. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1734. * @param {float} to:float The final y location with which to tween to
  1735. * @param {float} time:float The time to complete the tween in
  1736. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1737. * @example LeanTween.moveY(gameObject.GetComponent&lt;RectTransform&gt;(), 200f, 1f).setDelay(1f);
  1738. */
  1739. public static LTDescr moveY(RectTransform rectTrans, float to, float time){
  1740. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasMoveY().setRect( rectTrans ) );
  1741. }
  1742. /**
  1743. * Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)n</summary>
  1744. *
  1745. * @method LeanTween.moveZ (RectTransform)
  1746. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1747. * @param {float} to:float The final x location with which to tween to
  1748. * @param {float} time:float The time to complete the tween in
  1749. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1750. * @example LeanTween.moveZ(gameObject.GetComponent&lt;RectTransform&gt;(), 200f, 1f).setDelay(1f);
  1751. */
  1752. public static LTDescr moveZ(RectTransform rectTrans, float to, float time){
  1753. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasMoveZ().setRect( rectTrans ) );
  1754. }
  1755. /**
  1756. * Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1757. *
  1758. * @method LeanTween.rotate (RectTransform)
  1759. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1760. * @param {float} to:float The degree with which to rotate the RectTransform
  1761. * @param {float} time:float The time to complete the tween in
  1762. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1763. * @example LeanTween.rotate(gameObject.GetComponent&lt;RectTransform&gt;(), 90f, 1f).setDelay(1f);
  1764. */
  1765. public static LTDescr rotate(RectTransform rectTrans, float to, float time){
  1766. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasRotateAround().setRect( rectTrans ).setAxis(Vector3.forward) );
  1767. }
  1768. public static LTDescr rotate(RectTransform rectTrans, Vector3 to, float time){
  1769. return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasRotateAround().setRect( rectTrans ).setAxis(Vector3.forward) );
  1770. }
  1771. /**
  1772. * Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1773. *
  1774. * @method LeanTween.rotateAround (RectTransform)
  1775. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1776. * @param {Vector3} axis:Vector3 The axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
  1777. * @param {float} to:float The degree with which to rotate the RectTransform
  1778. * @param {float} time:float The time to complete the tween in
  1779. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1780. * @example LeanTween.rotateAround(gameObject.GetComponent&lt;RectTransform&gt;(), Vector3.forward, 90f, 1f).setDelay(1f);
  1781. */
  1782. public static LTDescr rotateAround(RectTransform rectTrans, Vector3 axis, float to, float time){
  1783. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasRotateAround().setRect( rectTrans ).setAxis(axis) );
  1784. }
  1785. /**
  1786. * Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1787. *
  1788. * @method LeanTween.rotateAroundLocal (RectTransform)
  1789. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1790. * @param {Vector3} axis:Vector3 The local axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
  1791. * @param {float} to:float The degree with which to rotate the RectTransform
  1792. * @param {float} time:float The time to complete the tween in
  1793. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1794. * @example LeanTween.rotateAroundLocal(gameObject.GetComponent&lt;RectTransform&gt;(), Vector3.forward, 90f, 1f).setDelay(1f);
  1795. */
  1796. public static LTDescr rotateAroundLocal(RectTransform rectTrans, Vector3 axis, float to, float time){
  1797. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasRotateAroundLocal().setRect( rectTrans ).setAxis(axis) );
  1798. }
  1799. /**
  1800. * Scale a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Scale a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1801. *
  1802. * @method LeanTween.scale (RectTransform)
  1803. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1804. * @param {Vector3} to:Vector3 The final Vector3 with which to tween to (localScale)
  1805. * @param {float} time:float The time to complete the tween in
  1806. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1807. * @example LeanTween.scale(gameObject.GetComponent&lt;RectTransform&gt;(), gameObject.GetComponent&lt;RectTransform&gt;().localScale*2f, 1f).setDelay(1f);
  1808. */
  1809. public static LTDescr scale(RectTransform rectTrans, Vector3 to, float time){
  1810. return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasScale().setRect( rectTrans ) );
  1811. }
  1812. /**
  1813. * Change the sizeDelta of a RectTransform object (used in Unity Canvas, for Buttons, Panel, Scrollbar, etc...) <summary>Change the sizeDelta of a RectTransform object (used in Unity Canvas, for Buttons, Panel, Scrollbar, etc...)</summary>
  1814. *
  1815. * @method LeanTween.size (RectTransform)
  1816. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1817. * @param {Vector2} to:Vector2 The final Vector2 the tween will end at for sizeDelta property
  1818. * @param {float} time:float The time to complete the tween in
  1819. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1820. * @example LeanTween.size(gameObject.GetComponent&lt;RectTransform&gt;(), gameObject.GetComponent&lt;RectTransform&gt;().sizeDelta*2f, 1f).setDelay(1f);
  1821. */
  1822. public static LTDescr size(RectTransform rectTrans, Vector2 to, float time){
  1823. return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasSizeDelta().setRect( rectTrans ) );
  1824. }
  1825. /**
  1826. * Alpha an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Alpha an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1827. *
  1828. * @method LeanTween.alpha (RectTransform)
  1829. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1830. * @param {float} to:float The final Vector3 with which to tween to (localScale)
  1831. * @param {float} time:float The time to complete the tween in
  1832. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1833. * @example LeanTween.alpha(gameObject.GetComponent&lt;RectTransform&gt;(), 0.5f, 1f).setDelay(1f);
  1834. */
  1835. public static LTDescr alpha(RectTransform rectTrans, float to, float time){
  1836. return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasAlpha().setRect( rectTrans ) );
  1837. }
  1838. /**
  1839. * Change the Color of an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) <summary>Change the Color of an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)</summary>
  1840. *
  1841. * @method LeanTween.alpha (RectTransform)
  1842. * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
  1843. * @param {float} to:float The final Vector3 with which to tween to (localScale)
  1844. * @param {float} time:float The time to complete the tween in
  1845. * @return {LTDescr} LTDescr an object that distinguishes the tween
  1846. * @example LeanTween.color(gameObject.GetComponent&lt;RectTransform&gt;(), 0.5f, 1f).setDelay(1f);
  1847. */
  1848. public static LTDescr color(RectTransform rectTrans, Color to, float time){
  1849. return pushNewTween( rectTrans.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setCanvasColor().setRect( rectTrans ).setPoint( new Vector3(to.r, to.g, to.b) ) );
  1850. }
  1851. #endif
  1852. // Tweening Functions - Thanks to Robert Penner and GFX47
  1853. public static float tweenOnCurve( LTDescr tweenDescr, float ratioPassed ){
  1854. // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed));
  1855. return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed);
  1856. }
  1857. public static Vector3 tweenOnCurveVector( LTDescr tweenDescr, float ratioPassed ){
  1858. return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed),
  1859. tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed),
  1860. tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed) );
  1861. }
  1862. public static float easeOutQuadOpt( float start, float diff, float ratioPassed ){
  1863. return -diff * ratioPassed * (ratioPassed - 2) + start;
  1864. }
  1865. public static float easeInQuadOpt( float start, float diff, float ratioPassed ){
  1866. return diff * ratioPassed * ratioPassed + start;
  1867. }
  1868. public static float easeInOutQuadOpt( float start, float diff, float ratioPassed ){
  1869. ratioPassed /= .5f;
  1870. if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
  1871. ratioPassed--;
  1872. return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
  1873. }
  1874. public static Vector3 easeInOutQuadOpt( Vector3 start, Vector3 diff, float ratioPassed ){
  1875. ratioPassed /= .5f;
  1876. if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
  1877. ratioPassed--;
  1878. return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
  1879. }
  1880. public static float linear(float start, float end, float val){
  1881. return Mathf.Lerp(start, end, val);
  1882. }
  1883. public static float clerp(float start, float end, float val){
  1884. float min = 0.0f;
  1885. float max = 360.0f;
  1886. float half = Mathf.Abs((max - min) / 2.0f);
  1887. float retval = 0.0f;
  1888. float diff = 0.0f;
  1889. if ((end - start) < -half){
  1890. diff = ((max - start) + end) * val;
  1891. retval = start + diff;
  1892. }else if ((end - start) > half){
  1893. diff = -((max - end) + start) * val;
  1894. retval = start + diff;
  1895. }else retval = start + (end - start) * val;
  1896. return retval;
  1897. }
  1898. public static float spring(float start, float end, float val ){
  1899. val = Mathf.Clamp01(val);
  1900. 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) ));
  1901. return start + (end - start) * val;
  1902. }
  1903. public static float easeInQuad(float start, float end, float val){
  1904. end -= start;
  1905. return end * val * val + start;
  1906. }
  1907. public static float easeOutQuad(float start, float end, float val){
  1908. end -= start;
  1909. return -end * val * (val - 2) + start;
  1910. }
  1911. public static float easeInOutQuad(float start, float end, float val){
  1912. val /= .5f;
  1913. end -= start;
  1914. if (val < 1) return end / 2 * val * val + start;
  1915. val--;
  1916. return -end / 2 * (val * (val - 2) - 1) + start;
  1917. }
  1918. public static float easeInOutQuadOpt2(float start, float diffBy2, float val, float val2){
  1919. val /= .5f;
  1920. if (val < 1) return diffBy2 * val2 + start;
  1921. val--;
  1922. return -diffBy2 * ((val2 - 2) - 1f) + start;
  1923. }
  1924. public static float easeInCubic(float start, float end, float val){
  1925. end -= start;
  1926. return end * val * val * val + start;
  1927. }
  1928. public static float easeOutCubic(float start, float end, float val){
  1929. val--;
  1930. end -= start;
  1931. return end * (val * val * val + 1) + start;
  1932. }
  1933. public static float easeInOutCubic(float start, float end, float val){
  1934. val /= .5f;
  1935. end -= start;
  1936. if (val < 1) return end / 2 * val * val * val + start;
  1937. val -= 2;
  1938. return end / 2 * (val * val * val + 2) + start;
  1939. }
  1940. public static float easeInQuart(float start, float end, float val){
  1941. end -= start;
  1942. return end * val * val * val * val + start;
  1943. }
  1944. public static float easeOutQuart(float start, float end, float val){
  1945. val--;
  1946. end -= start;
  1947. return -end * (val * val * val * val - 1) + start;
  1948. }
  1949. public static float easeInOutQuart(float start, float end, float val){
  1950. val /= .5f;
  1951. end -= start;
  1952. if (val < 1) return end / 2 * val * val * val * val + start;
  1953. val -= 2;
  1954. return -end / 2 * (val * val * val * val - 2) + start;
  1955. }
  1956. public static float easeInQuint(float start, float end, float val){
  1957. end -= start;
  1958. return end * val * val * val * val * val + start;
  1959. }
  1960. public static float easeOutQuint(float start, float end, float val){
  1961. val--;
  1962. end -= start;
  1963. return end * (val * val * val * val * val + 1) + start;
  1964. }
  1965. public static float easeInOutQuint(float start, float end, float val){
  1966. val /= .5f;
  1967. end -= start;
  1968. if (val < 1) return end / 2 * val * val * val * val * val + start;
  1969. val -= 2;
  1970. return end / 2 * (val * val * val * val * val + 2) + start;
  1971. }
  1972. public static float easeInSine(float start, float end, float val){
  1973. end -= start;
  1974. return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start;
  1975. }
  1976. public static float easeOutSine(float start, float end, float val){
  1977. end -= start;
  1978. return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start;
  1979. }
  1980. public static float easeInOutSine(float start, float end, float val){
  1981. end -= start;
  1982. return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start;
  1983. }
  1984. public static float easeInExpo(float start, float end, float val){
  1985. end -= start;
  1986. return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start;
  1987. }
  1988. public static float easeOutExpo(float start, float end, float val){
  1989. end -= start;
  1990. return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start;
  1991. }
  1992. public static float easeInOutExpo(float start, float end, float val){
  1993. val /= .5f;
  1994. end -= start;
  1995. if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start;
  1996. val--;
  1997. return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start;
  1998. }
  1999. public static float easeInCirc(float start, float end, float val){
  2000. end -= start;
  2001. return -end * (Mathf.Sqrt(1 - val * val) - 1) + start;
  2002. }
  2003. public static float easeOutCirc(float start, float end, float val){
  2004. val--;
  2005. end -= start;
  2006. return end * Mathf.Sqrt(1 - val * val) + start;
  2007. }
  2008. public static float easeInOutCirc(float start, float end, float val){
  2009. val /= .5f;
  2010. end -= start;
  2011. if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start;
  2012. val -= 2;
  2013. return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start;
  2014. }
  2015. public static float easeInBounce(float start, float end, float val){
  2016. end -= start;
  2017. float d = 1f;
  2018. return end - easeOutBounce(0, end, d-val) + start;
  2019. }
  2020. public static float easeOutBounce(float start, float end, float val){
  2021. val /= 1f;
  2022. end -= start;
  2023. if (val < (1 / 2.75f)){
  2024. return end * (7.5625f * val * val) + start;
  2025. }else if (val < (2 / 2.75f)){
  2026. val -= (1.5f / 2.75f);
  2027. return end * (7.5625f * (val) * val + .75f) + start;
  2028. }else if (val < (2.5 / 2.75)){
  2029. val -= (2.25f / 2.75f);
  2030. return end * (7.5625f * (val) * val + .9375f) + start;
  2031. }else{
  2032. val -= (2.625f / 2.75f);
  2033. return end * (7.5625f * (val) * val + .984375f) + start;
  2034. }
  2035. }
  2036. public static float easeInOutBounce(float start, float end, float val){
  2037. end -= start;
  2038. float d= 1f;
  2039. if (val < d/2) return easeInBounce(0, end, val*2) * 0.5f + start;
  2040. else return easeOutBounce(0, end, val*2-d) * 0.5f + end*0.5f + start;
  2041. }
  2042. public static float easeInBack(float start, float end, float val, float overshoot = 1.0f){
  2043. end -= start;
  2044. val /= 1;
  2045. float s= 1.70158f * overshoot;
  2046. return end * (val) * val * ((s + 1) * val - s) + start;
  2047. }
  2048. public static float easeOutBack(float start, float end, float val, float overshoot = 1.0f){
  2049. float s = 1.70158f * overshoot;
  2050. end -= start;
  2051. val = (val / 1) - 1;
  2052. return end * ((val) * val * ((s + 1) * val + s) + 1) + start;
  2053. }
  2054. public static float easeInOutBack(float start, float end, float val, float overshoot = 1.0f){
  2055. float s = 1.70158f * overshoot;
  2056. end -= start;
  2057. val /= .5f;
  2058. if ((val) < 1){
  2059. s *= (1.525f) * overshoot;
  2060. return end / 2 * (val * val * (((s) + 1) * val - s)) + start;
  2061. }
  2062. val -= 2;
  2063. s *= (1.525f) * overshoot;
  2064. return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start;
  2065. }
  2066. public static float easeInElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){
  2067. end -= start;
  2068. float p = period;
  2069. float s = 0f;
  2070. float a = 0f;
  2071. if (val == 0f) return start;
  2072. if (val == 1f) return start + end;
  2073. if (a == 0f || a < Mathf.Abs(end)){
  2074. a = end;
  2075. s = p / 4f;
  2076. }else{
  2077. s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
  2078. }
  2079. if(overshoot>1f && val>0.6f )
  2080. overshoot = 1f + ((1f-val) / 0.4f * (overshoot-1f));
  2081. // Debug.Log("ease in elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
  2082. val = val-1f;
  2083. return start-(a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
  2084. }
  2085. public static float easeOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){
  2086. end -= start;
  2087. float p = period;
  2088. float s = 0f;
  2089. float a = 0f;
  2090. if (val == 0f) return start;
  2091. // Debug.Log("ease out elastic val:"+val+" a:"+a);
  2092. if (val == 1f) return start + end;
  2093. if (a == 0f || a < Mathf.Abs(end)){
  2094. a = end;
  2095. s = p / 4f;
  2096. }else{
  2097. s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
  2098. }
  2099. if(overshoot>1f && val<0.4f )
  2100. overshoot = 1f + (val / 0.4f * (overshoot-1f));
  2101. // Debug.Log("ease out elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
  2102. return start + end + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * overshoot;
  2103. }
  2104. public static float easeInOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f)
  2105. {
  2106. end -= start;
  2107. float p = period;
  2108. float s = 0f;
  2109. float a = 0f;
  2110. if (val == 0f) return start;
  2111. val = val / (1f/2f);
  2112. if (val == 2f) return start + end;
  2113. if (a == 0f || a < Mathf.Abs(end)){
  2114. a = end;
  2115. s = p / 4f;
  2116. }else{
  2117. s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
  2118. }
  2119. if(overshoot>1f){
  2120. if( val<0.2f ){
  2121. overshoot = 1f + (val / 0.2f * (overshoot-1f));
  2122. }else if( val > 0.8f ){
  2123. overshoot = 1f + ((1f-val) / 0.2f * (overshoot-1f));
  2124. }
  2125. }
  2126. if (val < 1f){
  2127. val = val-1f;
  2128. return start - 0.5f * (a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
  2129. }
  2130. val = val-1f;
  2131. return end + start + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * 0.5f * overshoot;
  2132. }
  2133. // LeanTween Listening/Dispatch
  2134. private static System.Action<LTEvent>[] eventListeners;
  2135. private static GameObject[] goListeners;
  2136. private static int eventsMaxSearch = 0;
  2137. public static int EVENTS_MAX = 10;
  2138. public static int LISTENERS_MAX = 10;
  2139. private static int INIT_LISTENERS_MAX = LISTENERS_MAX;
  2140. public static void addListener( int eventId, System.Action<LTEvent> callback ){
  2141. addListener(tweenEmpty, eventId, callback);
  2142. }
  2143. /**
  2144. * Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called
  2145. *
  2146. * @method LeanTween.addListener
  2147. * @param {GameObject} caller:GameObject the gameObject the listener is attached to
  2148. * @param {int} eventId:int a unique int that describes the event (best to use an enum)
  2149. * @param {System.Action<LTEvent>} callback:System.Action<LTEvent> the method to call when the event has been dispatched
  2150. * @example
  2151. * LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);<br />
  2152. * <br />
  2153. * void jumpUp( LTEvent e ){ Debug.Log("jump!"); }<br />
  2154. */
  2155. public static void addListener( GameObject caller, int eventId, System.Action<LTEvent> callback ){
  2156. if(eventListeners==null){
  2157. INIT_LISTENERS_MAX = LISTENERS_MAX;
  2158. eventListeners = new System.Action<LTEvent>[ EVENTS_MAX * LISTENERS_MAX ];
  2159. goListeners = new GameObject[ EVENTS_MAX * LISTENERS_MAX ];
  2160. }
  2161. // Debug.Log("searching for an empty space for:"+caller + " eventid:"+event);
  2162. for(i = 0; i < INIT_LISTENERS_MAX; i++){
  2163. int point = eventId*INIT_LISTENERS_MAX + i;
  2164. if(goListeners[ point ]==null || eventListeners[ point ]==null){
  2165. eventListeners[ point ] = callback;
  2166. goListeners[ point ] = caller;
  2167. if(i>=eventsMaxSearch)
  2168. eventsMaxSearch = i+1;
  2169. // Debug.Log("adding event for:"+caller.name);
  2170. return;
  2171. }
  2172. #if UNITY_FLASH
  2173. if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback)){
  2174. // Debug.Log("This event is already being listened for.");
  2175. return;
  2176. }
  2177. #else
  2178. if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback)){
  2179. // Debug.Log("This event is already being listened for.");
  2180. return;
  2181. }
  2182. #endif
  2183. }
  2184. Debug.LogError("You ran out of areas to add listeners, consider increasing LISTENERS_MAX, ex: LeanTween.LISTENERS_MAX = "+(LISTENERS_MAX*2));
  2185. }
  2186. public static bool removeListener( int eventId, System.Action<LTEvent> callback ){
  2187. return removeListener( tweenEmpty, eventId, callback);
  2188. }
  2189. public static bool removeListener( int eventId ){
  2190. int point = eventId*INIT_LISTENERS_MAX + i;
  2191. eventListeners[ point ] = null;
  2192. goListeners[ point ] = null;
  2193. return true;
  2194. }
  2195. /**
  2196. * Remove an event listener you have added
  2197. * @method LeanTween.removeListener
  2198. * @param {GameObject} caller:GameObject the gameObject the listener is attached to
  2199. * @param {int} eventId:int a unique int that describes the event (best to use an enum)
  2200. * @param {System.Action<LTEvent>} callback:System.Action<LTEvent> the method that was specified to call when the event has been dispatched
  2201. * @example
  2202. * LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);<br />
  2203. * <br />
  2204. * void jumpUp( LTEvent e ){ }<br />
  2205. */
  2206. public static bool removeListener( GameObject caller, int eventId, System.Action<LTEvent> callback ){
  2207. for(i = 0; i < eventsMaxSearch; i++){
  2208. int point = eventId*INIT_LISTENERS_MAX + i;
  2209. #if UNITY_FLASH
  2210. if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback) ){
  2211. #else
  2212. if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback) ){
  2213. #endif
  2214. eventListeners[ point ] = null;
  2215. goListeners[ point ] = null;
  2216. return true;
  2217. }
  2218. }
  2219. return false;
  2220. }
  2221. /**
  2222. * Tell the added listeners that you are dispatching the event
  2223. * @method LeanTween.dispatchEvent
  2224. * @param {int} eventId:int a unique int that describes the event (best to use an enum)
  2225. * @example
  2226. * LeanTween.dispatchEvent( (int)MyEvents.JUMP );<br />
  2227. */
  2228. public static void dispatchEvent( int eventId ){
  2229. dispatchEvent( eventId, null);
  2230. }
  2231. /**
  2232. * Tell the added listeners that you are dispatching the event
  2233. * @method LeanTween.dispatchEvent
  2234. * @param {int} eventId:int a unique int that describes the event (best to use an enum)
  2235. * @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object
  2236. * @example
  2237. * LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );<br />
  2238. * <br />
  2239. * void jumpUp( LTEvent e ){<br />
  2240. * &#160; Transform tran = (Transform)e.data;<br />
  2241. * }<br />
  2242. */
  2243. public static void dispatchEvent( int eventId, object data ){
  2244. for(int k = 0; k < eventsMaxSearch; k++){
  2245. int point = eventId*INIT_LISTENERS_MAX + k;
  2246. if(eventListeners[ point ]!=null){
  2247. if(goListeners[point]){
  2248. eventListeners[ point ]( new LTEvent(eventId, data) );
  2249. }else{
  2250. eventListeners[ point ] = null;
  2251. }
  2252. }
  2253. }
  2254. }
  2255. } // End LeanTween class
  2256. public class LTUtility {
  2257. public static Vector3[] reverse( Vector3[] arr ){
  2258. int length = arr.Length;
  2259. int left = 0;
  2260. int right = length - 1;
  2261. for (; left < right; left += 1, right -= 1){
  2262. Vector3 temporary = arr[left];
  2263. arr[left] = arr[right];
  2264. arr[right] = temporary;
  2265. }
  2266. return arr;
  2267. }
  2268. }
  2269. public class LTBezier {
  2270. public float length;
  2271. private Vector3 a;
  2272. private Vector3 aa;
  2273. private Vector3 bb;
  2274. private Vector3 cc;
  2275. private float len;
  2276. private float[] arcLengths;
  2277. public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision){
  2278. this.a = a;
  2279. aa = (-a + 3*(b-c) + d);
  2280. bb = 3*(a+c) - 6*b;
  2281. cc = 3*(b-a);
  2282. this.len = 1.0f / precision;
  2283. arcLengths = new float[(int)this.len + (int)1];
  2284. arcLengths[0] = 0;
  2285. Vector3 ov = a;
  2286. Vector3 v;
  2287. float clen = 0.0f;
  2288. for(int i = 1; i <= this.len; i++) {
  2289. v = bezierPoint(i * precision);
  2290. clen += (ov - v).magnitude;
  2291. this.arcLengths[i] = clen;
  2292. ov = v;
  2293. }
  2294. this.length = clen;
  2295. }
  2296. private float map(float u) {
  2297. float targetLength = u * this.arcLengths[(int)this.len];
  2298. int low = 0;
  2299. int high = (int)this.len;
  2300. int index = 0;
  2301. while (low < high) {
  2302. index = low + ((int)((high - low) / 2.0f) | 0);
  2303. if (this.arcLengths[index] < targetLength) {
  2304. low = index + 1;
  2305. } else {
  2306. high = index;
  2307. }
  2308. }
  2309. if(this.arcLengths[index] > targetLength)
  2310. index--;
  2311. if(index<0)
  2312. index = 0;
  2313. return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len;
  2314. }
  2315. private Vector3 bezierPoint(float t){
  2316. return ((aa* t + (bb))* t + cc)* t + a;
  2317. }
  2318. public Vector3 point(float t){
  2319. return bezierPoint( map(t) );
  2320. }
  2321. }
  2322. /**
  2323. * Manually animate along a bezier path with this class
  2324. * @class LTBezierPath
  2325. * @constructor
  2326. * @param {Vector3 Array} pts A set of points that define one or many bezier paths (the paths should be passed in multiples of 4, which correspond to each individual bezier curve)<br />
  2327. * It goes in the order: <strong>startPoint</strong>,endControl,startControl,<strong>endPoint</strong> - <strong>Note:</strong> the control for the end and start are reversed! This is just a *quirk* of the API.<br />
  2328. * <img src="http://dentedpixel.com/assets/LTBezierExplanation.gif" width="413" height="196" style="margin-top:10px" />
  2329. * @example
  2330. * LTBezierPath ltPath = new LTBezierPath( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(1f,0f,0f), new Vector3(1f,0f,0f), new Vector3(1f,1f,0f)} );<br /><br />
  2331. * LeanTween.move(lt, ltPath.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate <br />
  2332. * Vector3 pt = ltPath.point( 0.6f ); // retrieve a point along the path
  2333. */
  2334. public class LTBezierPath {
  2335. public Vector3[] pts;
  2336. public float length;
  2337. public bool orientToPath;
  2338. public bool orientToPath2d;
  2339. private LTBezier[] beziers;
  2340. private float[] lengthRatio;
  2341. private int currentBezier=0,previousBezier=0;
  2342. public LTBezierPath(){ }
  2343. public LTBezierPath( Vector3[] pts_ ){
  2344. setPoints( pts_ );
  2345. }
  2346. public void setPoints( Vector3[] pts_ ){
  2347. if(pts_.Length<4)
  2348. LeanTween.logError( "LeanTween - When passing values for a vector path, you must pass four or more values!" );
  2349. if(pts_.Length%4!=0)
  2350. LeanTween.logError( "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..." );
  2351. pts = pts_;
  2352. int k = 0;
  2353. beziers = new LTBezier[ pts.Length / 4 ];
  2354. lengthRatio = new float[ beziers.Length ];
  2355. int i;
  2356. length = 0;
  2357. for(i = 0; i < pts.Length; i+=4){
  2358. beziers[k] = new LTBezier(pts[i+0],pts[i+2],pts[i+1],pts[i+3],0.05f);
  2359. length += beziers[k].length;
  2360. k++;
  2361. }
  2362. // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers);
  2363. for(i = 0; i < beziers.Length; i++){
  2364. lengthRatio[i] = beziers[i].length / length;
  2365. }
  2366. }
  2367. /**
  2368. * @property {float} distance distance of the path (in unity units)
  2369. */
  2370. public float distance{
  2371. get{
  2372. return length;
  2373. }
  2374. }
  2375. /**
  2376. * Retrieve a point along a path <summary>Move a GameObject to a certain location</summary>
  2377. *
  2378. * @method point
  2379. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2380. * @return {Vector3} Vector3 position of the point along the path
  2381. * @example
  2382. * transform.position = ltPath.point( 0.6f );
  2383. */
  2384. public Vector3 point( float ratio ){
  2385. float added = 0.0f;
  2386. for(int i = 0; i < lengthRatio.Length; i++){
  2387. added += lengthRatio[i];
  2388. if(added >= ratio)
  2389. return beziers[i].point( (ratio-(added-lengthRatio[i])) / lengthRatio[i] );
  2390. }
  2391. return beziers[lengthRatio.Length-1].point( 1.0f );
  2392. }
  2393. public void place2d( Transform transform, float ratio ){
  2394. transform.position = point( ratio );
  2395. ratio += 0.001f;
  2396. if(ratio<=1.0f){
  2397. Vector3 v3Dir = point( ratio ) - transform.position;
  2398. float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
  2399. transform.eulerAngles = new Vector3(0, 0, angle);
  2400. }
  2401. }
  2402. public void placeLocal2d( Transform transform, float ratio ){
  2403. transform.localPosition = point( ratio );
  2404. ratio += 0.001f;
  2405. if(ratio<=1.0f){
  2406. Vector3 v3Dir = point( ratio ) - transform.localPosition;
  2407. float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
  2408. transform.localEulerAngles = new Vector3(0, 0, angle);
  2409. }
  2410. }
  2411. /**
  2412. * Place an object along a certain point on the path (facing the direction perpendicular to the path) <summary>Move a GameObject to a certain location</summary>
  2413. *
  2414. * @method place
  2415. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2416. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2417. * @example
  2418. * ltPath.place( transform, 0.6f );
  2419. */
  2420. public void place( Transform transform, float ratio ){
  2421. place( transform, ratio, Vector3.up );
  2422. }
  2423. /**
  2424. * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path <summary>Move a GameObject to a certain location</summary>
  2425. *
  2426. * @method place
  2427. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2428. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2429. * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
  2430. * @example
  2431. * ltPath.place( transform, 0.6f, Vector3.left );
  2432. */
  2433. public void place( Transform transform, float ratio, Vector3 worldUp ){
  2434. transform.position = point( ratio );
  2435. ratio += 0.001f;
  2436. if(ratio<=1.0f)
  2437. transform.LookAt( point( ratio ), worldUp );
  2438. }
  2439. /**
  2440. * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space <summary>Move a GameObject to a certain location</summary>
  2441. *
  2442. * @method placeLocal
  2443. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2444. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2445. * @example
  2446. * ltPath.placeLocal( transform, 0.6f );
  2447. */
  2448. public void placeLocal( Transform transform, float ratio ){
  2449. placeLocal( transform, ratio, Vector3.up );
  2450. }
  2451. /**
  2452. * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space <summary>Move a GameObject to a certain location</summary>
  2453. *
  2454. * @method placeLocal
  2455. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2456. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2457. * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
  2458. * @example
  2459. * ltPath.placeLocal( transform, 0.6f, Vector3.left );
  2460. */
  2461. public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){
  2462. // Debug.Log("place ratio:" + ratio + " greater:"+(ratio>1f));
  2463. ratio = Mathf.Clamp01(ratio);
  2464. transform.localPosition = point( ratio );
  2465. // Debug.Log("ratio:" + ratio + " +:" + (ratio + 0.001f));
  2466. ratio = Mathf.Clamp01(ratio + 0.001f);
  2467. if(ratio<=1.0f)
  2468. transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp );
  2469. }
  2470. public void gizmoDraw(float t = -1.0f)
  2471. {
  2472. Vector3 prevPt = point(0);
  2473. for (int i = 1; i <= 120; i++)
  2474. {
  2475. float pm = (float)i / 120f;
  2476. Vector3 currPt2 = point(pm);
  2477. //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
  2478. Gizmos.color = (previousBezier == currentBezier) ? Color.magenta : Color.grey;
  2479. Gizmos.DrawLine(currPt2, prevPt);
  2480. prevPt = currPt2;
  2481. previousBezier = currentBezier;
  2482. }
  2483. }
  2484. }
  2485. /**
  2486. * Animate along a set of points that need to be in the format: controlPoint, point1, point2.... pointLast, endControlPoint <summary>Move a GameObject to a certain location</summary>
  2487. * @class LTSpline
  2488. * @constructor
  2489. * @param {Vector3 Array} pts A set of points that define the points the path will pass through (starting with starting control point, and ending with a control point)<br />
  2490. <i><strong>Note:</strong> The first and last item just define the angle of the end points, they are not actually used in the spline path itself. If you do not care about the angle you can jus set the first two items and last two items as the same value.</i>
  2491. * @example
  2492. * LTSpline ltSpline = new LTSpline( new Vector3[] { new Vector3(0f,0f,0f),new Vector3(0f,0f,0f), new Vector3(0f,0.5f,0f), new Vector3(1f,1f,0f), new Vector3(1f,1f,0f)} );<br /><br />
  2493. * LeanTween.moveSpline(lt, ltSpline.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate <br />
  2494. * Vector3 pt = ltSpline.point( 0.6f ); // retrieve a point along the path
  2495. */
  2496. [System.Serializable]
  2497. public class LTSpline {
  2498. public static int DISTANCE_COUNT = 3; // increase for a more accurate constant speed
  2499. public static int SUBLINE_COUNT = 20; // increase for a more accurate smoothing of the curves into lines
  2500. /**
  2501. * @property {float} distance distance of the spline (in unity units)
  2502. */
  2503. public float distance = 0f;
  2504. public bool constantSpeed = true;
  2505. public Vector3[] pts;
  2506. [System.NonSerialized]
  2507. public Vector3[] ptsAdj;
  2508. public int ptsAdjLength;
  2509. public bool orientToPath;
  2510. public bool orientToPath2d;
  2511. private int numSections;
  2512. private int currPt;
  2513. public LTSpline( Vector3[] pts ){
  2514. init( pts, true);
  2515. }
  2516. public LTSpline( Vector3[] pts, bool constantSpeed ) {
  2517. this.constantSpeed = constantSpeed;
  2518. init(pts, constantSpeed);
  2519. }
  2520. private void init( Vector3[] pts, bool constantSpeed){
  2521. if(pts.Length<4){
  2522. LeanTween.logError( "LeanTween - When passing values for a spline path, you must pass four or more values!" );
  2523. return;
  2524. }
  2525. this.pts = new Vector3[pts.Length];
  2526. System.Array.Copy(pts, this.pts, pts.Length);
  2527. numSections = pts.Length - 3;
  2528. float minSegment = float.PositiveInfinity;
  2529. Vector3 earlierPoint = this.pts[1];
  2530. float totalDistance = 0f;
  2531. for(int i=1; i < this.pts.Length-1; i++){
  2532. // float pointDistance = (this.pts[i]-earlierPoint).sqrMagnitude;
  2533. float pointDistance = Vector3.Distance(this.pts[i], earlierPoint);
  2534. //Debug.Log("pointDist:"+pointDistance);
  2535. if(pointDistance < minSegment){
  2536. minSegment = pointDistance;
  2537. }
  2538. totalDistance += pointDistance;
  2539. }
  2540. if(constantSpeed){
  2541. minSegment = totalDistance / (numSections*SUBLINE_COUNT);
  2542. //Debug.Log("minSegment:"+minSegment+" numSections:"+numSections);
  2543. float minPrecision = minSegment / SUBLINE_COUNT; // number of subdivisions in each segment
  2544. int precision = (int)Mathf.Ceil(totalDistance / minPrecision) * DISTANCE_COUNT;
  2545. // Debug.Log("precision:"+precision);
  2546. if(precision<=1) // precision has to be greater than one
  2547. precision = 2;
  2548. ptsAdj = new Vector3[ precision ];
  2549. earlierPoint = interp( 0f );
  2550. int num = 1;
  2551. ptsAdj[0] = earlierPoint;
  2552. distance = 0f;
  2553. for(int i = 0; i < precision + 1; i++){
  2554. float fract = ((float)(i)) / precision;
  2555. // Debug.Log("fract:"+fract);
  2556. Vector3 point = interp( fract );
  2557. float dist = Vector3.Distance(point, earlierPoint);
  2558. // float dist = (point-earlierPoint).sqrMagnitude;
  2559. if(dist>=minPrecision || fract>=1.0f){
  2560. ptsAdj[num] = point;
  2561. distance += dist; // only add it to the total distance once we know we are adding it as an adjusted point
  2562. earlierPoint = point;
  2563. // Debug.Log("fract:"+fract+" point:"+point);
  2564. num++;
  2565. }
  2566. }
  2567. // make sure there is a point at the very end
  2568. /*num++;
  2569. Vector3 endPoint = interp( 1f );
  2570. ptsAdj[num] = endPoint;*/
  2571. // Debug.Log("fract 1f endPoint:"+endPoint);
  2572. ptsAdjLength = num;
  2573. }
  2574. // Debug.Log("map 1f:"+map(1f)+" end:"+ptsAdj[ ptsAdjLength-1 ]);
  2575. // Debug.Log("ptsAdjLength:"+ptsAdjLength+" minPrecision:"+minPrecision+" precision:"+precision);
  2576. }
  2577. public Vector3 map( float u ){
  2578. if(u>=1f)
  2579. return pts[ pts.Length - 2];
  2580. float t = u * (ptsAdjLength-1);
  2581. int first = (int)Mathf.Floor( t );
  2582. int next = (int)Mathf.Ceil( t );
  2583. if(first<0)
  2584. first = 0;
  2585. Vector3 val = ptsAdj[ first ];
  2586. Vector3 nextVal = ptsAdj[ next ];
  2587. float diff = t - first;
  2588. // Debug.Log("u:"+u+" val:"+val +" nextVal:"+nextVal+" diff:"+diff+" first:"+first+" next:"+next);
  2589. val = val + (nextVal - val) * diff;
  2590. return val;
  2591. }
  2592. public Vector3 interp(float t) {
  2593. currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
  2594. float u = t * (float) numSections - (float) currPt;
  2595. //Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length );
  2596. Vector3 a = pts[currPt];
  2597. Vector3 b = pts[currPt + 1];
  2598. Vector3 c = pts[currPt + 2];
  2599. Vector3 d = pts[currPt + 3];
  2600. Vector3 val = (.5f * (
  2601. (-a + 3f * b - 3f * c + d) * (u * u * u)
  2602. + (2f * a - 5f * b + 4f * c - d) * (u * u)
  2603. + (-a + c) * u
  2604. + 2f * b));
  2605. // Debug.Log("currPt:"+currPt+" t:"+t+" val.x"+val.x+" y:"+val.y+" z:"+val.z);
  2606. return val;
  2607. }
  2608. /**
  2609. * Retrieve a point along a path <summary>Move a GameObject to a certain location</summary>
  2610. *
  2611. * @method ratioAtPoint
  2612. * @param {Vector3} point:Vector3 given a current location it makes the best approximiation of where it is along the path ratio-wise (0-1)
  2613. * @return {float} float of ratio along the path
  2614. * @example
  2615. * ratioIter = ltSpline.ratioAtPoint( transform.position );
  2616. */
  2617. public float ratioAtPoint( Vector3 pt ){
  2618. float closestDist = float.MaxValue;
  2619. int closestI = 0;
  2620. for (int i = 0; i < ptsAdjLength; i++) {
  2621. float dist = Vector3.Distance(pt, ptsAdj[i]);
  2622. // Debug.Log("i:"+i+" dist:"+dist);
  2623. if(dist<closestDist){
  2624. closestDist = dist;
  2625. closestI = i;
  2626. }
  2627. }
  2628. // Debug.Log("closestI:"+closestI+" ptsAdjLength:"+ptsAdjLength);
  2629. return (float) closestI / (float)(ptsAdjLength-1);
  2630. }
  2631. /**
  2632. * Retrieve a point along a path <summary>Move a GameObject to a certain location</summary>
  2633. *
  2634. * @method point
  2635. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2636. * @return {Vector3} Vector3 position of the point along the path
  2637. * @example
  2638. * transform.position = ltSpline.point( 0.6f );
  2639. */
  2640. public Vector3 point( float ratio ){
  2641. float t = ratio>1f?1f:ratio;
  2642. return constantSpeed ? map(t) : interp(t);
  2643. }
  2644. public void place2d( Transform transform, float ratio ){
  2645. transform.position = point( ratio );
  2646. ratio += 0.001f;
  2647. if(ratio<=1.0f){
  2648. Vector3 v3Dir = point( ratio ) - transform.position;
  2649. float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
  2650. transform.eulerAngles = new Vector3(0, 0, angle);
  2651. }
  2652. }
  2653. public void placeLocal2d( Transform transform, float ratio ){
  2654. Transform trans = transform.parent;
  2655. if(trans==null){ // this has no parent, just do a regular transform
  2656. place2d(transform, ratio);
  2657. return;
  2658. }
  2659. transform.localPosition = point( ratio );
  2660. ratio += 0.001f;
  2661. if(ratio<=1.0f){
  2662. Vector3 ptAhead = point( ratio );//trans.TransformPoint( );
  2663. Vector3 v3Dir = ptAhead - transform.localPosition;
  2664. float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
  2665. transform.localEulerAngles = new Vector3(0, 0, angle);
  2666. }
  2667. }
  2668. /**
  2669. * Place an object along a certain point on the path (facing the direction perpendicular to the path) <summary>Move a GameObject to a certain location</summary>
  2670. *
  2671. * @method place
  2672. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2673. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2674. * @example
  2675. * ltPath.place( transform, 0.6f );
  2676. */
  2677. public void place( Transform transform, float ratio ){
  2678. place(transform, ratio, Vector3.up);
  2679. }
  2680. /**
  2681. * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path <summary>Move a GameObject to a certain location</summary>
  2682. *
  2683. * @method place
  2684. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2685. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2686. * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
  2687. * @example
  2688. * ltPath.place( transform, 0.6f, Vector3.left );
  2689. */
  2690. public void place( Transform transform, float ratio, Vector3 worldUp ){
  2691. // ratio = Mathf.Repeat(ratio, 1.0f); // make sure ratio is always between 0-1
  2692. transform.position = point( ratio );
  2693. ratio += 0.001f;
  2694. if(ratio<=1.0f)
  2695. transform.LookAt( point( ratio ), worldUp );
  2696. }
  2697. /**
  2698. * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space <summary>Move a GameObject to a certain location</summary>
  2699. *
  2700. * @method placeLocal
  2701. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2702. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2703. * @example
  2704. * ltPath.placeLocal( transform, 0.6f );
  2705. */
  2706. public void placeLocal( Transform transform, float ratio ){
  2707. placeLocal( transform, ratio, Vector3.up );
  2708. }
  2709. /**
  2710. * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path - Local Space, not world-space <summary>Move a GameObject to a certain location</summary>
  2711. *
  2712. * @method placeLocal
  2713. * @param {Transform} transform:Transform the transform of the object you wish to place along the path
  2714. * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
  2715. * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
  2716. * @example
  2717. * ltPath.placeLocal( transform, 0.6f, Vector3.left );
  2718. */
  2719. public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){
  2720. transform.localPosition = point( ratio );
  2721. ratio += 0.001f;
  2722. if(ratio<=1.0f)
  2723. transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp );
  2724. }
  2725. public void gizmoDraw(float t = -1.0f) {
  2726. if(ptsAdj==null || ptsAdj.Length<=0)
  2727. return;
  2728. Vector3 prevPt = ptsAdj[0];
  2729. for (int i = 0; i < ptsAdjLength; i++) {
  2730. Vector3 currPt2 = ptsAdj[i];
  2731. // Debug.Log("currPt2:"+currPt2);
  2732. //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
  2733. Gizmos.DrawLine(prevPt, currPt2);
  2734. prevPt = currPt2;
  2735. }
  2736. }
  2737. public void drawGizmo( Color color ) {
  2738. if( this.ptsAdjLength>=4){
  2739. Vector3 prevPt = this.ptsAdj[0];
  2740. Color colorBefore = Gizmos.color;
  2741. Gizmos.color = color;
  2742. for (int i = 0; i < this.ptsAdjLength; i++) {
  2743. Vector3 currPt2 = this.ptsAdj[i];
  2744. // Debug.Log("currPt2:"+currPt2);
  2745. Gizmos.DrawLine(prevPt, currPt2);
  2746. prevPt = currPt2;
  2747. }
  2748. Gizmos.color = colorBefore;
  2749. }
  2750. }
  2751. public static void drawGizmo(Transform[] arr, Color color) {
  2752. if(arr.Length>=4){
  2753. Vector3[] vec3s = new Vector3[arr.Length];
  2754. for(int i = 0; i < arr.Length; i++){
  2755. vec3s[i] = arr[i].position;
  2756. }
  2757. LTSpline spline = new LTSpline(vec3s);
  2758. Vector3 prevPt = spline.ptsAdj[0];
  2759. Color colorBefore = Gizmos.color;
  2760. Gizmos.color = color;
  2761. for (int i = 0; i < spline.ptsAdjLength; i++) {
  2762. Vector3 currPt2 = spline.ptsAdj[i];
  2763. // Debug.Log("currPt2:"+currPt2);
  2764. Gizmos.DrawLine(prevPt, currPt2);
  2765. prevPt = currPt2;
  2766. }
  2767. Gizmos.color = colorBefore;
  2768. }
  2769. }
  2770. public static void drawLine(Transform[] arr, float width, Color color) {
  2771. if(arr.Length>=4){
  2772. }
  2773. }
  2774. /*public Vector3 Velocity(float t) {
  2775. t = map( t );
  2776. int numSections = pts.Length - 3;
  2777. int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
  2778. float u = t * (float) numSections - (float) currPt;
  2779. Vector3 a = pts[currPt];
  2780. Vector3 b = pts[currPt + 1];
  2781. Vector3 c = pts[currPt + 2];
  2782. Vector3 d = pts[currPt + 3];
  2783. return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u)
  2784. + (2f * a -5f * b + 4f * c - d) * u
  2785. + .5f * c - .5f * a;
  2786. }*/
  2787. public void drawLinesGLLines(Material outlineMaterial, Color color, float width){
  2788. GL.PushMatrix();
  2789. outlineMaterial.SetPass(0);
  2790. GL.LoadPixelMatrix();
  2791. GL.Begin(GL.LINES);
  2792. GL.Color(color);
  2793. if (constantSpeed) {
  2794. if (this.ptsAdjLength >= 4) {
  2795. Vector3 prevPt = this.ptsAdj[0];
  2796. for (int i = 0; i < this.ptsAdjLength; i++) {
  2797. Vector3 currPt2 = this.ptsAdj[i];
  2798. GL.Vertex(prevPt);
  2799. GL.Vertex(currPt2);
  2800. prevPt = currPt2;
  2801. }
  2802. }
  2803. } else {
  2804. if (this.pts.Length >= 4) {
  2805. Vector3 prevPt = this.pts[0];
  2806. float split = 1f / ((float)this.pts.Length * 10f);
  2807. float iter = 0f;
  2808. while (iter < 1f) {
  2809. float at = iter / 1f;
  2810. Vector3 currPt2 = interp(at);
  2811. // Debug.Log("currPt2:"+currPt2);
  2812. GL.Vertex(prevPt);
  2813. GL.Vertex(currPt2);
  2814. prevPt = currPt2;
  2815. iter += split;
  2816. }
  2817. }
  2818. }
  2819. GL.End();
  2820. GL.PopMatrix();
  2821. }
  2822. public Vector3[] generateVectors(){
  2823. if (this.pts.Length >= 4) {
  2824. List<Vector3> meshPoints = new List<Vector3>();
  2825. Vector3 prevPt = this.pts[0];
  2826. meshPoints.Add(prevPt);
  2827. float split = 1f / ((float)this.pts.Length * 10f);
  2828. float iter = 0f;
  2829. while (iter < 1f) {
  2830. float at = iter / 1f;
  2831. Vector3 currPt2 = interp(at);
  2832. // Debug.Log("currPt2:"+currPt2);
  2833. // GL.Vertex(prevPt);
  2834. // GL.Vertex(currPt2);
  2835. meshPoints.Add(currPt2);
  2836. // prevPt = currPt2;
  2837. iter += split;
  2838. }
  2839. meshPoints.ToArray();
  2840. }
  2841. return null;
  2842. }
  2843. }
  2844. /**
  2845. * Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method<br /><br />
  2846. * <strong>Example Javascript: </strong><br />var bRect:LTRect = new LTRect( 0, 0, 100, 50 );<br />
  2847. * LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );<br />
  2848. * function OnGUI(){<br />
  2849. * &#160; if(GUI.Button(bRect.rect, "Scale")){ }<br />
  2850. * }<br />
  2851. * <br />
  2852. * <strong>Example C#: </strong> <br />
  2853. * LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );<br />
  2854. * LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f );<br />
  2855. * void OnGUI(){<br />
  2856. * &#160; if(GUI.Button(bRect.rect, "Scale")){ }<br />
  2857. * }<br />
  2858. *
  2859. * @class LTRect
  2860. * @constructor
  2861. * @param {float} x:float X location
  2862. * @param {float} y:float Y location
  2863. * @param {float} width:float Width
  2864. * @param {float} height:float Height
  2865. * @param {float} alpha:float (Optional) initial alpha amount (0-1)
  2866. * @param {float} rotation:float (Optional) initial rotation in degrees (0-360)
  2867. */
  2868. [System.Serializable]
  2869. public class LTRect : System.Object{
  2870. /**
  2871. * Pass this value to the GUI Methods
  2872. *
  2873. * @property rect
  2874. * @type {Rect} rect:Rect Rect object that controls the positioning and size
  2875. */
  2876. public Rect _rect;
  2877. public float alpha = 1f;
  2878. public float rotation;
  2879. public Vector2 pivot;
  2880. public Vector2 margin;
  2881. public Rect relativeRect = new Rect(0f,0f,float.PositiveInfinity,float.PositiveInfinity);
  2882. public bool rotateEnabled;
  2883. [HideInInspector]
  2884. public bool rotateFinished;
  2885. public bool alphaEnabled;
  2886. public string labelStr;
  2887. public LTGUI.Element_Type type;
  2888. public GUIStyle style;
  2889. public bool useColor = false;
  2890. public Color color = Color.white;
  2891. public bool fontScaleToFit;
  2892. public bool useSimpleScale;
  2893. public bool sizeByHeight;
  2894. public Texture texture;
  2895. private int _id = -1;
  2896. [HideInInspector]
  2897. public int counter;
  2898. public static bool colorTouched;
  2899. public LTRect(){
  2900. reset();
  2901. this.rotateEnabled = this.alphaEnabled = true;
  2902. _rect = new Rect(0f,0f,1f,1f);
  2903. }
  2904. public LTRect(Rect rect){
  2905. _rect = rect;
  2906. reset();
  2907. }
  2908. public LTRect(float x, float y, float width, float height){
  2909. _rect = new Rect(x,y,width,height);
  2910. this.alpha = 1.0f;
  2911. this.rotation = 0.0f;
  2912. this.rotateEnabled = this.alphaEnabled = false;
  2913. }
  2914. public LTRect(float x, float y, float width, float height, float alpha){
  2915. _rect = new Rect(x,y,width,height);
  2916. this.alpha = alpha;
  2917. this.rotation = 0.0f;
  2918. this.rotateEnabled = this.alphaEnabled = false;
  2919. }
  2920. public LTRect(float x, float y, float width, float height, float alpha, float rotation){
  2921. _rect = new Rect(x,y,width,height);
  2922. this.alpha = alpha;
  2923. this.rotation = rotation;
  2924. this.rotateEnabled = this.alphaEnabled = false;
  2925. if(rotation!=0.0f){
  2926. this.rotateEnabled = true;
  2927. resetForRotation();
  2928. }
  2929. }
  2930. public bool hasInitiliazed{
  2931. get{
  2932. return _id!=-1;
  2933. }
  2934. }
  2935. public int id{
  2936. get{
  2937. int toId = _id | counter << 16;
  2938. /*uint backId = toId & 0xFFFF;
  2939. uint backCounter = toId >> 16;
  2940. if(_id!=backId || backCounter!=counter){
  2941. Debug.LogError("BAD CONVERSION toId:"+_id);
  2942. }*/
  2943. return toId;
  2944. }
  2945. }
  2946. public void setId( int id, int counter){
  2947. this._id = id;
  2948. this.counter = counter;
  2949. }
  2950. public void reset(){
  2951. this.alpha = 1.0f;
  2952. this.rotation = 0.0f;
  2953. this.rotateEnabled = this.alphaEnabled = false;
  2954. this.margin = Vector2.zero;
  2955. this.sizeByHeight = false;
  2956. this.useColor = false;
  2957. }
  2958. public void resetForRotation(){
  2959. Vector3 scale = new Vector3(GUI.matrix[0,0], GUI.matrix[1,1], GUI.matrix[2,2]);
  2960. if(pivot==Vector2.zero){
  2961. pivot = new Vector2((_rect.x+((_rect.width)*0.5f )) * scale.x + GUI.matrix[0,3], (_rect.y+((_rect.height)*0.5f )) * scale.y + GUI.matrix[1,3]);
  2962. }
  2963. }
  2964. public float x{
  2965. get{ return _rect.x; }
  2966. set{ _rect.x = value; }
  2967. }
  2968. public float y{
  2969. get{ return _rect.y; }
  2970. set{ _rect.y = value; }
  2971. }
  2972. public float width{
  2973. get{ return _rect.width; }
  2974. set{ _rect.width = value; }
  2975. }
  2976. public float height{
  2977. get{ return _rect.height; }
  2978. set{ _rect.height = value; }
  2979. }
  2980. public Rect rect{
  2981. get{
  2982. if(colorTouched){
  2983. colorTouched = false;
  2984. GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,1.0f);
  2985. }
  2986. if(rotateEnabled){
  2987. if(rotateFinished){
  2988. rotateFinished = false;
  2989. rotateEnabled = false;
  2990. //this.rotation = 0.0f;
  2991. pivot = Vector2.zero;
  2992. }else{
  2993. GUIUtility.RotateAroundPivot(rotation, pivot);
  2994. }
  2995. }
  2996. if(alphaEnabled){
  2997. GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,alpha);
  2998. colorTouched = true;
  2999. }
  3000. if(fontScaleToFit){
  3001. if(this.useSimpleScale){
  3002. style.fontSize = (int)(_rect.height*this.relativeRect.height);
  3003. }else{
  3004. style.fontSize = (int)_rect.height;
  3005. }
  3006. }
  3007. return _rect;
  3008. }
  3009. set{
  3010. _rect = value;
  3011. }
  3012. }
  3013. public LTRect setStyle( GUIStyle style ){
  3014. this.style = style;
  3015. return this;
  3016. }
  3017. public LTRect setFontScaleToFit( bool fontScaleToFit ){
  3018. this.fontScaleToFit = fontScaleToFit;
  3019. return this;
  3020. }
  3021. public LTRect setColor( Color color ){
  3022. this.color = color;
  3023. this.useColor = true;
  3024. return this;
  3025. }
  3026. public LTRect setAlpha( float alpha ){
  3027. this.alpha = alpha;
  3028. return this;
  3029. }
  3030. public LTRect setLabel( String str ){
  3031. this.labelStr = str;
  3032. return this;
  3033. }
  3034. public LTRect setUseSimpleScale( bool useSimpleScale, Rect relativeRect){
  3035. this.useSimpleScale = useSimpleScale;
  3036. this.relativeRect = relativeRect;
  3037. return this;
  3038. }
  3039. public LTRect setUseSimpleScale( bool useSimpleScale){
  3040. this.useSimpleScale = useSimpleScale;
  3041. this.relativeRect = new Rect(0f,0f,Screen.width,Screen.height);
  3042. return this;
  3043. }
  3044. public LTRect setSizeByHeight( bool sizeByHeight){
  3045. this.sizeByHeight = sizeByHeight;
  3046. return this;
  3047. }
  3048. public override string ToString(){
  3049. return "x:"+_rect.x+" y:"+_rect.y+" width:"+_rect.width+" height:"+_rect.height;
  3050. }
  3051. }
  3052. /**
  3053. * Object that describes the event to an event listener
  3054. * @class LTEvent
  3055. * @constructor
  3056. * @param {object} data:object Data that has been passed from the dispatchEvent method
  3057. */
  3058. public class LTEvent {
  3059. public int id;
  3060. public object data;
  3061. public LTEvent(int id, object data){
  3062. this.id = id;
  3063. this.data = data;
  3064. }
  3065. }
  3066. public class LTGUI {
  3067. public static int RECT_LEVELS = 5;
  3068. public static int RECTS_PER_LEVEL = 10;
  3069. public static int BUTTONS_MAX = 24;
  3070. private static LTRect[] levels;
  3071. private static int[] levelDepths;
  3072. private static Rect[] buttons;
  3073. private static int[] buttonLevels;
  3074. private static int[] buttonLastFrame;
  3075. private static LTRect r;
  3076. private static Color color = Color.white;
  3077. private static bool isGUIEnabled = false;
  3078. private static int global_counter = 0;
  3079. public enum Element_Type{
  3080. Texture,
  3081. Label
  3082. }
  3083. public static void init(){
  3084. if(levels==null){
  3085. levels = new LTRect[RECT_LEVELS*RECTS_PER_LEVEL];
  3086. levelDepths = new int[RECT_LEVELS];
  3087. }
  3088. }
  3089. public static void initRectCheck(){
  3090. if(buttons==null){
  3091. buttons = new Rect[BUTTONS_MAX];
  3092. buttonLevels = new int[BUTTONS_MAX];
  3093. buttonLastFrame = new int[BUTTONS_MAX];
  3094. for(int i = 0; i < buttonLevels.Length; i++){
  3095. buttonLevels[i] = -1;
  3096. }
  3097. }
  3098. }
  3099. public static void reset(){
  3100. if(isGUIEnabled){
  3101. isGUIEnabled = false;
  3102. for(int i = 0; i < levels.Length; i++){
  3103. levels[i] = null;
  3104. }
  3105. for(int i = 0; i < levelDepths.Length; i++){
  3106. levelDepths[i] = 0;
  3107. }
  3108. }
  3109. }
  3110. public static void update( int updateLevel ){
  3111. if(isGUIEnabled){
  3112. init();
  3113. if(levelDepths[updateLevel]>0){
  3114. color = GUI.color;
  3115. int baseI = updateLevel*RECTS_PER_LEVEL;
  3116. int maxLoop = baseI + levelDepths[updateLevel];// RECTS_PER_LEVEL;//;
  3117. for(int i = baseI; i < maxLoop; i++){
  3118. r = levels[i];
  3119. // Debug.Log("r:"+r+" i:"+i);
  3120. if(r!=null /*&& checkOnScreen(r.rect)*/){
  3121. //Debug.Log("label:"+r.labelStr+" textColor:"+r.style.normal.textColor);
  3122. if(r.useColor)
  3123. GUI.color = r.color;
  3124. if(r.type == Element_Type.Label){
  3125. if(r.style!=null)
  3126. GUI.skin.label = r.style;
  3127. if(r.useSimpleScale){
  3128. GUI.Label( new Rect((r.rect.x + r.margin.x + r.relativeRect.x)*r.relativeRect.width, (r.rect.y + r.margin.y + r.relativeRect.y)*r.relativeRect.height, r.rect.width*r.relativeRect.width, r.rect.height*r.relativeRect.height), r.labelStr );
  3129. }else{
  3130. GUI.Label( new Rect(r.rect.x + r.margin.x, r.rect.y + r.margin.y, r.rect.width, r.rect.height), r.labelStr );
  3131. }
  3132. }else if(r.type == Element_Type.Texture && r.texture!=null){
  3133. Vector2 size = r.useSimpleScale ? new Vector2(0f, r.rect.height*r.relativeRect.height) : new Vector2(r.rect.width, r.rect.height);
  3134. if(r.sizeByHeight){
  3135. size.x = (float)r.texture.width/(float)r.texture.height * size.y;
  3136. }
  3137. if(r.useSimpleScale){
  3138. GUI.DrawTexture( new Rect((r.rect.x + r.margin.x + r.relativeRect.x)*r.relativeRect.width, (r.rect.y + r.margin.y + r.relativeRect.y)*r.relativeRect.height, size.x, size.y), r.texture );
  3139. }else{
  3140. GUI.DrawTexture( new Rect(r.rect.x + r.margin.x, r.rect.y + r.margin.y, size.x, size.y), r.texture );
  3141. }
  3142. }
  3143. }
  3144. }
  3145. GUI.color = color;
  3146. }
  3147. }
  3148. }
  3149. public static bool checkOnScreen(Rect rect){
  3150. bool offLeft = rect.x + rect.width < 0f;
  3151. bool offRight = rect.x > Screen.width;
  3152. bool offBottom = rect.y > Screen.height;
  3153. bool offTop = rect.y + rect.height < 0f;
  3154. return !(offLeft || offRight || offBottom || offTop);
  3155. }
  3156. public static void destroy( int id ){
  3157. int backId = id & 0xFFFF;
  3158. int backCounter = id >> 16;
  3159. if(id>=0 && levels[backId]!=null && levels[backId].hasInitiliazed && levels[backId].counter==backCounter)
  3160. levels[backId] = null;
  3161. }
  3162. public static void destroyAll( int depth ){ // clears all gui elements on depth
  3163. int maxLoop = depth*RECTS_PER_LEVEL + RECTS_PER_LEVEL;
  3164. for(int i = depth*RECTS_PER_LEVEL; levels!=null && i < maxLoop; i++){
  3165. levels[i] = null;
  3166. }
  3167. }
  3168. public static LTRect label( Rect rect, string label, int depth){
  3169. return LTGUI.label(new LTRect(rect), label, depth);
  3170. }
  3171. public static LTRect label( LTRect rect, string label, int depth){
  3172. rect.type = Element_Type.Label;
  3173. rect.labelStr = label;
  3174. return element(rect, depth);
  3175. }
  3176. public static LTRect texture( Rect rect, Texture texture, int depth){
  3177. return LTGUI.texture( new LTRect(rect), texture, depth);
  3178. }
  3179. public static LTRect texture( LTRect rect, Texture texture, int depth){
  3180. rect.type = Element_Type.Texture;
  3181. rect.texture = texture;
  3182. return element(rect, depth);
  3183. }
  3184. public static LTRect element( LTRect rect, int depth){
  3185. isGUIEnabled = true;
  3186. init();
  3187. int maxLoop = depth*RECTS_PER_LEVEL + RECTS_PER_LEVEL;
  3188. int k = 0;
  3189. if(rect!=null){
  3190. destroy(rect.id);
  3191. }
  3192. if(rect.type==LTGUI.Element_Type.Label && rect.style!=null){
  3193. if(rect.style.normal.textColor.a<=0f){
  3194. Debug.LogWarning("Your GUI normal color has an alpha of zero, and will not be rendered.");
  3195. }
  3196. }
  3197. if(rect.relativeRect.width==float.PositiveInfinity){
  3198. rect.relativeRect = new Rect(0f,0f,Screen.width,Screen.height);
  3199. }
  3200. for(int i = depth*RECTS_PER_LEVEL; i < maxLoop; i++){
  3201. r = levels[i];
  3202. if(r==null){
  3203. r = rect;
  3204. r.rotateEnabled = true;
  3205. r.alphaEnabled = true;
  3206. r.setId( i, global_counter );
  3207. levels[i] = r;
  3208. // Debug.Log("k:"+k+ " maxDepth:"+levelDepths[depth]);
  3209. if(k>=levelDepths[depth]){
  3210. levelDepths[depth] = k + 1;
  3211. }
  3212. global_counter++;
  3213. return r;
  3214. }
  3215. k++;
  3216. }
  3217. Debug.LogError("You ran out of GUI Element spaces");
  3218. return null;
  3219. }
  3220. public static bool hasNoOverlap( Rect rect, int depth ){
  3221. initRectCheck();
  3222. bool hasNoOverlap = true;
  3223. bool wasAddedToList = false;
  3224. for(int i = 0; i < buttonLevels.Length; i++){
  3225. // Debug.Log("buttonLastFrame["+i+"]:"+buttonLastFrame[i]);
  3226. //Debug.Log("buttonLevels["+i+"]:"+buttonLevels[i]);
  3227. if(buttonLevels[i]>=0){
  3228. //Debug.Log("buttonLastFrame["+i+"]:"+buttonLastFrame[i]+" Time.frameCount:"+Time.frameCount);
  3229. if( buttonLastFrame[i] + 1 < Time.frameCount ){ // It has to have been visible within the current, or
  3230. buttonLevels[i] = -1;
  3231. // Debug.Log("resetting i:"+i);
  3232. }else{
  3233. //if(buttonLevels[i]>=0)
  3234. // Debug.Log("buttonLevels["+i+"]:"+buttonLevels[i]);
  3235. if(buttonLevels[i]>depth){
  3236. /*if(firstTouch().x > 0){
  3237. Debug.Log("buttons["+i+"]:"+buttons[i] + " firstTouch:");
  3238. Debug.Log(firstTouch());
  3239. Debug.Log(buttonLevels[i]);
  3240. }*/
  3241. if(pressedWithinRect( buttons[i] )){
  3242. hasNoOverlap = false; // there is an overlapping button that is higher
  3243. }
  3244. }
  3245. }
  3246. }
  3247. if(wasAddedToList==false && buttonLevels[i]<0){
  3248. wasAddedToList = true;
  3249. buttonLevels[i] = depth;
  3250. buttons[i] = rect;
  3251. buttonLastFrame[i] = Time.frameCount;
  3252. }
  3253. }
  3254. return hasNoOverlap;
  3255. }
  3256. public static bool pressedWithinRect( Rect rect ){
  3257. Vector2 vec2 = firstTouch();
  3258. if(vec2.x<0f)
  3259. return false;
  3260. float vecY = Screen.height-vec2.y;
  3261. return (vec2.x > rect.x && vec2.x < rect.x + rect.width && vecY > rect.y && vecY < rect.y + rect.height);
  3262. }
  3263. public static bool checkWithinRect(Vector2 vec2, Rect rect){
  3264. vec2.y = Screen.height-vec2.y;
  3265. return (vec2.x > rect.x && vec2.x < rect.x + rect.width && vec2.y > rect.y && vec2.y < rect.y + rect.height);
  3266. }
  3267. public static Vector2 firstTouch(){
  3268. if(Input.touchCount>0){
  3269. return Input.touches[0].position;
  3270. }else if(Input.GetMouseButton(0)){
  3271. return Input.mousePosition;
  3272. }
  3273. return new Vector2(Mathf.NegativeInfinity,Mathf.NegativeInfinity);
  3274. }
  3275. }
  3276. namespace DentedPixel { public class LeanDummy {} }
  3277. //}