//namespace DentedPixel{
// LeanTween version 2.46 - http://dentedpixel.com/developer-diary/
//
// The MIT License (MIT)
//
// Copyright (c) 2017 Russell Savage - Dented Pixel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/*
TERMS OF USE - EASING EQUATIONS#
Open source under the BSD License.
Copyright (c)2001 Robert Penner
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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.
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.
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.
*/
/**
* Pass this to the "ease" parameter, to get a different easing behavior
* Optional Parameters are passed at the end of every method
*
* Example:
* LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
*
* You can pass the optional parameters in any order, and chain on as many as you wish!
* You can also modify this tween later, just save the unique id of the tween.
*
Example:
* int id = LeanTween.moveX(gameObject, 1f, 1f).id;
* LTDescr d = LeanTween.descr( id );
* if(d!=null){ // if the tween has already finished it will return null
* // change some parameters
* d.setOnComplete( onCompleteFunc ).setEase( LeanTweenType.easeInOutBack );
* }
*
* @class LeanTween
*/
public class LeanTween : MonoBehaviour {
public static bool throwErrors = true;
public static float tau = Mathf.PI*2.0f;
public static float PI_DIV2 = Mathf.PI / 2.0f;
private static LTSeq[] sequences;
private static LTDescr[] tweens;
private static int[] tweensFinished;
private static int[] tweensFinishedIds;
private static LTDescr tween;
private static int tweenMaxSearch = -1;
private static int maxTweens = 400;
private static int maxSequences = 400;
private static int frameRendered= -1;
private static GameObject _tweenEmpty;
public static float dtEstimated = -1f;
public static float dtManual;
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
private static float previousRealTime;
#endif
public static float dtActual;
private static uint global_counter = 0;
private static int i;
private static int j;
private static int finishedCnt;
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 ) );
public static AnimationCurve shake = new AnimationCurve( new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(0.75f, -1f), new Keyframe(1f, 0f) ) ;
public static void init(){
init(maxTweens);
}
public static int maxSearch{
get{
return tweenMaxSearch;
}
}
public static int maxSimulataneousTweens{
get {
return maxTweens;
}
}
/**
* Find out how many tweens you have animating at a given time Find out how many tweens you have animating at a given time
*
* @method LeanTween.tweensRunning
* @example
* Debug.Log("I have "+LeanTween.tweensRunning+" animating!");
*/
public static int tweensRunning{
get{
int count = 0;
for (int i = 0; i <= tweenMaxSearch; i++){
if (tweens[i].toggle){
count++;
}
}
return count;
}
}
/**
* 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. 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.
*
* @method LeanTween.init
* @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
* @example
* LeanTween.init( 800 );
*/
public static void init(int maxSimultaneousTweens ){
init(maxSimultaneousTweens, maxSequences);
}
public static void init(int maxSimultaneousTweens, int maxSimultaneousSequences){
if(tweens==null){
maxTweens = maxSimultaneousTweens;
tweens = new LTDescr[maxTweens];
tweensFinished = new int[maxTweens];
tweensFinishedIds = new int[maxTweens];
_tweenEmpty = new GameObject();
_tweenEmpty.name = "~LeanTween";
_tweenEmpty.AddComponent(typeof(LeanTween));
_tweenEmpty.isStatic = true;
#if !UNITY_EDITOR
_tweenEmpty.hideFlags = HideFlags.HideAndDontSave;
#endif
#if UNITY_EDITOR
if(Application.isPlaying)
DontDestroyOnLoad( _tweenEmpty );
#else
DontDestroyOnLoad( _tweenEmpty );
#endif
for(int i = 0; i < maxTweens; i++){
tweens[i] = new LTDescr();
}
#if UNITY_5_4_OR_NEWER
UnityEngine.SceneManagement.SceneManager.sceneLoaded += onLevelWasLoaded54;
#endif
sequences = new LTSeq[ maxSimultaneousSequences ];
for(int i = 0; i < maxSimultaneousSequences; i++){
sequences[i] = new LTSeq();
}
}
}
public static void reset(){
if(tweens!=null){
for (int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i]!=null)
tweens[i].toggle = false;
}
}
tweens = null;
Destroy(_tweenEmpty);
}
public void Update(){
LeanTween.update();
}
#if UNITY_5_4_OR_NEWER
private static void onLevelWasLoaded54( UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode ){ internalOnLevelWasLoaded( scene.buildIndex ); }
#else
public void OnLevelWasLoaded( int lvl ){ internalOnLevelWasLoaded( lvl ); }
#endif
private static void internalOnLevelWasLoaded( int lvl ){
// Debug.Log("reseting gui");
LTGUI.reset();
}
private static int maxTweenReached;
public static void update() {
if(frameRendered != Time.frameCount){ // make sure update is only called once per frame
init();
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
dtEstimated = Time.realtimeSinceStartup - previousRealTime;
if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large
dtEstimated = 0.2f;
previousRealTime = Time.realtimeSinceStartup;
#else
dtEstimated = dtEstimated<0f ? 0f : dtEstimated = Time.unscaledDeltaTime;
// Debug.Log("Time.unscaledDeltaTime:"+Time.unscaledDeltaTime);
#endif
dtActual = Time.deltaTime;
maxTweenReached = 0;
finishedCnt = 0;
// if(tweenMaxSearch>1500)
// Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
for( int i = 0; i <= tweenMaxSearch && i < maxTweens; i++){
tween = tweens[i];
// if(i==0 && tweens[i].toggle)
// Debug.Log("tweens["+i+"]"+tweens[i]);
if(tween.toggle){
maxTweenReached = i;
if (tween.updateInternal()) { // returns true if the tween is finished with it's loop
tweensFinished[finishedCnt] = i;
tweensFinishedIds[finishedCnt] = tweens[i].id;
finishedCnt++;
}
}
}
// Debug.Log("maxTweenReached:"+maxTweenReached);
tweenMaxSearch = maxTweenReached;
frameRendered = Time.frameCount;
for(int i = 0; i < finishedCnt; i++){
j = tweensFinished[i];
tween = tweens[ j ];
if (tween.id == tweensFinishedIds[i]){
// Debug.Log("removing tween:"+tween);
removeTween(j);
if(tween.hasExtraOnCompletes && tween.trans!=null)
tween.callOnCompletes();
}
}
}
}
public static void removeTween( int i, int uniqueId){ // Only removes the tween if the unique id matches Move a GameObject to a certain location
if(tweens[i].uniqueId==uniqueId){
removeTween( i );
}
}
// This method is only used internally! Do not call this from your scripts. To cancel a tween use LeanTween.cancel
public static void removeTween( int i ){
if(tweens[i].toggle){
tweens[i].toggle = false;
tweens[i].counter = uint.MaxValue;
//logError("Removing tween["+i+"]:"+tweens[i]);
if(tweens[i].destroyOnComplete){
// Debug.Log("destroying tween.type:"+tween.type+" ltRect"+(tweens[i]._optional.ltRect==null));
if(tweens[i]._optional.ltRect!=null){
// Debug.Log("destroy i:"+i+" id:"+tweens[i].ltRect.id);
LTGUI.destroy( tweens[i]._optional.ltRect.id );
}else{ // check if equal to tweenEmpty
if(tweens[i].trans!=null && tweens[i].trans.gameObject!=_tweenEmpty){
Destroy(tweens[i].trans.gameObject);
}
}
}
//tweens[i].optional = null;
startSearch = i;
//Debug.Log("start search reset:"+startSearch + " i:"+i+" tweenMaxSearch:"+tweenMaxSearch);
if(i+1>=tweenMaxSearch){
//Debug.Log("reset to zero");
startSearch = 0;
//tweenMaxSearch--;
}
}
}
public static Vector3[] add(Vector3[] a, Vector3 b){
Vector3[] c = new Vector3[ a.Length ];
for(i=0; iCancels all tweens
*
* @method LeanTween.cancelAll
* @param {bool} callComplete:bool (optional) if true, then the all onCompletes will run before canceling
* @example LeanTween.cancelAll(true);
*/
public static void cancelAll(){
cancelAll(false);
}
public static void cancelAll(bool callComplete){
init();
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].trans != null){
if (callComplete && tweens[i].optional.onComplete != null)
tweens[i].optional.onComplete();
removeTween(i);
}
}
}
/**
* Cancel all tweens that are currently targeting the gameObjectCancel all tweens that are currently targeting the gameObject
*
* @method LeanTween.cancel
* @param {GameObject} gameObject:GameObject gameObject whose tweens you wish to cancel
* @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling
* @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f);
* LeanTween.cancel( gameObject );
*/
public static void cancel( GameObject gameObject ){
cancel( gameObject, false);
}
public static void cancel( GameObject gameObject, bool callOnComplete ){
init();
Transform trans = gameObject.transform;
for(int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i].toggle && tweens[i].trans==trans){
if (callOnComplete && tweens[i].optional.onComplete != null)
tweens[i].optional.onComplete();
removeTween(i);
}
}
}
public static void cancel( RectTransform rect ){
cancel( rect.gameObject, false);
}
// public static void cancel( GameObject gameObject, int uniqueId ){
// if(uniqueId>=0){
// init();
// int backId = uniqueId & 0xFFFF;
// int backCounter = uniqueId >> 16;
// // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tweens[backId].counter + " tweens[id].type:"+tweens[backId].type);
// if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter))
// removeTween((int)backId);
// }
// }
public static void cancel( GameObject gameObject, int uniqueId, bool callOnComplete = false ){
if(uniqueId>=0){
init();
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
// Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" counter:"+backCounter + " setCounter:"+ tw eens[backId].counter + " tweens[id].type:"+tweens[backId].type);
if(tweens[backId].trans==null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter==backCounter)) {
if (callOnComplete && tweens[backId].optional.onComplete != null)
tweens[backId].optional.onComplete();
removeTween((int)backId);
}
}
}
public static void cancel( LTRect ltRect, int uniqueId ){
if(uniqueId>=0){
init();
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
// Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
if(tweens[backId]._optional.ltRect == ltRect && tweens[backId].counter==backCounter)
removeTween((int)backId);
}
}
/**
* Cancel a specific tween with the provided id Cancel a specific tween with the provided id
*
* @method LeanTween.cancel
* @param {int} id:int unique id that represents that tween
* @param {bool} callOnComplete:bool (optional) whether to call the onComplete method before canceling
* @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).id;
* LeanTween.cancel( id );
*/
public static void cancel( int uniqueId ){
cancel( uniqueId, false);
}
public static void cancel( int uniqueId, bool callOnComplete ){
if(uniqueId>=0){
init();
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
if (backId > tweens.Length - 1) { // sequence
int sequenceId = backId - tweens.Length;
LTSeq seq = sequences[sequenceId];
for (int i = 0; i < maxSequences; i++) {
if (seq.current.tween != null) {
int tweenId = seq.current.tween.uniqueId;
int tweenIndex = tweenId & 0xFFFF;
removeTween(tweenIndex);
}
if (seq.previous == null)
break;
seq.current = seq.previous;
}
} else { // tween
// Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
if (tweens[backId].counter == backCounter) {
if (callOnComplete && tweens[backId].optional.onComplete != null)
tweens[backId].optional.onComplete();
removeTween((int)backId);
}
}
}
}
/**
* Retrieve a tweens LTDescr object to modify Retrieve a tweens LTDescr object to modify
*
* @method LeanTween.descr
* @param {int} id:int unique id that represents that tween
* @example int id = LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod ).id;
*
// later I want decide I want to change onComplete method
* LTDescr descr = LeanTween.descr( id );
* if(descr!=null) // if the tween has already finished it will come back null
* descr.setOnComplete( newMethod );
*/
public static LTDescr descr( int uniqueId ){
init();
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
// Debug.Log("backId:" + backId+" backCounter:"+backCounter);
if (tweens[backId] != null && tweens[backId].uniqueId == uniqueId && tweens[backId].counter == backCounter) {
// Debug.Log("tween count:" + tweens[backId].counter);
return tweens[backId];
}
for(int i = 0; i <= tweenMaxSearch; i++){
if (tweens[i].uniqueId == uniqueId && tweens[i].counter == backCounter) {
return tweens[i];
}
}
return null;
}
public static LTDescr description( int uniqueId ){
return descr( uniqueId );
}
/**
* Retrieve a tweens LTDescr object(s) to modify Retrieve a tweens LTDescr object(s) to modifyn
*
* @method LeanTween.descriptions
* @param {GameObject} id:GameObject object whose tween descriptions you want to retrieve
* @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnComplete( oldMethod );
*
// later I want decide I want to change onComplete method
* LTDescr[] descr = LeanTween.descriptions( gameObject );
* if(descr.Length>0) // make sure there is a valid description for this target
* descr[0].setOnComplete( newMethod );// in this case we only ever expect there to be one tween on this object
*/
public static LTDescr[] descriptions(GameObject gameObject = null) {
if (gameObject == null) return null;
List descrs = new List();
Transform trans = gameObject.transform;
for (int i = 0; i <= tweenMaxSearch; i++) {
if (tweens[i].toggle && tweens[i].trans == trans)
descrs.Add( tweens[i] );
}
return descrs.ToArray();
}
[System.Obsolete("Use 'pause( id )' instead")]
public static void pause( GameObject gameObject, int uniqueId ){
pause( uniqueId );
}
/**
* Pause all tweens for a GameObject Pause all tweens for a GameObject
*
* @method LeanTween.pause
* @param {int} id:int Id of the tween you want to pause
* @example
* int id = LeanTween.moveX(gameObject, 5, 1.0).id
* LeanTween.pause( id );
* // Later....
* LeanTween.resume( id );
*/
public static void pause( int uniqueId ){
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
if(tweens[backId].counter==backCounter){
tweens[backId].pause();
}
}
/**
* Pause all tweens for a GameObject Pause all tweens for a GameObject
*
* @method LeanTween.pause
* @param {GameObject} gameObject:GameObject GameObject whose tweens you want to pause
*/
public static void pause( GameObject gameObject ){
Transform trans = gameObject.transform;
for(int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i].trans==trans){
tweens[i].pause();
}
}
}
/**
* Pause all active tweens Pause all active tweens
*
* @method LeanTween.pauseAll
*/
public static void pauseAll(){
init();
for (int i = 0; i <= tweenMaxSearch; i++){
tweens[i].pause();
}
}
/**
* Resume all active tweens Resume all active tweens
*
* @method LeanTween.resumeAll
*/
public static void resumeAll(){
init();
for (int i = 0; i <= tweenMaxSearch; i++){
tweens[i].resume();
}
}
[System.Obsolete("Use 'resume( id )' instead")]
public static void resume( GameObject gameObject, int uniqueId ){
resume( uniqueId );
}
/**
* Resume a specific tween Resume a specific tween
*
* @method LeanTween.resume
* @param {int} id:int Id of the tween you want to resume
* @example
* int id = LeanTween.moveX(gameObject, 5, 1.0).id
* LeanTween.pause( id );
* // Later....
* LeanTween.resume( id );
*/
public static void resume( int uniqueId ){
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
if(tweens[backId].counter==backCounter){
tweens[backId].resume();
}
}
/**
* Resume all the tweens on a GameObject Resume all the tweens on a GameObject
*
* @method LeanTween.resume
* @param {GameObject} gameObject:GameObject GameObject whose tweens you want to resume
*/
public static void resume( GameObject gameObject ){
Transform trans = gameObject.transform;
for(int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i].trans==trans)
tweens[i].resume();
}
}
/**
* Test whether or not a tween is active on a GameObject Test whether or not a tween is active on a GameObject
*
* @method LeanTween.isTweening
* @param {GameObject} gameObject:GameObject GameObject that you want to test if it is tweening
*/
public static bool isTweening( GameObject gameObject = null ){
if(gameObject==null){
for(int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i].toggle)
return true;
}
return false;
}
Transform trans = gameObject.transform;
for(int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i].toggle && tweens[i].trans==trans)
return true;
}
return false;
}
public static bool isTweening( RectTransform rect ){
return isTweening(rect.gameObject);
}
/**
* Test whether or not a tween is active or not Test whether or not a tween is active or not
*
* @method LeanTween.isTweening
* @param {GameObject} id:int id of the tween that you want to test if it is tweening
* @example
* int id = LeanTween.moveX(gameObject, 1f, 3f).id;
* if(LeanTween.isTweening( id ))
* Debug.Log("I am tweening!");
*/
public static bool isTweening( int uniqueId ){
int backId = uniqueId & 0xFFFF;
int backCounter = uniqueId >> 16;
if (backId < 0 || backId >= maxTweens) return false;
// Debug.Log("tweens[backId].counter:"+tweens[backId].counter+" backCounter:"+backCounter +" toggle:"+tweens[backId].toggle);
if(tweens[backId].counter==backCounter && tweens[backId].toggle){
return true;
}
return false;
}
public static bool isTweening( LTRect ltRect ){
for( int i = 0; i <= tweenMaxSearch; i++){
if(tweens[i].toggle && tweens[i]._optional.ltRect==ltRect)
return true;
}
return false;
}
public static void drawBezierPath(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float arrowSize = 0.0f, Transform arrowTransform = null){
Vector3 last = a;
Vector3 p;
Vector3 aa = (-a + 3*(b-c) + d);
Vector3 bb = 3*(a+c) - 6*b;
Vector3 cc = 3*(b-a);
float t;
if(arrowSize>0.0f){
Vector3 beforePos = arrowTransform.position;
Quaternion beforeQ = arrowTransform.rotation;
float distanceTravelled = 0f;
for(float k = 1.0f; k <= 120.0f; k++){
t = k / 120.0f;
p = ((aa* t + (bb))* t + cc)* t + a;
Gizmos.DrawLine(last, p);
distanceTravelled += (p-last).magnitude;
if(distanceTravelled>1f){
distanceTravelled = distanceTravelled - 1f;
/*float deltaY = p.y - last.y;
float deltaX = p.x - last.x;
float ang = Mathf.Atan(deltaY / deltaX);
Vector3 arrow = p + new Vector3( Mathf.Cos(ang+2.5f), Mathf.Sin(ang+2.5f), 0f)*0.5f;
Gizmos.DrawLine(p, arrow);
arrow = p + new Vector3( Mathf.Cos(ang+-2.5f), Mathf.Sin(ang+-2.5f), 0f)*0.5f;
Gizmos.DrawLine(p, arrow);*/
arrowTransform.position = p;
arrowTransform.LookAt( last, Vector3.forward );
Vector3 to = arrowTransform.TransformDirection(Vector3.right);
// Debug.Log("to:"+to+" tweenEmpty.transform.position:"+arrowTransform.position);
Vector3 back = (last-p);
back = back.normalized;
Gizmos.DrawLine(p, p + (to + back)*arrowSize);
to = arrowTransform.TransformDirection(-Vector3.right);
Gizmos.DrawLine(p, p + (to + back)*arrowSize);
}
last = p;
}
arrowTransform.position = beforePos;
arrowTransform.rotation = beforeQ;
}else{
for(float k = 1.0f; k <= 30.0f; k++){
t = k / 30.0f;
p = ((aa* t + (bb))* t + cc)* t + a;
Gizmos.DrawLine(last, p);
last = p;
}
}
}
public static object logError( string error ){
if(throwErrors) Debug.LogError(error); else Debug.Log(error);
return null;
}
public static LTDescr options(LTDescr seed){ Debug.LogError("error this function is no longer used"); return null; }
public static LTDescr options(){
init();
bool found = false;
// Debug.Log("Search start");
for(j=0, i = startSearch; j <= maxTweens; i++){
if(j >= maxTweens)
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;
if(i>=maxTweens)
i = 0;
// Debug.Log("searching i:"+i);
if(tweens[i].toggle==false){
if(i+1>tweenMaxSearch)
tweenMaxSearch = i+1;
startSearch = i + 1;
found = true;
break;
}
j++;
}
if(found==false)
logError("no available tween found!");
// Debug.Log("new tween with i:"+i+" counter:"+tweens[i].counter+" tweenMaxSearch:"+tweenMaxSearch+" tween:"+tweens[i]);
tweens[i].reset();
global_counter++;
if(global_counter>0x8000)
global_counter = 0;
tweens[i].setId( (uint)i, global_counter );
return tweens[i];
}
public static GameObject tweenEmpty{
get{
init(maxTweens);
return _tweenEmpty;
}
}
public static int startSearch = 0;
public static LTDescr d;
private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float time, LTDescr tween ){
init(maxTweens);
if(gameObject==null || tween==null)
return null;
tween.trans = gameObject.transform;
tween.to = to;
tween.time = time;
if (tween.time <= 0f)
tween.updateInternal();
//tween.hasPhysics = gameObject.rigidbody!=null;
return tween;
}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
/**
* Play a sequence of images on a Unity UI Object Play a sequence of images on a Unity UI Object
*
* @method LeanTween.play
* @param {RectTransform} rectTransform:RectTransform RectTransform that you want to play the sequence of sprites on
* @param {Sprite[]} sprites:Sprite[] Sequence of sprites to be played
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.play(gameObject.GetComponent<RectTransform>(), sprites).setLoopPingPong();
*/
public static LTDescr play(RectTransform rectTransform, UnityEngine.Sprite[] sprites){
float defaultFrameRate = 0.25f;
float time = defaultFrameRate * sprites.Length;
return pushNewTween(rectTransform.gameObject, new Vector3((float)sprites.Length - 1.0f,0,0), time, options().setCanvasPlaySprite().setSprites( sprites ).setRepeat(-1));
}
#endif
/**
* Fade a gameobject's material to a certain alpha value. The material's shader needs to support alpha. Owl labs has some excellent efficient shaders. Fade a gameobject's material to a certain alpha value.
*
* @method LeanTween.alpha
* @param {GameObject} gameObject:GameObject Gameobject that you wish to fade
* @param {float} to:float the final alpha value (0-1)
* @param {float} time:float The time with which to fade the object
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.alpha(gameObject, 1f, 1f) .setDelay(1f);
*/
public static LTDescr alpha(GameObject gameObject, float to, float time){
LTDescr lt = pushNewTween( gameObject, new Vector3(to,0,0), time, options().setAlpha() );
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
SpriteRenderer ren = gameObject.GetComponent();
lt.spriteRen = ren;
#endif
return lt;
}
/**
* Retrieve a sequencer object where you can easily chain together tweens and methods one after another Retrieve a sequencer object where you can easily chain together tweens and methods one after another
*
* @method LeanTween.sequence
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
* @example
* var seq = LeanTween.sequence();
* seq.add(1f); // delay everything one second
* seq.add( () => { // fire an event before start
* Debug.Log("I have started");
* });
* seq.add( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween
* seq.add( () => { // fire event after tween
* Debug.Log("We are done now");
* });;
*/
public static LTSeq sequence( bool initSequence = true){
init(maxTweens);
// Loop through and find available sequence
for (int i = 0; i < sequences.Length; i++) {
// Debug.Log("i:" + i + " sequences[i]:" + sequences[i]);
if (sequences[i].tween==null || sequences[i].tween.toggle == false) {
if (sequences[i].toggle == false) {
LTSeq seq = sequences[i];
if (initSequence) {
seq.init((uint)(i + tweens.Length), global_counter);
global_counter++;
if (global_counter > 0x8000)
global_counter = 0;
} else {
seq.reset();
}
return seq;
}
}
}
return null;
}
/**
* Fade a GUI Object Fade a GUI Object
*
* @method LeanTween.alpha
* @param {LTRect} ltRect:LTRect LTRect that you wish to fade
* @param {float} to:float the final alpha value (0-1)
* @param {float} time:float The time with which to fade the object
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.alpha(ltRect, 1f, 1f) .setEase(LeanTweenType.easeInCirc);
*/
public static LTDescr alpha(LTRect ltRect, float to, float time){
ltRect.alphaEnabled = true;
return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, options().setGUIAlpha().setRect( ltRect ) );
}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
/**
* Fade a Unity UI Object Fade a Unity UI Object
*
* @method LeanTween.alphaText
* @param {RectTransform} rectTransform:RectTransform RectTransform associated with the Text Component you wish to fade
* @param {float} to:float the final alpha value (0-1)
* @param {float} time:float The time with which to fade the object
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.alphaText(gameObject.GetComponent<RectTransform>(), 1f, 1f) .setEase(LeanTweenType.easeInCirc);
*/
public static LTDescr textAlpha(RectTransform rectTransform, float to, float time){
return pushNewTween(rectTransform.gameObject, new Vector3(to,0,0), time, options().setTextAlpha());
}
public static LTDescr alphaText(RectTransform rectTransform, float to, float time){
return pushNewTween(rectTransform.gameObject, new Vector3(to,0,0), time, options().setTextAlpha());
}
/**
* Fade a Unity UI Canvas Group Fade a Unity UI Canvas Group
*
* @method LeanTween.alphaCanvas
* @param {RectTransform} rectTransform:RectTransform RectTransform that the CanvasGroup is attached to
* @param {float} to:float the final alpha value (0-1)
* @param {float} time:float The time with which to fade the object
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.alphaCanvas(gameObject.GetComponent<RectTransform>(), 0f, 1f) .setLoopPingPong();
*/
public static LTDescr alphaCanvas(CanvasGroup canvasGroup, float to, float time){
return pushNewTween(canvasGroup.gameObject, new Vector3(to,0,0), time, options().setCanvasGroupAlpha());
}
#endif
/**
* This works by tweening the vertex colors directly. This works by tweening the vertex colors directly
Vertex-based coloring is useful because you avoid making a copy of your
object's material for each instance that needs a different color.
A shader that supports vertex colors is required for it to work
(for example the shaders in Mobile/Particles/)
*
* @method LeanTween.alphaVertex
* @param {GameObject} gameObject:GameObject Gameobject that you wish to alpha
* @param {float} to:float The alpha value you wish to tween to
* @param {float} time:float The time with which to delay before calling the function
* @return {LTDescr} LTDescr an object that distinguishes the tween
*/
public static LTDescr alphaVertex(GameObject gameObject, float to, float time){
return pushNewTween( gameObject, new Vector3(to,0f,0f), time, options().setAlphaVertex() );
}
/**
* Change a gameobject's material to a certain color value. The material's shader needs to support color tinting. Owl labs has some excellent efficient shaders. Change a gameobject's material to a certain color value
*
* @method LeanTween.color
* @param {GameObject} gameObject:GameObject Gameobject that you wish to change the color
* @param {Color} to:Color the final color value ex: Color.Red, new Color(1.0f,1.0f,0.0f,0.8f)
* @param {float} time:float The time with which to fade the object
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.color(gameObject, Color.yellow, 1f) .setDelay(1f);
*/
public static LTDescr color(GameObject gameObject, Color to, float time){
LTDescr lt = pushNewTween( gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setColor().setPoint( new Vector3(to.r, to.g, to.b) ) );
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
SpriteRenderer ren = gameObject.GetComponent();
lt.spriteRen = ren;
#endif
return lt;
}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
/**
* Change the color a Unity UI Object Change the color a Unity UI Object
*
* @method LeanTween.colorText
* @param {RectTransform} rectTransform:RectTransform RectTransform attached to the Text Component whose color you want to change
* @param {Color} to:Color the final alpha value ex: Color.Red, new Color(1.0f,1.0f,0.0f,0.8f)
* @param {float} time:float The time with which to fade the object
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example
* LeanTween.colorText(gameObject.GetComponent<RectTransform>(), Color.yellow, 1f) .setDelay(1f);
*/
public static LTDescr textColor(RectTransform rectTransform, Color to, float time){
return pushNewTween(rectTransform.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
}
public static LTDescr colorText(RectTransform rectTransform, Color to, float time){
return pushNewTween(rectTransform.gameObject, new Vector3(1.0f, to.a, 0.0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
}
#endif
/**
* Call a method after a specified amount of time Call a method after a specified amount of time
*
* @method LeanTween.delayedCall
* @param {GameObject} gameObject:GameObject Gameobject that you wish to associate with this delayed call
* @param {float} time:float delay The time you wish to pass before the method is called
* @return {LTDescr} LTDescr an object that distinguishes the tween
* @example LeanTween.delayedCall(gameObject, 1f, ()=>{ Debug.Log("I am called one second later!"); }));
*/
public static LTDescr delayedCall( float delayTime, Action callback){
return pushNewTween( tweenEmpty, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
}
public static LTDescr delayedCall( float delayTime, Action