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.

3615 lines
127 KiB

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