/*
http://www.cgsoso.com/forum-211-1.html
CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
CGSOSO 主打游戏开发,影视设计等CG资源素材。
插件如若商用,请务必官网购买!
daily assets update for try.
U should buy the asset from home store if u use it in your project!
*/
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
public class LeanTween : MonoBehaviour
{
public static bool throwErrors = true;
public static float tau = (float)Math.PI * 2f;
public static float PI_DIV2 = (float)Math.PI / 2f;
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;
public static float dtActual;
private static uint global_counter = 0u;
private static int i;
private static int j;
private static int finishedCnt;
public static AnimationCurve punch = new AnimationCurve(new Keyframe(0f, 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(1f, 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));
private static int maxTweenReached;
public static int startSearch = 0;
public static LTDescr d;
private static Action[] eventListeners;
private static GameObject[] goListeners;
private static int eventsMaxSearch = 0;
public static int EVENTS_MAX = 10;
public static int LISTENERS_MAX = 10;
private static int INIT_LISTENERS_MAX = LISTENERS_MAX;
[CompilerGenerated]
private static UnityAction _003C_003Ef__mg_0024cache0;
public static int maxSearch => tweenMaxSearch;
public static int maxSimulataneousTweens => maxTweens;
public static int tweensRunning
{
get
{
int num = 0;
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].toggle)
{
num++;
}
}
return num;
}
}
public static GameObject tweenEmpty
{
get
{
init(maxTweens);
return _tweenEmpty;
}
}
public static void init()
{
init(maxTweens);
}
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;
_tweenEmpty.hideFlags = HideFlags.HideAndDontSave;
UnityEngine.Object.DontDestroyOnLoad(_tweenEmpty);
for (int i = 0; i < maxTweens; i++)
{
tweens[i] = new LTDescr();
}
SceneManager.sceneLoaded += onLevelWasLoaded54;
sequences = new LTSeq[maxSimultaneousSequences];
for (int j = 0; j < maxSimultaneousSequences; j++)
{
sequences[j] = 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;
UnityEngine.Object.Destroy(_tweenEmpty);
}
public void Update()
{
update();
}
private static void onLevelWasLoaded54(Scene scene, LoadSceneMode mode)
{
internalOnLevelWasLoaded(scene.buildIndex);
}
private static void internalOnLevelWasLoaded(int lvl)
{
LTGUI.reset();
}
public static void update()
{
if (frameRendered == Time.frameCount)
{
return;
}
init();
dtEstimated = ((dtEstimated < 0f) ? 0f : (dtEstimated = Time.unscaledDeltaTime));
dtActual = Time.deltaTime;
maxTweenReached = 0;
finishedCnt = 0;
for (int i = 0; i <= tweenMaxSearch && i < maxTweens; i++)
{
tween = tweens[i];
if (tween.toggle)
{
maxTweenReached = i;
if (tween.updateInternal())
{
tweensFinished[finishedCnt] = i;
tweensFinishedIds[finishedCnt] = tweens[i].id;
finishedCnt++;
}
}
}
tweenMaxSearch = maxTweenReached;
frameRendered = Time.frameCount;
for (int j = 0; j < finishedCnt; j++)
{
LeanTween.j = tweensFinished[j];
tween = tweens[LeanTween.j];
if (tween.id == tweensFinishedIds[j])
{
removeTween(LeanTween.j);
if (tween.hasExtraOnCompletes && tween.trans != null)
{
tween.callOnCompletes();
}
}
}
}
public static void removeTween(int i, int uniqueId)
{
if (tweens[i].uniqueId == uniqueId)
{
removeTween(i);
}
}
public static void removeTween(int i)
{
if (!tweens[i].toggle)
{
return;
}
tweens[i].toggle = false;
tweens[i].counter = uint.MaxValue;
if (tweens[i].destroyOnComplete)
{
if (tweens[i]._optional.ltRect != null)
{
LTGUI.destroy(tweens[i]._optional.ltRect.id);
}
else if (tweens[i].trans != null && tweens[i].trans.gameObject != _tweenEmpty)
{
UnityEngine.Object.Destroy(tweens[i].trans.gameObject);
}
}
startSearch = i;
if (i + 1 >= tweenMaxSearch)
{
startSearch = 0;
}
}
public static Vector3[] add(Vector3[] a, Vector3 b)
{
Vector3[] array = new Vector3[a.Length];
for (i = 0; i < a.Length; i++)
{
array[i] = a[i] + b;
}
return array;
}
public static float closestRot(float from, float to)
{
float num = 0f - (360f - to);
float num2 = 360f + to;
float num3 = Mathf.Abs(to - from);
float num4 = Mathf.Abs(num - from);
float num5 = Mathf.Abs(num2 - from);
if (num3 < num4 && num3 < num5)
{
return to;
}
if (num4 < num5)
{
return num;
}
return num2;
}
public static void cancelAll()
{
cancelAll(callComplete: 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);
}
}
}
public static void cancel(GameObject gameObject)
{
cancel(gameObject, callOnComplete: false);
}
public static void cancel(GameObject gameObject, bool callOnComplete)
{
init();
Transform transform = gameObject.transform;
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].toggle && tweens[i].trans == transform)
{
if (callOnComplete && tweens[i].optional.onComplete != null)
{
tweens[i].optional.onComplete();
}
removeTween(i);
}
}
}
public static void cancel(RectTransform rect)
{
cancel(rect.gameObject, callOnComplete: false);
}
public static void cancel(GameObject gameObject, int uniqueId, bool callOnComplete = false)
{
if (uniqueId < 0)
{
return;
}
init();
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (tweens[num].trans == null || (tweens[num].trans.gameObject == gameObject && tweens[num].counter == num2))
{
if (callOnComplete && tweens[num].optional.onComplete != null)
{
tweens[num].optional.onComplete();
}
removeTween(num);
}
}
public static void cancel(LTRect ltRect, int uniqueId)
{
if (uniqueId >= 0)
{
init();
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (tweens[num]._optional.ltRect == ltRect && tweens[num].counter == num2)
{
removeTween(num);
}
}
}
public static void cancel(int uniqueId)
{
cancel(uniqueId, callOnComplete: false);
}
public static void cancel(int uniqueId, bool callOnComplete)
{
if (uniqueId < 0)
{
return;
}
init();
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (num > tweens.Length - 1)
{
int num3 = num - tweens.Length;
LTSeq lTSeq = sequences[num3];
for (int i = 0; i < maxSequences; i++)
{
if (lTSeq.current.tween != null)
{
int uniqueId2 = lTSeq.current.tween.uniqueId;
int num4 = uniqueId2 & 0xFFFF;
removeTween(num4);
}
if (lTSeq.previous == null)
{
break;
}
lTSeq.current = lTSeq.previous;
}
}
else if (tweens[num].counter == num2)
{
if (callOnComplete && tweens[num].optional.onComplete != null)
{
tweens[num].optional.onComplete();
}
removeTween(num);
}
}
public static LTDescr descr(int uniqueId)
{
init();
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (tweens[num] != null && tweens[num].uniqueId == uniqueId && tweens[num].counter == num2)
{
return tweens[num];
}
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].uniqueId == uniqueId && tweens[i].counter == num2)
{
return tweens[i];
}
}
return null;
}
public static LTDescr description(int uniqueId)
{
return descr(uniqueId);
}
public static LTDescr[] descriptions(GameObject gameObject = null)
{
if (gameObject == null)
{
return null;
}
List list = new List();
Transform transform = gameObject.transform;
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].toggle && tweens[i].trans == transform)
{
list.Add(tweens[i]);
}
}
return list.ToArray();
}
[Obsolete("Use 'pause( id )' instead")]
public static void pause(GameObject gameObject, int uniqueId)
{
pause(uniqueId);
}
public static void pause(int uniqueId)
{
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (tweens[num].counter == num2)
{
tweens[num].pause();
}
}
public static void pause(GameObject gameObject)
{
Transform transform = gameObject.transform;
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].trans == transform)
{
tweens[i].pause();
}
}
}
public static void pauseAll()
{
init();
for (int i = 0; i <= tweenMaxSearch; i++)
{
tweens[i].pause();
}
}
public static void resumeAll()
{
init();
for (int i = 0; i <= tweenMaxSearch; i++)
{
tweens[i].resume();
}
}
[Obsolete("Use 'resume( id )' instead")]
public static void resume(GameObject gameObject, int uniqueId)
{
resume(uniqueId);
}
public static void resume(int uniqueId)
{
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (tweens[num].counter == num2)
{
tweens[num].resume();
}
}
public static void resume(GameObject gameObject)
{
Transform transform = gameObject.transform;
for (int i = 0; i <= tweenMaxSearch; i++)
{
if (tweens[i].trans == transform)
{
tweens[i].resume();
}
}
}
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 transform = gameObject.transform;
for (int j = 0; j <= tweenMaxSearch; j++)
{
if (tweens[j].toggle && tweens[j].trans == transform)
{
return true;
}
}
return false;
}
public static bool isTweening(RectTransform rect)
{
return isTweening(rect.gameObject);
}
public static bool isTweening(int uniqueId)
{
int num = uniqueId & 0xFFFF;
int num2 = uniqueId >> 16;
if (num < 0 || num >= maxTweens)
{
return false;
}
if (tweens[num].counter == num2 && tweens[num].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 = 0f, Transform arrowTransform = null)
{
Vector3 vector = a;
Vector3 a2 = -a + 3f * (b - c) + d;
Vector3 b2 = 3f * (a + c) - 6f * b;
Vector3 b3 = 3f * (b - a);
if (arrowSize > 0f)
{
Vector3 position = arrowTransform.position;
Quaternion rotation = arrowTransform.rotation;
float num = 0f;
for (float num2 = 1f; num2 <= 120f; num2 += 1f)
{
float num3 = num2 / 120f;
Vector3 vector2 = ((a2 * num3 + b2) * num3 + b3) * num3 + a;
Gizmos.DrawLine(vector, vector2);
num += (vector2 - vector).magnitude;
if (num > 1f)
{
num -= 1f;
arrowTransform.position = vector2;
arrowTransform.LookAt(vector, Vector3.forward);
Vector3 a3 = arrowTransform.TransformDirection(Vector3.right);
Vector3 normalized = (vector - vector2).normalized;
Gizmos.DrawLine(vector2, vector2 + (a3 + normalized) * arrowSize);
a3 = arrowTransform.TransformDirection(-Vector3.right);
Gizmos.DrawLine(vector2, vector2 + (a3 + normalized) * arrowSize);
}
vector = vector2;
}
arrowTransform.position = position;
arrowTransform.rotation = rotation;
}
else
{
for (float num4 = 1f; num4 <= 30f; num4 += 1f)
{
float num3 = num4 / 30f;
Vector3 vector2 = ((a2 * num3 + b2) * num3 + b3) * num3 + a;
Gizmos.DrawLine(vector, vector2);
vector = vector2;
}
}
}
public static object logError(string error)
{
if (throwErrors)
{
UnityEngine.Debug.LogError(error);
}
else
{
UnityEngine.Debug.Log(error);
}
return null;
}
public static LTDescr options(LTDescr seed)
{
UnityEngine.Debug.LogError("error this function is no longer used");
return null;
}
public static LTDescr options()
{
init();
bool flag = false;
j = 0;
i = startSearch;
while (j <= maxTweens)
{
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;
}
if (!tweens[i].toggle)
{
if (i + 1 > tweenMaxSearch)
{
tweenMaxSearch = i + 1;
}
startSearch = i + 1;
flag = true;
break;
}
j++;
i++;
}
if (!flag)
{
logError("no available tween found!");
}
tweens[i].reset();
global_counter++;
if (global_counter > 32768)
{
global_counter = 0u;
}
tweens[i].setId((uint)i, global_counter);
return tweens[i];
}
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();
}
return tween;
}
public static LTDescr play(RectTransform rectTransform, Sprite[] sprites)
{
float num = 0.25f;
float time = num * (float)sprites.Length;
return pushNewTween(rectTransform.gameObject, new Vector3((float)sprites.Length - 1f, 0f, 0f), time, options().setCanvasPlaySprite().setSprites(sprites).setRepeat(-1));
}
public static LTDescr alpha(GameObject gameObject, float to, float time)
{
LTDescr lTDescr = pushNewTween(gameObject, new Vector3(to, 0f, 0f), time, options().setAlpha());
SpriteRenderer spriteRenderer = lTDescr.spriteRen = gameObject.GetComponent();
return lTDescr;
}
public static LTSeq sequence(bool initSequence = true)
{
init(maxTweens);
for (int i = 0; i < sequences.Length; i++)
{
if ((sequences[i].tween != null && sequences[i].tween.toggle) || sequences[i].toggle)
{
continue;
}
LTSeq lTSeq = sequences[i];
if (initSequence)
{
lTSeq.init((uint)(i + tweens.Length), global_counter);
global_counter++;
if (global_counter > 32768)
{
global_counter = 0u;
}
}
else
{
lTSeq.reset();
}
return lTSeq;
}
return null;
}
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));
}
public static LTDescr textAlpha(RectTransform rectTransform, float to, float time)
{
return pushNewTween(rectTransform.gameObject, new Vector3(to, 0f, 0f), time, options().setTextAlpha());
}
public static LTDescr alphaText(RectTransform rectTransform, float to, float time)
{
return pushNewTween(rectTransform.gameObject, new Vector3(to, 0f, 0f), time, options().setTextAlpha());
}
public static LTDescr alphaCanvas(CanvasGroup canvasGroup, float to, float time)
{
return pushNewTween(canvasGroup.gameObject, new Vector3(to, 0f, 0f), time, options().setCanvasGroupAlpha());
}
public static LTDescr alphaVertex(GameObject gameObject, float to, float time)
{
return pushNewTween(gameObject, new Vector3(to, 0f, 0f), time, options().setAlphaVertex());
}
public static LTDescr color(GameObject gameObject, Color to, float time)
{
LTDescr lTDescr = pushNewTween(gameObject, new Vector3(1f, to.a, 0f), time, options().setColor().setPoint(new Vector3(to.r, to.g, to.b)));
SpriteRenderer spriteRenderer = lTDescr.spriteRen = gameObject.GetComponent();
return lTDescr;
}
public static LTDescr textColor(RectTransform rectTransform, Color to, float time)
{
return pushNewTween(rectTransform.gameObject, new Vector3(1f, to.a, 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(1f, to.a, 0f), time, options().setTextColor().setPoint(new Vector3(to.r, to.g, to.b)));
}
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