diff --git a/Assets/Fungus/Scripts/Commands/Conversation.cs b/Assets/Fungus/Scripts/Commands/Conversation.cs
index c7dfb143..42e1da4a 100644
--- a/Assets/Fungus/Scripts/Commands/Conversation.cs
+++ b/Assets/Fungus/Scripts/Commands/Conversation.cs
@@ -7,11 +7,11 @@ using System.Collections;
namespace Fungus
{
///
- /// Do multiple say and portrait commands in a single block of text. Format is: [character] [portrait] [stage position] [: Story text].
+ /// Do multiple say and portrait commands in a single block of text. Format is: [character] [portrait] [stage position] [hide] [<<< | >>>] [clear | noclear] [wait | nowait] [fade | nofade] [: Story text].
///
[CommandInfo("Narrative",
- "Conversation",
- "Do multiple say and portrait commands in a single block of text. Format is: [character] [portrait] [stage position] [: Story text]")]
+ "Conversation",
+ "Do multiple say and portrait commands in a single block of text. Format is: [character] [portrait] [stage position] [hide] [<<< | >>>] [clear | noclear] [wait | nowait] [fade | nofade] [: Story text]")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class Conversation : Command
@@ -20,6 +20,12 @@ namespace Fungus
protected ConversationManager conversationManager = new ConversationManager();
+ [SerializeField] protected BooleanData clearPrevious = new BooleanData(true);
+ [SerializeField] protected BooleanData waitForInput = new BooleanData(true);
+ [Tooltip("a wait for seconds added to each item of the conversation.")]
+ [SerializeField] protected FloatData waitForSeconds = new FloatData(0);
+ [SerializeField] protected BooleanData fadeWhenDone = new BooleanData(true);
+
protected virtual void Start()
{
conversationManager.PopulateCharacterCache();
@@ -30,6 +36,11 @@ namespace Fungus
var flowchart = GetFlowchart();
string subbedText = flowchart.SubstituteVariables(conversationText.Value);
+ conversationManager.ClearPrev = clearPrevious;
+ conversationManager.WaitForInput = waitForInput;
+ conversationManager.FadeDone = fadeWhenDone;
+ conversationManager.WaitForSeconds = waitForSeconds;
+
yield return StartCoroutine(conversationManager.DoConversation(subbedText));
Continue();
diff --git a/Assets/Fungus/Scripts/Commands/Input/GetKey.cs b/Assets/Fungus/Scripts/Commands/Input/GetKey.cs
new file mode 100644
index 00000000..341fd99d
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Input/GetKey.cs
@@ -0,0 +1,174 @@
+using UnityEngine;
+
+namespace Fungus
+{
+ //
+ /// Store Input.GetKey in a variable. Supports an optional Negative key input. A negative value will be overridden by a positive one, they do not add.
+ ///
+ [CommandInfo("Input",
+ "GetKey",
+ "Store Input.GetKey in a variable. Supports an optional Negative key input. A negative value will be overridden by a positive one, they do not add.")]
+ [AddComponentMenu("")]
+ public class GetKey : Command
+ {
+ [SerializeField]
+ protected KeyCode keyCode = KeyCode.None;
+
+ [Tooltip("Optional, secondary or negative keycode. For booleans will also set to true, for int and float will set to -1.")]
+ [SerializeField]
+ protected KeyCode keyCodeNegative = KeyCode.None;
+
+ [SerializeField]
+ [Tooltip("Only used if KeyCode is KeyCode.None, expects a name of the key to use.")]
+ protected StringData keyCodeName = new StringData(string.Empty);
+
+ [SerializeField]
+ [Tooltip("Optional, secondary or negative keycode. For booleans will also set to true, for int and float will set to -1." +
+ "Only used if KeyCode is KeyCode.None, expects a name of the key to use.")]
+ protected StringData keyCodeNameNegative = new StringData(string.Empty);
+
+ public enum InputKeyQueryType
+ {
+ Down,
+ Up,
+ State
+ }
+
+ [Tooltip("Do we want an Input.GetKeyDown, GetKeyUp or GetKey")]
+ [SerializeField]
+ protected InputKeyQueryType keyQueryType = InputKeyQueryType.State;
+
+ [Tooltip("Will store true or false or 0 or 1 depending on type. Sets true or -1 for negative key values.")]
+ [SerializeField]
+ [VariableProperty(typeof(FloatVariable), typeof(BooleanVariable), typeof(IntegerVariable))]
+ protected Variable outValue;
+
+ public override void OnEnter()
+ {
+ FillOutValue(0);
+
+ if (keyCodeNegative != KeyCode.None)
+ {
+ DoKeyCode(keyCodeNegative, -1);
+ }
+ else if (!string.IsNullOrEmpty(keyCodeNameNegative))
+ {
+ DoKeyName(keyCodeNameNegative, -1);
+ }
+
+
+ if (keyCode != KeyCode.None)
+ {
+ DoKeyCode(keyCode, 1);
+ }
+ else if (!string.IsNullOrEmpty(keyCodeName))
+ {
+ DoKeyName(keyCodeName, 1);
+ }
+
+ Continue();
+ }
+
+ private void DoKeyCode(KeyCode key, int trueVal)
+ {
+ switch (keyQueryType)
+ {
+ case InputKeyQueryType.Down:
+ if (Input.GetKeyDown(key))
+ {
+ FillOutValue(trueVal);
+ }
+ break;
+ case InputKeyQueryType.Up:
+ if (Input.GetKeyUp(key))
+ {
+ FillOutValue(trueVal);
+ }
+ break;
+ case InputKeyQueryType.State:
+ if (Input.GetKey(key))
+ {
+ FillOutValue(trueVal);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void DoKeyName(string key, int trueVal)
+ {
+ switch (keyQueryType)
+ {
+ case InputKeyQueryType.Down:
+ if (Input.GetKeyDown(key))
+ {
+ FillOutValue(trueVal);
+ }
+ break;
+ case InputKeyQueryType.Up:
+ if (Input.GetKeyUp(key))
+ {
+ FillOutValue(trueVal);
+ }
+ break;
+ case InputKeyQueryType.State:
+ if (Input.GetKey(key))
+ {
+ FillOutValue(trueVal);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void FillOutValue(int v)
+ {
+ FloatVariable fvar = outValue as FloatVariable;
+ if (fvar != null)
+ {
+ fvar.Value = v;
+ return;
+ }
+
+ BooleanVariable bvar = outValue as BooleanVariable;
+ if (bvar != null)
+ {
+ bvar.Value = v == 0 ? false : true;
+ return;
+ }
+
+ IntegerVariable ivar = outValue as IntegerVariable;
+ if (ivar != null)
+ {
+ ivar.Value = v;
+ return;
+ }
+ }
+
+ public override string GetSummary()
+ {
+ if (outValue == null)
+ {
+ return "Error: no outvalue set";
+ }
+
+ return (keyCode != KeyCode.None ? keyCode.ToString() : keyCodeName) + " in " + outValue.Key;
+ }
+
+ public override Color GetButtonColor()
+ {
+ return new Color32(235, 191, 217, 255);
+ }
+
+ public override bool HasReference(Variable variable)
+ {
+ if (keyCodeName.stringRef == variable || outValue == variable || keyCodeNameNegative.stringRef == variable)
+ return true;
+
+ return false;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Scripts/Commands/Input/GetKey.cs.meta b/Assets/Fungus/Scripts/Commands/Input/GetKey.cs.meta
new file mode 100644
index 00000000..d821cc16
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Input/GetKey.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: abf9e2e4334293449850759c812dd9db
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/Property.meta b/Assets/Fungus/Scripts/Commands/Priority.meta
similarity index 60%
rename from Assets/Fungus/Scripts/Commands/Property.meta
rename to Assets/Fungus/Scripts/Commands/Priority.meta
index d2aa6cd5..f6aaeb61 100644
--- a/Assets/Fungus/Scripts/Commands/Property.meta
+++ b/Assets/Fungus/Scripts/Commands/Priority.meta
@@ -1,9 +1,10 @@
fileFormatVersion: 2
-guid: 103d5735e5e7b4a409ae0bb18c246f22
+guid: 61d2004f0aa3f1847beb167296c897d8
folderAsset: yes
-timeCreated: 1513473561
+timeCreated: 1523180219
licenseType: Free
DefaultImporter:
+ externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs
new file mode 100644
index 00000000..a1aa957a
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs
@@ -0,0 +1,34 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Fungus
+{
+ ///
+ /// Copy the value of the Priority Count to a local IntegerVariable, intended primarily to assist with debugging use of Priority.
+ ///
+ [CommandInfo("Priority Signals",
+ "Get Priority Count",
+ "Copy the value of the Priority Count to a local IntegerVariable, intended primarily to assist with debugging use of Priority.")]
+ public class FungusPriorityCount : Command
+ {
+ [VariableProperty(typeof(IntegerVariable))]
+ public IntegerVariable outVar;
+
+ public override void OnEnter()
+ {
+ outVar.Value = FungusPrioritySignals.CurrentPriorityDepth;
+
+ Continue();
+ }
+
+ public override string GetSummary()
+ {
+ if(outVar == null)
+ {
+ return "Error: No out var supplied";
+ }
+ return outVar.Key;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs.meta b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs.meta
new file mode 100644
index 00000000..4862a858
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityCount.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: a3aeb6a9bd739484080e7965ecaab89e
+timeCreated: 1523926493
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityDecrease.cs b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityDecrease.cs
new file mode 100644
index 00000000..8461eaee
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityDecrease.cs
@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Fungus
+{
+ ///
+ /// Decrease the FungusPriority count, causing the related FungusPrioritySignals to fire.
+ /// Intended to be used to notify external systems that fungus is doing something important and they should perhaps resume.
+ ///
+ [CommandInfo("Priority Signals",
+ "Priority Down",
+ "Decrease the FungusPriority count, causing the related FungusPrioritySignals to fire. " +
+ "Intended to be used to notify external systems that fungus is doing something important and they should perhaps resume.")]
+ public class FungusPriorityDecrease : Command
+ {
+ public override void OnEnter()
+ {
+ FungusPrioritySignals.DoDecreasePriorityDepth();
+
+ Continue();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityDecrease.cs.meta b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityDecrease.cs.meta
new file mode 100644
index 00000000..385cd193
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityDecrease.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: ebc295ba6aed8944fa3974a64f33cc42
+timeCreated: 1523926493
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityIncrease.cs b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityIncrease.cs
new file mode 100644
index 00000000..40282e32
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityIncrease.cs
@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Fungus
+{
+ ///
+ /// Increases the FungusPriority count, causing the related FungusPrioritySignals to fire.
+ /// Intended to be used to notify external systems that fungus is doing something important and they should perhaps pause.
+ ///
+ [CommandInfo("Priority Signals",
+ "Priority Up",
+ "Increases the FungusPriority count, causing the related FungusPrioritySignals to fire. " +
+ "Intended to be used to notify external systems that fungus is doing something important and they should perhaps pause.")]
+ public class FungusPriorityIncrease : Command
+ {
+ public override void OnEnter()
+ {
+ FungusPrioritySignals.DoIncreasePriorityDepth();
+
+ Continue();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityIncrease.cs.meta b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityIncrease.cs.meta
new file mode 100644
index 00000000..49d7aed5
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityIncrease.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 3d07cf5e706b13a4eb0ae53386c30fbd
+timeCreated: 1523926493
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityReset.cs b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityReset.cs
new file mode 100644
index 00000000..d854f388
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityReset.cs
@@ -0,0 +1,22 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Fungus
+{
+ ///
+ /// Resets the FungusPriority count to zero. Useful if you are among logic that is hard to have matching increase and decreases.
+ ///
+ [CommandInfo("Priority Signals",
+ "Priority Reset",
+ "Resets the FungusPriority count to zero. Useful if you are among logic that is hard to have matching increase and decreases.")]
+ public class FungusPriorityReset : Command
+ {
+ public override void OnEnter()
+ {
+ FungusPrioritySignals.DoResetPriority();
+
+ Continue();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityReset.cs.meta b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityReset.cs.meta
new file mode 100644
index 00000000..7929cf49
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/Priority/FungusPriorityReset.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: b5b98ba2a3006db49959601485049a0d
+timeCreated: 1523926493
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/StopFlowchart.cs b/Assets/Fungus/Scripts/Commands/StopFlowchart.cs
index c11cedbb..d439796f 100644
--- a/Assets/Fungus/Scripts/Commands/StopFlowchart.cs
+++ b/Assets/Fungus/Scripts/Commands/StopFlowchart.cs
@@ -27,21 +27,21 @@ namespace Fungus
{
var flowchart = GetFlowchart();
- if (stopParentFlowchart)
- {
- flowchart.StopAllBlocks();
- }
-
for (int i = 0; i < targetFlowcharts.Count; i++)
{
var f = targetFlowcharts[i];
- if (f == flowchart)
- {
- // Flowchart has already been stopped
- continue;
- }
f.StopAllBlocks();
}
+
+ //current block and command logic doesn't require it in this order but it makes sense to
+ // stop everything but yourself first
+ if (stopParentFlowchart)
+ {
+ flowchart.StopAllBlocks();
+ }
+
+ //you might not be stopping this flowchart so keep going
+ Continue();
}
public override bool IsReorderableArray(string propertyName)
diff --git a/Assets/Fungus/Scripts/Components/EventHandler.cs b/Assets/Fungus/Scripts/Components/EventHandler.cs
index 602c8eb7..b563acf1 100644
--- a/Assets/Fungus/Scripts/Components/EventHandler.cs
+++ b/Assets/Fungus/Scripts/Components/EventHandler.cs
@@ -65,6 +65,12 @@ namespace Fungus
var flowchart = ParentBlock.GetFlowchart();
+ //if somehow the flowchart is invalid or has been disabled we don't want to continue
+ if(flowchart == null || !flowchart.isActiveAndEnabled)
+ {
+ return false;
+ }
+
// Auto-follow the executing block if none is currently selected
if (flowchart.SelectedBlock == null)
{
diff --git a/Assets/Fungus/Scripts/Components/PortraitController.cs b/Assets/Fungus/Scripts/Components/PortraitController.cs
index 47c2fc9b..1f58d155 100644
--- a/Assets/Fungus/Scripts/Components/PortraitController.cs
+++ b/Assets/Fungus/Scripts/Components/PortraitController.cs
@@ -203,7 +203,7 @@ namespace Fungus
float duration = (fadeDuration > 0f) ? fadeDuration : float.Epsilon;
// Fade in character image (first time)
- LeanTween.alpha(portraitImage.transform as RectTransform, 1f, duration).setEase(stage.FadeEaseType);
+ LeanTween.alpha(portraitImage.transform as RectTransform, 1f, duration).setEase(stage.FadeEaseType).setRecursive(false);
// Tell character about portrait image
character.State.portraitImage = portraitImage;
@@ -455,7 +455,7 @@ namespace Fungus
float duration = (options.fadeDuration > 0f) ? options.fadeDuration : float.Epsilon;
// Fade out a duplicate of the existing portrait image
- if (options.character.State.portraitImage != null)
+ if (options.character.State.portraitImage != null && options.character.State.portraitImage.sprite != null)
{
GameObject tempGO = GameObject.Instantiate(options.character.State.portraitImage.gameObject);
tempGO.transform.SetParent(options.character.State.portraitImage.transform, false);
@@ -469,7 +469,7 @@ namespace Fungus
LeanTween.alpha(tempImage.rectTransform, 0f, duration).setEase(stage.FadeEaseType).setOnComplete(() => {
Destroy(tempGO);
- });
+ }).setRecursive(false);
}
// Fade in the new sprite image
@@ -478,7 +478,7 @@ namespace Fungus
{
options.character.State.portraitImage.sprite = options.portrait;
options.character.State.portraitImage.color = new Color(1f, 1f, 1f, 0f);
- LeanTween.alpha(options.character.State.portraitImage.rectTransform, 1f, duration).setEase(stage.FadeEaseType);
+ LeanTween.alpha(options.character.State.portraitImage.rectTransform, 1f, duration).setEase(stage.FadeEaseType).setRecursive(false);
}
DoMoveTween(options);
@@ -577,7 +577,7 @@ namespace Fungus
// LeanTween doesn't handle 0 duration properly
float duration = (options.fadeDuration > 0f) ? options.fadeDuration : float.Epsilon;
- LeanTween.alpha(options.character.State.portraitImage.rectTransform, 0f, duration).setEase(stage.FadeEaseType);
+ LeanTween.alpha(options.character.State.portraitImage.rectTransform, 0f, duration).setEase(stage.FadeEaseType).setRecursive(false);
DoMoveTween(options);
@@ -610,7 +610,7 @@ namespace Fungus
// LeanTween doesn't handle 0 duration properly
float duration = (stage.FadeDuration > 0f) ? stage.FadeDuration : float.Epsilon;
- LeanTween.color(character.State.portraitImage.rectTransform, targetColor, duration).setEase(stage.FadeEaseType);
+ LeanTween.color(character.State.portraitImage.rectTransform, targetColor, duration).setEase(stage.FadeEaseType).setRecursive(false);
}
#endregion
diff --git a/Assets/Fungus/Scripts/Editor/FungusEditorResources.cs b/Assets/Fungus/Scripts/Editor/FungusEditorResources.cs
index b3ebd715..d2a84915 100644
--- a/Assets/Fungus/Scripts/Editor/FungusEditorResources.cs
+++ b/Assets/Fungus/Scripts/Editor/FungusEditorResources.cs
@@ -78,7 +78,7 @@ namespace Fungus.EditorUtils
private static FungusEditorResources instance;
private static readonly string editorResourcesFolderName = "\"EditorResources\"";
- private static readonly string PartialEditorResourcesPath = System.IO.Path.Combine("Fungus\\", "EditorResources");
+ private static readonly string PartialEditorResourcesPath = System.IO.Path.Combine("Fungus", "EditorResources");
[SerializeField] [HideInInspector] private bool updateOnReloadScripts = false;
internal static FungusEditorResources Instance
diff --git a/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs b/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs
index 60171bbb..1c681464 100644
--- a/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs
+++ b/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs
@@ -25,10 +25,13 @@ namespace Fungus
//sorted list of the GO instance IDs that have flowcharts on them
static List flowchartIDs = new List();
+ static bool initalHierarchyCheckFlag = true;
+
static HierarchyIcons()
- {
+ {
+ initalHierarchyCheckFlag = true;
EditorApplication.hierarchyWindowItemOnGUI += HierarchyIconCallback;
- EditorApplication.hierarchyWindowChanged += HierarchyChanged;
+ EditorApplication.hierarchyChanged += HierarchyChanged;
}
//track all gameobjectIds that have flowcharts on them
@@ -48,6 +51,12 @@ namespace Fungus
//Draw icon if the isntance id is in our cached list
static void HierarchyIconCallback(int instanceID, Rect selectionRect)
{
+ if(initalHierarchyCheckFlag)
+ {
+ HierarchyChanged();
+ initalHierarchyCheckFlag = false;
+ }
+
if (EditorUtils.FungusEditorPreferences.hideMushroomInHierarchy)
return;
diff --git a/Assets/Fungus/Scripts/Signals/FungusActiveSignals.cs b/Assets/Fungus/Scripts/Signals/FungusActiveSignals.cs
new file mode 100644
index 00000000..f28f75bd
--- /dev/null
+++ b/Assets/Fungus/Scripts/Signals/FungusActiveSignals.cs
@@ -0,0 +1,96 @@
+namespace Fungus
+{
+ ///
+ /// Fungus Priority event signalling system.
+ /// A common point for Fungus core systems and user Commands to signal to external code that a
+ /// Fungus system is currently doing something important.
+ ///
+ /// One intended use case for this system is to have your code listen to this to know when to
+ /// stop player movement or camera movement etc. when the player is engaged in a conversation
+ /// with an NPC.
+ ///
+ public static class FungusPrioritySignals
+ {
+ #region Public members
+ ///
+ /// used by increase and decrease active depth functions.
+ ///
+ private static int activeDepth;
+
+ public static int CurrentPriorityDepth
+ {
+ get
+ {
+ return activeDepth;
+ }
+ }
+
+ public static event FungusPriorityStartHandler OnFungusPriorityStart;
+ public delegate void FungusPriorityStartHandler();
+
+ public static event FungusPriorityEndHandler OnFungusPriorityEnd;
+ public delegate void FungusPriorityEndHandler();
+
+
+ public static event FungusPriorityChangeHandler OnFungusPriorityChange;
+ public delegate void FungusPriorityChangeHandler(int previousActiveDepth, int newActiveDepth);
+
+ ///
+ /// Adds 1 to the theactiveDepth. If it was zero causes the OnFungusPriorityStart
+ ///
+ public static void DoIncreasePriorityDepth()
+ {
+ if(activeDepth == 0)
+ {
+ if (OnFungusPriorityStart != null)
+ {
+ OnFungusPriorityStart();
+ }
+ }
+ if(OnFungusPriorityChange != null)
+ {
+ OnFungusPriorityChange(activeDepth, activeDepth + 1);
+ }
+ activeDepth++;
+ }
+
+ ///
+ /// Subtracts 1 to the theactiveDepth. If it reaches zero causes the OnFungusPriorityEnd
+ ///
+ public static void DoDecreasePriorityDepth()
+ {
+ if (OnFungusPriorityChange != null)
+ {
+ OnFungusPriorityChange(activeDepth, activeDepth - 1);
+ }
+ if(activeDepth == 1)
+ {
+ if(OnFungusPriorityEnd != null)
+ {
+ OnFungusPriorityEnd();
+ }
+ }
+ activeDepth--;
+ }
+
+ ///
+ /// Forces active depth back to 0. If already 0 fires no signals.
+ ///
+ public static void DoResetPriority()
+ {
+ if (activeDepth == 0)
+ return;
+
+ if (OnFungusPriorityChange != null)
+ {
+ OnFungusPriorityChange(activeDepth, 0);
+ }
+ if (OnFungusPriorityEnd != null)
+ {
+ OnFungusPriorityEnd();
+ }
+ activeDepth = 0;
+ }
+ #endregion
+ }
+}
diff --git a/Assets/Fungus/Scripts/Signals/FungusActiveSignals.cs.meta b/Assets/Fungus/Scripts/Signals/FungusActiveSignals.cs.meta
new file mode 100644
index 00000000..3d081ea0
--- /dev/null
+++ b/Assets/Fungus/Scripts/Signals/FungusActiveSignals.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: fd542ada4b268ba49bcab2fd4d8e465e
+timeCreated: 1523173334
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Utils/ConversationManager.cs b/Assets/Fungus/Scripts/Utils/ConversationManager.cs
index 940eae8e..7dcf8efd 100644
--- a/Assets/Fungus/Scripts/Utils/ConversationManager.cs
+++ b/Assets/Fungus/Scripts/Utils/ConversationManager.cs
@@ -23,11 +23,25 @@ namespace Fungus
public bool Hide { get; set; }
public FacingDirection FacingDirection { get; set; }
public bool Flip { get; set; }
+ public bool ClearPrev { get; set; }
+ public bool WaitForInput { get; set; }
+ public bool FadeDone { get; set; }
}
protected Character[] characters;
protected bool exitSayWait;
+ public bool ClearPrev { get; set; }
+ public bool WaitForInput { get; set; }
+ public bool FadeDone { get; set; }
+ public FloatData WaitForSeconds { get; internal set; }
+
+ public ConversationManager()
+ {
+ ClearPrev = true;
+ FadeDone = true;
+ WaitForInput = true;
+ }
///
/// Splits the string passed in by the delimiters passed in.
@@ -150,16 +164,53 @@ namespace Fungus
protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter)
{
var item = new ConversationItem();
+ item.ClearPrev = ClearPrev;
+ item.FadeDone = FadeDone;
+ item.WaitForInput = WaitForInput;
// Populate the story text to be written
item.Text = text;
+ if(WaitForSeconds > 0)
+ {
+ item.Text += "{w=" + WaitForSeconds.ToString() +"}";
+ }
+
if (sayParams == null || sayParams.Length == 0)
{
// Text only, no params - early out.
return item;
}
+ //TODO this needs a refactor
+ for (int i = 0; i < sayParams.Length; i++)
+ {
+ if (string.Compare(sayParams[i], "clear", true) == 0)
+ {
+ item.ClearPrev = true;
+ }
+ else if (string.Compare(sayParams[i], "noclear", true) == 0)
+ {
+ item.ClearPrev = false;
+ }
+ else if (string.Compare(sayParams[i], "fade", true) == 0)
+ {
+ item.FadeDone = true;
+ }
+ else if (string.Compare(sayParams[i], "nofade", true) == 0)
+ {
+ item.FadeDone = false;
+ }
+ else if (string.Compare(sayParams[i], "wait", true) == 0)
+ {
+ item.WaitForInput = true;
+ }
+ else if (string.Compare(sayParams[i], "nowait", true) == 0)
+ {
+ item.WaitForInput = false;
+ }
+ }
+
// try to find the character param first, since we need to get its portrait
int characterIndex = -1;
if (characters == null)
@@ -381,7 +432,7 @@ namespace Fungus
if (!string.IsNullOrEmpty(item.Text)) {
exitSayWait = false;
- sayDialog.Say(item.Text, true, true, true, true, false, null, () => {
+ sayDialog.Say(item.Text, item.ClearPrev, item.WaitForInput, item.FadeDone, true, false, null, () => {
exitSayWait = true;
});
diff --git a/Assets/Fungus/Scripts/Utils/TextTagParser.cs b/Assets/Fungus/Scripts/Utils/TextTagParser.cs
index 6fb14a72..36b36451 100644
--- a/Assets/Fungus/Scripts/Utils/TextTagParser.cs
+++ b/Assets/Fungus/Scripts/Utils/TextTagParser.cs
@@ -209,6 +209,7 @@ namespace Fungus
"\t{w}, {w=0.5} Wait (seconds)\n" +
"\t{wi} Wait for input\n" +
"\t{wc} Wait for input and clear\n" +
+ "\t{wvo} Wait for voice over line to complete\n" +
"\t{wp}, {wp=0.5} Wait on punctuation (seconds){/wp}\n" +
"\t{c} Clear\n" +
"\t{x} Exit, advance to the next command without waiting for input\n" +
diff --git a/Assets/Fungus/Thirdparty/LeanTween.meta b/Assets/Fungus/Thirdparty/LeanTween.meta
index 0bc313d3..eb22f9ca 100644
--- a/Assets/Fungus/Thirdparty/LeanTween.meta
+++ b/Assets/Fungus/Thirdparty/LeanTween.meta
@@ -1,2 +1,8 @@
fileFormatVersion: 2
guid: 5e6a0fa47acf54892bbdae89028eaec3
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Thirdparty/LeanTween/LTDescr.cs b/Assets/Fungus/Thirdparty/LeanTween/LTDescr.cs
new file mode 100644
index 00000000..aed6fb65
--- /dev/null
+++ b/Assets/Fungus/Thirdparty/LeanTween/LTDescr.cs
@@ -0,0 +1,2285 @@
+//namespace DentedPixel{
+using System;
+using UnityEngine;
+
+/**
+* Internal Representation of a Tween
+*
+* This class represents all of the optional parameters you can pass to a method (it also represents the internal representation of the tween).
+* 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 pass parameters at a later time by saving a reference to what is returned.
+*
+* Retrieve a unique id for the tween by using the "id" property. You can pass this to LeanTween.pause, LeanTween.resume, LeanTween.cancel, LeanTween.isTweening methods
+*
+*
Example:
+* int id = LeanTween.moveX(gameObject, 1f, 3f).id;
+*
// pause a specific tween
+* LeanTween.pause(id);
+*
// resume later
+* LeanTween.resume(id);
+*
// check if it is tweening before kicking of a new tween
+ *
+ * @method setEase
+ * @param {LeanTweenType} easeType:LeanTweenType the easing type to use
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce );
+ */
+ public LTDescr setEase( LeanTweenType easeType ){
+
+ switch( easeType ){
+ case LeanTweenType.linear:
+ setEaseLinear(); break;
+ case LeanTweenType.easeOutQuad:
+ setEaseOutQuad(); break;
+ case LeanTweenType.easeInQuad:
+ setEaseInQuad(); break;
+ case LeanTweenType.easeInOutQuad:
+ setEaseInOutQuad(); break;
+ case LeanTweenType.easeInCubic:
+ setEaseInCubic();break;
+ case LeanTweenType.easeOutCubic:
+ setEaseOutCubic(); break;
+ case LeanTweenType.easeInOutCubic:
+ setEaseInOutCubic(); break;
+ case LeanTweenType.easeInQuart:
+ setEaseInQuart(); break;
+ case LeanTweenType.easeOutQuart:
+ setEaseOutQuart(); break;
+ case LeanTweenType.easeInOutQuart:
+ setEaseInOutQuart(); break;
+ case LeanTweenType.easeInQuint:
+ setEaseInQuint(); break;
+ case LeanTweenType.easeOutQuint:
+ setEaseOutQuint(); break;
+ case LeanTweenType.easeInOutQuint:
+ setEaseInOutQuint(); break;
+ case LeanTweenType.easeInSine:
+ setEaseInSine(); break;
+ case LeanTweenType.easeOutSine:
+ setEaseOutSine(); break;
+ case LeanTweenType.easeInOutSine:
+ setEaseInOutSine(); break;
+ case LeanTweenType.easeInExpo:
+ setEaseInExpo(); break;
+ case LeanTweenType.easeOutExpo:
+ setEaseOutExpo(); break;
+ case LeanTweenType.easeInOutExpo:
+ setEaseInOutExpo(); break;
+ case LeanTweenType.easeInCirc:
+ setEaseInCirc(); break;
+ case LeanTweenType.easeOutCirc:
+ setEaseOutCirc(); break;
+ case LeanTweenType.easeInOutCirc:
+ setEaseInOutCirc(); break;
+ case LeanTweenType.easeInBounce:
+ setEaseInBounce(); break;
+ case LeanTweenType.easeOutBounce:
+ setEaseOutBounce(); break;
+ case LeanTweenType.easeInOutBounce:
+ setEaseInOutBounce(); break;
+ case LeanTweenType.easeInBack:
+ setEaseInBack(); break;
+ case LeanTweenType.easeOutBack:
+ setEaseOutBack(); break;
+ case LeanTweenType.easeInOutBack:
+ setEaseInOutBack(); break;
+ case LeanTweenType.easeInElastic:
+ setEaseInElastic(); break;
+ case LeanTweenType.easeOutElastic:
+ setEaseOutElastic(); break;
+ case LeanTweenType.easeInOutElastic:
+ setEaseInOutElastic(); break;
+ case LeanTweenType.punch:
+ setEasePunch(); break;
+ case LeanTweenType.easeShake:
+ setEaseShake(); break;
+ case LeanTweenType.easeSpring:
+ setEaseSpring(); break;
+ default:
+ setEaseLinear(); break;
+ }
+
+ return this;
+ }
+
+ public LTDescr setEaseLinear(){ this.easeType = LeanTweenType.linear; this.easeMethod = this.easeLinear; return this; }
+
+ public LTDescr setEaseSpring(){ this.easeType = LeanTweenType.easeSpring; this.easeMethod = this.easeSpring; return this; }
+
+ public LTDescr setEaseInQuad(){ this.easeType = LeanTweenType.easeInQuad; this.easeMethod = this.easeInQuad; return this; }
+
+ public LTDescr setEaseOutQuad(){ this.easeType = LeanTweenType.easeOutQuad; this.easeMethod = this.easeOutQuad; return this; }
+
+ public LTDescr setEaseInOutQuad(){ this.easeType = LeanTweenType.easeInOutQuad; this.easeMethod = this.easeInOutQuad; return this;}
+
+ public LTDescr setEaseInCubic(){ this.easeType = LeanTweenType.easeInCubic; this.easeMethod = this.easeInCubic; return this; }
+
+ public LTDescr setEaseOutCubic(){ this.easeType = LeanTweenType.easeOutCubic; this.easeMethod = this.easeOutCubic; return this; }
+
+ public LTDescr setEaseInOutCubic(){ this.easeType = LeanTweenType.easeInOutCubic; this.easeMethod = this.easeInOutCubic; return this; }
+
+ public LTDescr setEaseInQuart(){ this.easeType = LeanTweenType.easeInQuart; this.easeMethod = this.easeInQuart; return this; }
+
+ public LTDescr setEaseOutQuart(){ this.easeType = LeanTweenType.easeOutQuart; this.easeMethod = this.easeOutQuart; return this; }
+
+ public LTDescr setEaseInOutQuart(){ this.easeType = LeanTweenType.easeInOutQuart; this.easeMethod = this.easeInOutQuart; return this; }
+
+ public LTDescr setEaseInQuint(){ this.easeType = LeanTweenType.easeInQuint; this.easeMethod = this.easeInQuint; return this; }
+
+ public LTDescr setEaseOutQuint(){ this.easeType = LeanTweenType.easeOutQuint; this.easeMethod = this.easeOutQuint; return this; }
+
+ public LTDescr setEaseInOutQuint(){ this.easeType = LeanTweenType.easeInOutQuint; this.easeMethod = this.easeInOutQuint; return this; }
+
+ public LTDescr setEaseInSine(){ this.easeType = LeanTweenType.easeInSine; this.easeMethod = this.easeInSine; return this; }
+
+ public LTDescr setEaseOutSine(){ this.easeType = LeanTweenType.easeOutSine; this.easeMethod = this.easeOutSine; return this; }
+
+ public LTDescr setEaseInOutSine(){ this.easeType = LeanTweenType.easeInOutSine; this.easeMethod = this.easeInOutSine; return this; }
+
+ public LTDescr setEaseInExpo(){ this.easeType = LeanTweenType.easeInExpo; this.easeMethod = this.easeInExpo; return this; }
+
+ public LTDescr setEaseOutExpo(){ this.easeType = LeanTweenType.easeOutExpo; this.easeMethod = this.easeOutExpo; return this; }
+
+ public LTDescr setEaseInOutExpo(){ this.easeType = LeanTweenType.easeInOutExpo; this.easeMethod = this.easeInOutExpo; return this; }
+
+ public LTDescr setEaseInCirc(){ this.easeType = LeanTweenType.easeInCirc; this.easeMethod = this.easeInCirc; return this; }
+
+ public LTDescr setEaseOutCirc(){ this.easeType = LeanTweenType.easeOutCirc; this.easeMethod = this.easeOutCirc; return this; }
+
+ public LTDescr setEaseInOutCirc(){ this.easeType = LeanTweenType.easeInOutCirc; this.easeMethod = this.easeInOutCirc; return this; }
+
+ public LTDescr setEaseInBounce(){ this.easeType = LeanTweenType.easeInBounce; this.easeMethod = this.easeInBounce; return this; }
+
+ public LTDescr setEaseOutBounce(){ this.easeType = LeanTweenType.easeOutBounce; this.easeMethod = this.easeOutBounce; return this; }
+
+ public LTDescr setEaseInOutBounce(){ this.easeType = LeanTweenType.easeInOutBounce; this.easeMethod = this.easeInOutBounce; return this; }
+
+ public LTDescr setEaseInBack(){ this.easeType = LeanTweenType.easeInBack; this.easeMethod = this.easeInBack; return this; }
+
+ public LTDescr setEaseOutBack(){ this.easeType = LeanTweenType.easeOutBack; this.easeMethod = this.easeOutBack; return this; }
+
+ public LTDescr setEaseInOutBack(){ this.easeType = LeanTweenType.easeInOutBack; this.easeMethod = this.easeInOutBack; return this; }
+
+ public LTDescr setEaseInElastic(){ this.easeType = LeanTweenType.easeInElastic; this.easeMethod = this.easeInElastic; return this; }
+
+ public LTDescr setEaseOutElastic(){ this.easeType = LeanTweenType.easeOutElastic; this.easeMethod = this.easeOutElastic; return this; }
+
+ public LTDescr setEaseInOutElastic(){ this.easeType = LeanTweenType.easeInOutElastic; this.easeMethod = this.easeInOutElastic; return this; }
+
+ public LTDescr setEasePunch(){ this._optional.animationCurve = LeanTween.punch; this.toInternal.x = this.from.x + this.to.x; this.easeMethod = this.tweenOnCurve; return this; }
+
+ public LTDescr setEaseShake(){ this._optional.animationCurve = LeanTween.shake; this.toInternal.x = this.from.x + this.to.x; this.easeMethod = this.tweenOnCurve; return this; }
+
+ private Vector3 tweenOnCurve(){
+ return new Vector3(this.from.x + (this.diff.x) * this._optional.animationCurve.Evaluate(ratioPassed),
+ this.from.y + (this.diff.y) * this._optional.animationCurve.Evaluate(ratioPassed),
+ this.from.z + (this.diff.z) * this._optional.animationCurve.Evaluate(ratioPassed) );
+ }
+
+ // Vector3 Ease Methods
+
+ private Vector3 easeInOutQuad(){
+ val = this.ratioPassed * 2f;
+
+ if (val < 1f) {
+ val = val * val;
+ return new Vector3( this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+ val = (1f-val) * (val - 3f) + 1f;
+ return new Vector3( this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+
+ private Vector3 easeInQuad(){
+ val = ratioPassed * ratioPassed;
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeOutQuad(){
+ val = this.ratioPassed;
+ val = -val * (val - 2f);
+ return (this.diff * val + this.from);
+ }
+
+ private Vector3 easeLinear(){
+ val = this.ratioPassed;
+ return new Vector3(this.from.x+this.diff.x*val, this.from.y+this.diff.y*val, this.from.z+this.diff.z*val);
+ }
+
+ private Vector3 easeSpring(){
+ val = Mathf.Clamp01(this.ratioPassed);
+ 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) ));
+ return this.from + this.diff * val;
+ }
+
+ private Vector3 easeInCubic(){
+ val = this.ratioPassed * this.ratioPassed * this.ratioPassed;
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeOutCubic(){
+ val = this.ratioPassed - 1f;
+ val = (val * val * val + 1);
+ return new Vector3( this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z) ;
+ }
+
+ private Vector3 easeInOutCubic(){
+ val = this.ratioPassed * 2f;
+ if (val < 1f) {
+ val = val * val * val;
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+ val -= 2f;
+ val = val * val * val + 2f;
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y,this.diffDiv2.z * val + this.from.z);
+ }
+
+ private Vector3 easeInQuart(){
+ val = this.ratioPassed * this.ratioPassed * this.ratioPassed * this.ratioPassed;
+ return diff * val + this.from;
+ }
+
+ private Vector3 easeOutQuart(){
+ val = this.ratioPassed - 1f;
+ val = -(val * val * val * val - 1);
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y,this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeInOutQuart(){
+ val = this.ratioPassed * 2f;
+ if (val < 1f) {
+ val = val * val * val * val;
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+ val -= 2f;
+// val = (val * val * val * val - 2f);
+ return -this.diffDiv2 * (val * val * val * val - 2f) + this.from;
+ }
+
+ private Vector3 easeInQuint(){
+ val = this.ratioPassed;
+ val = val * val * val * val * val;
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeOutQuint(){
+ val = this.ratioPassed - 1f;
+ val = (val * val * val * val * val + 1f);
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeInOutQuint(){
+ val = this.ratioPassed * 2f;
+ if (val < 1f){
+ val = val * val * val * val * val;
+ return new Vector3(this.diffDiv2.x * val + this.from.x,this.diffDiv2.y * val + this.from.y,this.diffDiv2.z * val + this.from.z);
+ }
+ val -= 2f;
+ val = (val * val * val * val * val + 2f);
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+
+ private Vector3 easeInSine(){
+ val = - Mathf.Cos(this.ratioPassed * LeanTween.PI_DIV2);
+ return new Vector3(this.diff.x * val + this.diff.x + this.from.x, this.diff.y * val + this.diff.y + this.from.y, this.diff.z * val + this.diff.z + this.from.z);
+ }
+
+ private Vector3 easeOutSine(){
+ val = Mathf.Sin(this.ratioPassed * LeanTween.PI_DIV2);
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y,this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeInOutSine(){
+ val = -(Mathf.Cos(Mathf.PI * this.ratioPassed) - 1f);
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+
+ private Vector3 easeInExpo(){
+ val = Mathf.Pow(2f, 10f * (this.ratioPassed - 1f));
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeOutExpo(){
+ val = (-Mathf.Pow(2f, -10f * this.ratioPassed) + 1f);
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeInOutExpo(){
+ val = this.ratioPassed * 2f;
+ if (val < 1) return this.diffDiv2 * Mathf.Pow(2, 10 * (val - 1)) + this.from;
+ val--;
+ return this.diffDiv2 * (-Mathf.Pow(2, -10 * val) + 2) + this.from;
+ }
+
+ private Vector3 easeInCirc(){
+ val = -(Mathf.Sqrt(1f - this.ratioPassed * this.ratioPassed) - 1f);
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeOutCirc(){
+ val = this.ratioPassed - 1f;
+ val = Mathf.Sqrt(1f - val * val);
+
+ return new Vector3(this.diff.x * val + this.from.x, this.diff.y * val + this.from.y, this.diff.z * val + this.from.z);
+ }
+
+ private Vector3 easeInOutCirc(){
+ val = this.ratioPassed * 2f;
+ if (val < 1f){
+ val = -(Mathf.Sqrt(1f - val * val) - 1f);
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+ val -= 2f;
+ val = (Mathf.Sqrt(1f - val * val) + 1f);
+ return new Vector3(this.diffDiv2.x * val + this.from.x, this.diffDiv2.y * val + this.from.y, this.diffDiv2.z * val + this.from.z);
+ }
+
+ private Vector3 easeInBounce(){
+ val = this.ratioPassed;
+ val = 1f - val;
+ return new Vector3(this.diff.x - LeanTween.easeOutBounce(0, this.diff.x, val) + this.from.x,
+ this.diff.y - LeanTween.easeOutBounce(0, this.diff.y, val) + this.from.y,
+ this.diff.z - LeanTween.easeOutBounce(0, this.diff.z, val) + this.from.z);
+ }
+
+ private Vector3 easeOutBounce ()
+ {
+ val = ratioPassed;
+ float valM, valN; // bounce values
+ if (val < (valM = 1 - 1.75f * this.overshoot / 2.75f)) {
+ val = 1 / valM / valM * val * val;
+ } else if (val < (valN = 1 - .75f * this.overshoot / 2.75f)) {
+ val -= (valM + valN) / 2;
+ // first bounce, height: 1/4
+ val = 7.5625f * val * val + 1 - .25f * this.overshoot * this.overshoot;
+ } else if (val < (valM = 1 - .25f * this.overshoot / 2.75f)) {
+ val -= (valM + valN) / 2;
+ // second bounce, height: 1/16
+ val = 7.5625f * val * val + 1 - .0625f * this.overshoot * this.overshoot;
+ } else { // valN = 1
+ val -= (valM + 1) / 2;
+ // third bounce, height: 1/64
+ val = 7.5625f * val * val + 1 - .015625f * this.overshoot * this.overshoot;
+ }
+ return this.diff * val + this.from;
+ }
+
+ private Vector3 easeInOutBounce(){
+ val = this.ratioPassed * 2f;
+ if (val < 1f){
+ return new Vector3(LeanTween.easeInBounce(0, this.diff.x, val) * 0.5f + this.from.x,
+ LeanTween.easeInBounce(0, this.diff.y, val) * 0.5f + this.from.y,
+ LeanTween.easeInBounce(0, this.diff.z, val) * 0.5f + this.from.z);
+ }else {
+ val = val - 1f;
+ return new Vector3(LeanTween.easeOutBounce(0, this.diff.x, val) * 0.5f + this.diffDiv2.x + this.from.x,
+ LeanTween.easeOutBounce(0, this.diff.y, val) * 0.5f + this.diffDiv2.y + this.from.y,
+ LeanTween.easeOutBounce(0, this.diff.z, val) * 0.5f + this.diffDiv2.z + this.from.z);
+ }
+ }
+
+ private Vector3 easeInBack(){
+ val = this.ratioPassed;
+ val /= 1;
+ float s = 1.70158f * this.overshoot;
+ return this.diff * (val) * val * ((s + 1) * val - s) + this.from;
+ }
+
+ private Vector3 easeOutBack(){
+ float s = 1.70158f * this.overshoot;
+ val = (this.ratioPassed / 1) - 1;
+ val = ((val) * val * ((s + 1) * val + s) + 1);
+ return this.diff * val + this.from;
+ }
+
+ private Vector3 easeInOutBack(){
+ float s = 1.70158f * this.overshoot;
+ val = this.ratioPassed * 2f;
+ if ((val) < 1){
+ s *= (1.525f) * overshoot;
+ return this.diffDiv2 * (val * val * (((s) + 1) * val - s)) + this.from;
+ }
+ val -= 2;
+ s *= (1.525f) * overshoot;
+ val = ((val) * val * (((s) + 1) * val + s) + 2);
+ return this.diffDiv2 * val + this.from;
+ }
+
+ private Vector3 easeInElastic(){
+ return new Vector3(LeanTween.easeInElastic(this.from.x,this.to.x,this.ratioPassed,this.overshoot,this.period),
+ LeanTween.easeInElastic(this.from.y,this.to.y,this.ratioPassed,this.overshoot,this.period),
+ LeanTween.easeInElastic(this.from.z,this.to.z,this.ratioPassed,this.overshoot,this.period));
+ }
+
+ private Vector3 easeOutElastic(){
+ return new Vector3(LeanTween.easeOutElastic(this.from.x,this.to.x,this.ratioPassed,this.overshoot,this.period),
+ LeanTween.easeOutElastic(this.from.y,this.to.y,this.ratioPassed,this.overshoot,this.period),
+ LeanTween.easeOutElastic(this.from.z,this.to.z,this.ratioPassed,this.overshoot,this.period));
+ }
+
+ private Vector3 easeInOutElastic()
+ {
+ return new Vector3(LeanTween.easeInOutElastic(this.from.x,this.to.x,this.ratioPassed,this.overshoot,this.period),
+ LeanTween.easeInOutElastic(this.from.y,this.to.y,this.ratioPassed,this.overshoot,this.period),
+ LeanTween.easeInOutElastic(this.from.z,this.to.z,this.ratioPassed,this.overshoot,this.period));
+ }
+
+ /**
+ * Set how far past a tween will overshoot for certain ease types (compatible: easeInBack, easeInOutBack, easeOutBack, easeOutElastic, easeInElastic, easeInOutElastic).
+ * @method setOvershoot
+ * @param {float} overshoot:float how far past the destination it will go before settling in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutBack ).setOvershoot(2f);
+ */
+ public LTDescr setOvershoot( float overshoot ){
+ this.overshoot = overshoot;
+ return this;
+ }
+
+ /**
+ * Set how short the iterations are for certain ease types (compatible: easeOutElastic, easeInElastic, easeInOutElastic).
+ * @method setPeriod
+ * @param {float} period:float how short the iterations are that the tween will animate at (default 0.3f)
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutElastic ).setPeriod(0.3f);
+ */
+ public LTDescr setPeriod( float period ){
+ this.period = period;
+ return this;
+ }
+
+ /**
+ * Set how large the effect is for certain ease types (compatible: punch, shake, animation curves).
+ * @method setScale
+ * @param {float} scale:float how much the ease will be multiplied by (default 1f)
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.punch ).setScale(2f);
+ */
+ public LTDescr setScale( float scale ){
+ this.scale = scale;
+ return this;
+ }
+
+ /**
+ * Set the type of easing used for the tween with a custom curve.
+ * @method setEase (AnimationCurve)
+ * @param {AnimationCurve} easeDefinition:AnimationCurve an AnimationCure that describes the type of easing you want, this is great for when you want a unique type of movement
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce );
+ */
+ public LTDescr setEase( AnimationCurve easeCurve ){
+ this._optional.animationCurve = easeCurve;
+ this.easeMethod = this.tweenOnCurve;
+ this.easeType = LeanTweenType.animationCurve;
+ return this;
+ }
+
+ /**
+ * Set the end that the GameObject is tweening towards
+ * @method setTo
+ * @param {Vector3} to:Vector3 point at which you want the tween to reach
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setEase( LeanTweenType.easeInOutBounce );
+ * // Later your want to change your destination or your destiation is constantly moving
+ * descr.setTo( new Vector3(5f,10f,3f) );
+ */
+ public LTDescr setTo( Vector3 to ){
+ if(this.hasInitiliazed){
+ this.to = to;
+ this.diff = to - this.from;
+ }else{
+ this.to = to;
+ }
+
+ return this;
+ }
+
+ public LTDescr setTo( Transform to ){
+ this._optional.toTrans = to;
+ return this;
+ }
+
+ /**
+ * Set the beginning of the tween
+ * @method setFrom
+ * @param {Vector3} from:Vector3 the point you would like the tween to start at
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LTDescr descr = LeanTween.move( cube, Vector3.up, new Vector3(1f,3f,0f), 1.0f ).setFrom( new Vector3(5f,10f,3f) );
+ */
+ public LTDescr setFrom( Vector3 from ){
+ if(this.trans){
+ this.init();
+ }
+ this.from = from;
+ // this.hasInitiliazed = true; // this is set, so that the "from" value isn't overwritten later on when the tween starts
+ this.diff = this.to - this.from;
+ this.diffDiv2 = this.diff * 0.5f;
+ return this;
+ }
+
+ public LTDescr setFrom( float from ){
+ return setFrom( new Vector3(from, 0f, 0f) );
+ }
+
+ public LTDescr setDiff( Vector3 diff ){
+ this.diff = diff;
+ return this;
+ }
+
+ public LTDescr setHasInitialized( bool has ){
+ this.hasInitiliazed = has;
+ return this;
+ }
+
+ public LTDescr setId( uint id, uint global_counter ){
+ this._id = id;
+ this.counter = global_counter;
+ // Debug.Log("Global counter:"+global_counter);
+ return this;
+ }
+
+ /**
+ * Set the point of time the tween will start in
+ * @method setPassed
+ * @param {float} passedTime:float the length of time in seconds the tween will start in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;
+ * // Later
+ * LTDescr descr = description( tweenId );
+ * descr.setPassed( 1f );
+ */
+ public LTDescr setPassed( float passed ){
+ this.passed = passed;
+ return this;
+ }
+
+ /**
+ * Set the finish time of the tween
+ * @method setTime
+ * @param {float} finishTime:float the length of time in seconds you wish the tween to complete in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;
+ * // Later
+ * LTDescr descr = description( tweenId );
+ * descr.setTime( 1f );
+ */
+ public LTDescr setTime( float time ){
+ float passedTimeRatio = this.passed / this.time;
+ this.passed = time * passedTimeRatio;
+ this.time = time;
+ return this;
+ }
+
+ /**
+ * Set the finish time of the tween
+ * @method setSpeed
+ * @param {float} speed:float the speed in unity units per second you wish the object to travel (overrides the given time)
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveLocalZ( gameObject, 10f, 1f).setSpeed(0.2f) // the given time is ignored when speed is set
+ */
+ public LTDescr setSpeed( float speed ){
+ this.speed = speed;
+ if(this.hasInitiliazed)
+ initSpeed();
+ return this;
+ }
+
+ /**
+ * Set the tween to repeat a number of times.
+ * @method setRepeat
+ * @param {int} repeatNum:int the number of times to repeat the tween. -1 to repeat infinite times
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 10 ).setLoopPingPong();
+ */
+ public LTDescr setRepeat( int repeat ){
+ this.loopCount = repeat;
+ if((repeat>1 && this.loopType == LeanTweenType.once) || (repeat < 0 && this.loopType == LeanTweenType.once)){
+ this.loopType = LeanTweenType.clamp;
+ }
+ if(this.type==TweenAction.CALLBACK || this.type==TweenAction.CALLBACK_COLOR){
+ this.setOnCompleteOnRepeat(true);
+ }
+ return this;
+ }
+
+ public LTDescr setLoopType( LeanTweenType loopType ){
+ this.loopType = loopType;
+ return this;
+ }
+
+ public LTDescr setUseEstimatedTime( bool useEstimatedTime ){
+ this.useEstimatedTime = useEstimatedTime;
+ this.usesNormalDt = false;
+ return this;
+ }
+
+ /**
+ * Set ignore time scale when tweening an object when you want the animation to be time-scale independent (ignores the Time.timeScale value). Great for pause screens, when you want all other action to be stopped (or slowed down)
+ * @method setIgnoreTimeScale
+ * @param {bool} useUnScaledTime:bool whether to use the unscaled time or not
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setIgnoreTimeScale( true );
+ */
+ public LTDescr setIgnoreTimeScale( bool useUnScaledTime ){
+ this.useEstimatedTime = useUnScaledTime;
+ this.usesNormalDt = false;
+ return this;
+ }
+
+ /**
+ * Use frames when tweening an object, when you don't want the animation to be time-frame independent...
+ * @method setUseFrames
+ * @param {bool} useFrames:bool whether to use estimated time or not
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseFrames( true );
+ */
+ public LTDescr setUseFrames( bool useFrames ){
+ this.useFrames = useFrames;
+ this.usesNormalDt = false;
+ return this;
+ }
+
+ public LTDescr setUseManualTime( bool useManualTime ){
+ this.useManualTime = useManualTime;
+ this.usesNormalDt = false;
+ return this;
+ }
+
+ public LTDescr setLoopCount( int loopCount ){
+ this.loopType = LeanTweenType.clamp;
+ this.loopCount = loopCount;
+ return this;
+ }
+
+ /**
+ * No looping involved, just run once (the default)
+ * @method setLoopOnce
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopOnce();
+ */
+ public LTDescr setLoopOnce(){ this.loopType = LeanTweenType.once; return this; }
+
+ /**
+ * When the animation gets to the end it starts back at where it began
+ * @method setLoopClamp
+ * @param {int} loops:int (defaults to -1) how many times you want the loop to happen (-1 for an infinite number of times)
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopClamp( 2 );
+ */
+ public LTDescr setLoopClamp(){
+ this.loopType = LeanTweenType.clamp;
+ if(this.loopCount==0)
+ this.loopCount = -1;
+ return this;
+ }
+ public LTDescr setLoopClamp( int loops ){
+ this.loopCount = loops;
+ return this;
+ }
+
+ /**
+ * When the animation gets to the end it then tweens back to where it started (and on, and on)
+ * @method setLoopPingPong
+ * @param {int} loops:int (defaults to -1) how many times you want the loop to happen in both directions (-1 for an infinite number of times). Passing a value of 1 will cause the object to go towards and back from it's destination once.
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopPingPong( 2 );
+ */
+ public LTDescr setLoopPingPong(){
+ this.loopType = LeanTweenType.pingPong;
+ if(this.loopCount==0)
+ this.loopCount = -1;
+ return this;
+ }
+ public LTDescr setLoopPingPong( int loops ) {
+ this.loopType = LeanTweenType.pingPong;
+ this.loopCount = loops == -1 ? loops : loops * 2;
+ return this;
+ }
+
+ /**
+ * Have a method called when the tween finishes
+ * @method setOnComplete
+ * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished(){ }
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished );
+ */
+ public LTDescr setOnComplete( Action onComplete ){
+ this._optional.onComplete = onComplete;
+ this.hasExtraOnCompletes = true;
+ return this;
+ }
+
+ /**
+ * Have a method called when the tween finishes
+ * @method setOnComplete (object)
+ * @param {Action
+ *
+ * @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);
+ }
+ }
+ }
-/**
-* Cancels 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].onComplete != null)
- tweens[i].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);
+ }
}
}
-}
-/**
-* Cancel 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].onComplete != null)
- tweens[i].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 ){
+// 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].ltRect == ltRect && tweens[backId].counter==backCounter)
- 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
-*
-* @method LeanTween.cancel
-* @param {int} id:int unique id that represents that tween
-* @param {bool} callOnComplete:int (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;
- // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type);
- if(tweens[backId].counter==backCounter){
- if(callOnComplete && tweens[backId].onComplete != null)
- tweens[backId].onComplete();
- 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
-*
-* @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 ){
- int backId = uniqueId & 0xFFFF;
- int backCounter = uniqueId >> 16;
-
- if(tweens[backId]!=null && tweens[backId].uniqueId == uniqueId && tweens[backId].counter==backCounter)
- return tweens[backId];
- for(int i = 0; i <= tweenMaxSearch; i++){
- if(tweens[i].uniqueId == uniqueId && tweens[i].counter==backCounter)
- return tweens[i];
- }
- return null;
-}
+ /**
+ * 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 );
-}
+ public static LTDescr description( int uniqueId ){
+ return descr( uniqueId );
+ }
-/**
-* Retrieve a tweens LTDescr object(s) to modify
-*
-* @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) {
+ /**
+ * 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();
@@ -2337,2633 +666,2563 @@ public static LTDescr[] descriptions(GameObject gameObject = null) {
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
-*
-* @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();
- }
-}
+ [System.Obsolete("Use 'pause( id )' instead")]
+ public static void pause( GameObject gameObject, int uniqueId ){
+ pause( uniqueId );
+ }
-/**
-* 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 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 active tweens
-*
-* @method LeanTween.pauseAll
-*/
-public static void pauseAll(){
- init();
- for (int i = 0; i <= tweenMaxSearch; i++){
- tweens[i].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();
+ }
+ }
}
-}
-/**
-* Resume all active tweens
-*
-* @method LeanTween.resumeAll
-*/
-public static void resumeAll(){
- init();
- for (int i = 0; i <= tweenMaxSearch; i++){
- tweens[i].resume();
+ /**
+ * 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();
+ }
}
-}
-[System.Obsolete("Use 'resume( id )' instead")]
-public static void resume( GameObject gameObject, int uniqueId ){
- resume( uniqueId );
-}
+ /**
+ * 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();
+ }
+ }
-/**
-* 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();
- }
-}
+ [System.Obsolete("Use 'resume( id )' instead")]
+ public static void resume( GameObject gameObject, int uniqueId ){
+ resume( uniqueId );
+ }
-/**
-* 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();
- }
-}
+ /**
+ * 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();
+ }
+ }
-/**
-* 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;
-}
+ /**
+ * 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 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;
-}
+ /**
+ * 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( LTRect ltRect ){
- for( int i = 0; i <= tweenMaxSearch; i++){
- if(tweens[i].toggle && tweens[i].ltRect==ltRect)
- return true;
- }
- return false;
-}
+ public static bool isTweening( RectTransform rect ){
+ return isTweening(rect.gameObject);
+ }
-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;
- }
- }
-}
+ /**
+ * 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 object logError( string error ){
- if(throwErrors) Debug.LogError(error); else Debug.Log(error);
- return null;
-}
+ 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;
+ }
-// LeanTween 2.0 Methods
-
-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;
- for(j=0, i = startSearch; j < maxTweens; i++){
- if(i>=maxTweens-1)
- i = 0;
- if(tweens[i].toggle==false){
- if(i+1>tweenMaxSearch)
- tweenMaxSearch = i+1;
- startSearch = i + 1;
- found = true;
- break;
- }
-
- j++;
- 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(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();
- tweens[i].setId( (uint)i );
-
- return tweens[i];
-}
+ 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;
+ }
-public static GameObject tweenEmpty{
- get{
- init(maxTweens);
- return _tweenEmpty;
- }
-}
+ 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 int startSearch = 0;
-public static LTDescr d;
-
-private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, LTDescr tween ){
- init(maxTweens);
- if(gameObject==null || tween==null)
- return null;
-
- tween.trans = gameObject.transform;
- tween.to = to;
- tween.time = time;
- tween.type = tweenAction;
- //tween.hasPhysics = gameObject.rigidbody!=null;
-
- return tween;
-}
+ public static object logError( string error ){
+ if(throwErrors) Debug.LogError(error); else Debug.Log(error);
+ return null;
+ }
-#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
-*
-* @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(), 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, TweenAction.CANVAS_PLAYSPRITE, options().setSprites( sprites ).setRepeat(-1));
-}
-#endif
+ 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;
+ }
-/**
-* 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.
-*
-* @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){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ALPHA, options() );
-}
+ j++;
+ }
+ if(found==false)
+ logError("no available tween found!");
-/**
-* 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, TweenAction.GUI_ALPHA, options().setRect( ltRect ) );
-}
+ // 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 );
-#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
-*
-* @method LeanTween.textAlpha
-* @param {RectTransform} rectTransform:RectTransform RectTransform 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.textAlpha(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, TweenAction.TEXT_ALPHA, options());
-}
-#endif
+ return tweens[i];
+ }
-/**
-* 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, TweenAction.ALPHA_VERTEX, options() );
-}
-/**
-* 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.
-*
-* @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){
- return pushNewTween( gameObject, new Vector3(1.0f, to.a, 0.0f), time, TweenAction.COLOR, options().setPoint( new Vector3(to.r, to.g, to.b) ) );
-}
+ public static GameObject tweenEmpty{
+ get{
+ init(maxTweens);
+ return _tweenEmpty;
+ }
+ }
-#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
-*
-* @method LeanTween.textColor
-* @param {RectTransform} rectTransform:RectTransform RectTransform that you wish to fade
-* @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.textColor(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, TweenAction.TEXT_COLOR, options().setPoint(new Vector3(to.r, to.g, to.b)));
-}
-#endif
+ public static int startSearch = 0;
+ public static LTDescr d;
-public static LTDescr delayedCall( float delayTime, Action callback){
- return pushNewTween( tweenEmpty, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback) );
-}
+ private static LTDescr pushNewTween( GameObject gameObject, Vector3 to, float time, LTDescr tween ){
+ init(maxTweens);
+ if(gameObject==null || tween==null)
+ return null;
-public static LTDescr delayedCall( float delayTime, Action callback){
- return pushNewTween( tweenEmpty, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback) );
-}
+ tween.trans = gameObject.transform;
+ tween.to = to;
+ tween.time = time;
-public static LTDescr delayedCall( GameObject gameObject, float delayTime, Action callback){
- return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback) );
-}
+ if (tween.time <= 0f)
+ tween.updateInternal();
+ //tween.hasPhysics = gameObject.rigidbody!=null;
-public static LTDescr delayedCall( GameObject gameObject, float delayTime, Action callback){
- return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback) );
-}
+ return tween;
+ }
-public static LTDescr destroyAfter( LTRect rect, float delayTime){
- return pushNewTween( tweenEmpty, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setRect( rect ).setDestroyOnComplete(true) );
-}
+ #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
-/*public static LTDescr delayedCall(GameObject gameObject, float delayTime, string callback){
- return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete( callback ) );
-}*/
+ /**
+ * 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;
+ }
-/**
-* Move a GameObject to a certain location
-*
-* @method LeanTween.move
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
-* @param {Vector3} vec:Vector3 to The final positin with which to move to
-* @param {float} time:float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.move(gameObject, new Vector3(0f,-3f,5f), 2.0f) .setEase( LeanTweenType.easeOutQuad );
-*/
-public static LTDescr move(GameObject gameObject, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.MOVE, options() );
-}
-public static LTDescr move(GameObject gameObject, Vector2 to, float time){
- return pushNewTween( gameObject, new Vector3(to.x, to.y, gameObject.transform.position.z), time, TweenAction.MOVE, options() );
-}
+ /**
+ * 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;
+ }
-/**
-* Move a GameObject along a set of bezier curves
-*
-* @method LeanTween.move
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
-* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle2,Handle1,Point2,...
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Javascript:
-* 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);
-* C#:
-* 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);;
-*/
-public static LTDescr move(GameObject gameObject, Vector3[] to, float time){
- d = options();
- if(d.path==null)
- d.path = new LTBezierPath( to );
- else
- d.path.setPoints( to );
-
- return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED, d );
-}
-public static LTDescr move(GameObject gameObject, LTBezierPath to, float time) {
- d = options();
- d.path = to;
+ /**
+ * 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 ) );
+ }
- return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED, d);
-}
-public static LTDescr move(GameObject gameObject, LTSpline to, float time) {
- d = options();
- d.spline = to;
+ #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());
+ }
- return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE, d);
-}
+ /**
+ * 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
-/**
-* Move a GameObject through a set of points
-*
-* @method LeanTween.moveSpline
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
-* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd 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.
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Javascript:
-* 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);
-* C#:
-* 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);
-*/
-public static LTDescr moveSpline(GameObject gameObject, Vector3[] to, float time){
- d = options();
- d.spline = new LTSpline( to );
+ /**
+ * 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() );
+ }
- return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE, d );
-}
+ /**
+ * 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;
+ }
-/**
-* Move a GameObject through a set of points, in local space
-*
-* @method LeanTween.moveSplineLocal
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
-* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Javascript:
-* 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);
-* C#:
-* 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);
-*/
-public static LTDescr moveSplineLocal(GameObject gameObject, Vector3[] to, float time){
- d = options();
- d.spline = new LTSpline( to );
+ #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
- return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, d );
-}
+ /**
+ * 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) );
+ }
-/**
-* Move a GUI Element to a certain location
-*
-* @method LeanTween.move (GUI)
-* @param {LTRect} ltRect:LTRect ltRect LTRect object that you wish to move
-* @param {Vector2} vec:Vector2 to The final position with which to move to (pixel coordinates)
-* @param {float} time:float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr move(LTRect ltRect, Vector2 to, float time){
- return pushNewTween( tweenEmpty, to, time, TweenAction.GUI_MOVE, options().setRect( ltRect ) );
-}
+ public static LTDescr delayedCall( float delayTime, Action callback){
+ return pushNewTween( tweenEmpty, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
+ }
-public static LTDescr moveMargin(LTRect ltRect, Vector2 to, float time){
- return pushNewTween( tweenEmpty, to, time, TweenAction.GUI_MOVE_MARGIN, options().setRect( ltRect ) );
-}
+ public static LTDescr delayedCall( GameObject gameObject, float delayTime, Action callback){
+ return pushNewTween( gameObject, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
+ }
-/**
-* Move a GameObject along the x-axis
-*
-* @method LeanTween.moveX
-* @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to move
-* @param {float} to:float to The final position with which to move to
-* @param {float} time:float time The time to complete the move in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr moveX(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_X, options() );
-}
+ public static LTDescr delayedCall( GameObject gameObject, float delayTime, Action callback){
+ return pushNewTween( gameObject, Vector3.zero, delayTime, options().setCallback().setOnComplete(callback) );
+ }
-/**
-* Move a GameObject along the y-axis
-*
-* @method LeanTween.moveY
-* @param {GameObject} GameObject gameObject Gameobject that you wish to move
-* @param {float} float to The final position with which to move to
-* @param {float} float time The time to complete the move in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr moveY(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_Y, options() );
-}
+ public static LTDescr destroyAfter( LTRect rect, float delayTime){
+ return pushNewTween( tweenEmpty, Vector3.zero, delayTime, options().setCallback().setRect( rect ).setDestroyOnComplete(true) );
+ }
-/**
-* Move a GameObject along the z-axis
-*
-* @method LeanTween.moveZ
-* @param {GameObject} GameObject gameObject Gameobject that you wish to move
-* @param {float} float to The final position with which to move to
-* @param {float} float time The time to complete the move in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr moveZ(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_Z, options() );
-}
+ /*public static LTDescr delayedCall(GameObject gameObject, float delayTime, string callback){
+ return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete( callback ) );
+ }*/
-/**
-* Move a GameObject to a certain location relative to the parent transform.
-*
-* @method LeanTween.moveLocal
-* @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
-* @param {Vector3} Vector3 to The final positin with which to move to
-* @param {float} float time The time to complete the tween in
-* @param {Hashtable} Hashtable optional Hashtable where you can pass optional items.
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr moveLocal(GameObject gameObject, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.MOVE_LOCAL, options() );
-}
-/**
-* Move a GameObject along a set of bezier curves, in local space
-*
-* @method LeanTween.moveLocal
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to move
-* @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,...
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Javascript:
-* 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);
-* C#:
-* LeanTween.move(gameObject, new Vector3[]{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
-*/
-public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time){
- d = options();
- if(d.path==null)
- d.path = new LTBezierPath( to );
- else
- d.path.setPoints( to );
-
- return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED_LOCAL, d );
-}
+ /**
+ * Move a GameObject to a certain location Move a GameObject to a certain location
+ *
+ * @method LeanTween.move
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {Vector3} vec:Vector3 to The final positin with which to move to
+ * @param {float} time:float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.move(gameObject, new Vector3(0f,-3f,5f), 2.0f) .setEase( LeanTweenType.easeOutQuad );
+ */
+ public static LTDescr move(GameObject gameObject, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setMove() );
+ }
+ public static LTDescr move(GameObject gameObject, Vector2 to, float time){
+ return pushNewTween( gameObject, new Vector3(to.x, to.y, gameObject.transform.position.z), time, options().setMove() );
+ }
-public static LTDescr moveLocalX(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_X, options() );
-}
-public static LTDescr moveLocalY(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_Y, options() );
-}
+ /**
+ * Move a GameObject along a set of bezier curves Move a GameObject along a set of bezier curves
+ *
+ * @method LeanTween.move
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle2,Handle1,Point2,...
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Javascript:
+ * 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);
+ * C#:
+ * 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);;
+ */
+ public static LTDescr move(GameObject gameObject, Vector3[] to, float time){
+ d = options().setMoveCurved();
+ if(d.optional.path==null)
+ d.optional.path = new LTBezierPath( to );
+ else
+ d.optional.path.setPoints( to );
+
+ return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
+ }
-public static LTDescr moveLocalZ(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_Z, options() );
-}
+ public static LTDescr move(GameObject gameObject, LTBezierPath to, float time) {
+ d = options().setMoveCurved();
+ d.optional.path = to;
-public static LTDescr moveLocal(GameObject gameObject, LTBezierPath to, float time) {
- d = options();
- d.path = to;
+ return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
+ }
- return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED_LOCAL, d);
-}
-public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time) {
- d = options();
- d.spline = to;
-
- return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, d);
-}
+ public static LTDescr move(GameObject gameObject, LTSpline to, float time) {
+ d = options().setMoveSpline();
+ d.optional.spline = to;
-/**
-* Rotate a GameObject, to values are in passed in degrees
-*
-* @method LeanTween.rotate
-* @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
-* @param {Vector3} Vector3 to The final rotation with which to rotate to
-* @param {float} float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.rotate(cube, new Vector3(180f,30f,0f), 1.5f);
-*/
+ return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
+ }
-public static LTDescr rotate(GameObject gameObject, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.ROTATE, options() );
-}
+ /**
+ * Move a GameObject through a set of points Move a GameObject through a set of points
+ *
+ * @method LeanTween.moveSpline
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd 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.
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Javascript:
+ * 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);
+ * C#:
+ * 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);
+ */
+ public static LTDescr moveSpline(GameObject gameObject, Vector3[] to, float time){
+ d = options().setMoveSpline();
+ d.optional.spline = new LTSpline( to );
+
+ return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
+ }
-/**
-* Rotate a GUI element (using an LTRect object), to a value that is in degrees
-*
-* @method LeanTween.rotate
-* @param {LTRect} ltRect:LTRect LTRect that you wish to rotate
-* @param {float} to:float The final rotation with which to rotate to
-* @param {float} time:float The time to complete the tween in
-* @param {Array} optional:Array Object Array where you can pass optional items.
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* if(GUI.Button(buttonRect.rect, "Rotate"))
-* LeanTween.rotate( buttonRect4, 150.0f, 1.0f).setEase(LeanTweenType.easeOutElastic);
-* GUI.matrix = Matrix4x4.identity;
-*/
-public static LTDescr rotate(LTRect ltRect, float to, float time){
- return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, TweenAction.GUI_ROTATE, options().setRect( ltRect ) );
-}
+ /**
+ * Move a GameObject through a set of points Move a GameObject through a set of points
+ *
+ * @method LeanTween.moveSpline
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {LTSpline} spline:LTSpline pass a pre-existing LTSpline for the object to move along
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Javascript:
+ * LeanTween.moveSpline(gameObject, ltSpline, 2.0) .setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
+ * C#:
+ * LeanTween.moveSpline(gameObject, ltSpline, 1.5f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
+ */
+ public static LTDescr moveSpline(GameObject gameObject, LTSpline to, float time){
+ d = options().setMoveSpline();
+ d.optional.spline = to;
+
+ return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
+ }
-/**
-* Rotate a GameObject in the objects local space (on the transforms localEulerAngles object)
-*
-* @method LeanTween.rotateLocal
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
-* @param {Vector3} to:Vector3 The final rotation with which to rotate to
-* @param {float} time:float The time to complete the rotation in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr rotateLocal(GameObject gameObject, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.ROTATE_LOCAL, options() );
-}
+ /**
+ * Move a GameObject through a set of points, in local space Move a GameObject through a set of points, in local space
+ *
+ * @method LeanTween.moveSplineLocal
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Javascript:
+ * 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);
+ * C#:
+ * 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);
+ */
+ public static LTDescr moveSplineLocal(GameObject gameObject, Vector3[] to, float time){
+ d = options().setMoveSplineLocal();
+ d.optional.spline = new LTSpline( to );
+
+ return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
+ }
-/**
-* Rotate a GameObject only on the X axis
-*
-* @method LeanTween.rotateX
-* @param {GameObject} GameObject Gameobject that you wish to rotate
-* @param {float} to:float The final x-axis rotation with which to rotate
-* @param {float} time:float The time to complete the rotation in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr rotateX(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ROTATE_X, options() );
-}
+ /**
+ * Move a GUI Element to a certain location Move a GUI Element to a certain location
+ *
+ * @method LeanTween.move (GUI)
+ * @param {LTRect} ltRect:LTRect ltRect LTRect object that you wish to move
+ * @param {Vector2} vec:Vector2 to The final position with which to move to (pixel coordinates)
+ * @param {float} time:float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr move(LTRect ltRect, Vector2 to, float time){
+ return pushNewTween( tweenEmpty, to, time, options().setGUIMove().setRect( ltRect ) );
+ }
-/**
-* Rotate a GameObject only on the Y axis
-*
-* @method LeanTween.rotateY
-* @param {GameObject} GameObject Gameobject that you wish to rotate
-* @param {float} to:float The final y-axis rotation with which to rotate
-* @param {float} time:float The time to complete the rotation in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr rotateY(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ROTATE_Y, options() );
-}
+ public static LTDescr moveMargin(LTRect ltRect, Vector2 to, float time){
+ return pushNewTween( tweenEmpty, to, time, options().setGUIMoveMargin().setRect( ltRect ) );
+ }
-/**
-* Rotate a GameObject only on the Z axis
-*
-* @method LeanTween.rotateZ
-* @param {GameObject} GameObject Gameobject that you wish to rotate
-* @param {float} to:float The final z-axis rotation with which to rotate
-* @param {float} time:float The time to complete the rotation in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr rotateZ(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ROTATE_Z, options() );
-}
+ /**
+ * Move a GameObject along the x-axis Move a GameObject along the x-axis
+ *
+ * @method LeanTween.moveX
+ * @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to move
+ * @param {float} to:float to The final position with which to move to
+ * @param {float} time:float time The time to complete the move in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr moveX(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveX() );
+ }
-/**
-* Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees)
-*
-* @method LeanTween.rotateAround
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
-* @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
-* @param {float} degrees:float the degrees in which to rotate
-* @param {float} time:float time The time to complete the rotation in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example:
-* LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
-*/
-public static LTDescr rotateAround(GameObject gameObject, Vector3 axis, float add, float time){
- return pushNewTween( gameObject, new Vector3(add,0f,0f), time, TweenAction.ROTATE_AROUND, options().setAxis(axis) );
-}
+ /**
+ * Move a GameObject along the y-axis Move a GameObject along the y-axis
+ *
+ * @method LeanTween.moveY
+ * @param {GameObject} GameObject gameObject Gameobject that you wish to move
+ * @param {float} float to The final position with which to move to
+ * @param {float} float time The time to complete the move in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr moveY(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveY() );
+ }
-/**
-* Rotate a GameObject around a certain Axis in Local Space (the best method to use when you want to rotate beyond 180 degrees)
-*
-* @method LeanTween.rotateAroundLocal
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
-* @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
-* @param {float} degrees:float the degrees in which to rotate
-* @param {float} time:float time The time to complete the rotation in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example:
-* LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
-*/
-public static LTDescr rotateAroundLocal(GameObject gameObject, Vector3 axis, float add, float time){
- return pushNewTween( gameObject, new Vector3(add,0f,0f), time, TweenAction.ROTATE_AROUND_LOCAL, options().setAxis(axis) );
-}
+ /**
+ * Move a GameObject along the z-axis Move a GameObject along the z-axis
+ *
+ * @method LeanTween.moveZ
+ * @param {GameObject} GameObject gameObject Gameobject that you wish to move
+ * @param {float} float to The final position with which to move to
+ * @param {float} float time The time to complete the move in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr moveZ(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveZ() );
+ }
-/**
-* Scale a GameObject to a certain size
-*
-* @method LeanTween.scale
-* @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to scale
-* @param {Vector3} vec:Vector3 to The size with which to tween to
-* @param {float} time:float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr scale(GameObject gameObject, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.SCALE, options() );
-}
-
-/**
-* Scale a GUI Element to a certain width and height
-*
-* @method LeanTween.scale (GUI)
-* @param {LTRect} LTRect ltRect LTRect object that you wish to move
-* @param {Vector2} Vector2 to The final width and height to scale to (pixel based)
-* @param {float} float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
-* LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 ).setEase(LeanTweenType.easeOutBounce);
-* function OnGUI(){
-* if(GUI.Button(bRect.rect, "Scale")){ }
-* }
-*
-* Example C#:
-* LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
-* LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f ).setEase(LeanTweenType.easeOutBounce);
-* void OnGUI(){
-* if(GUI.Button(bRect.rect, "Scale")){ }
-* }
-*/
-public static LTDescr scale(LTRect ltRect, Vector2 to, float time){
- return pushNewTween( tweenEmpty, to, time, TweenAction.GUI_SCALE, options().setRect( ltRect ) );
-}
+ /**
+ * Move a GameObject to a certain location relative to the parent transform. Move a GameObject to a certain location relative to the parent transform.
+ *
+ * @method LeanTween.moveLocal
+ * @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
+ * @param {Vector3} Vector3 to The final positin with which to move to
+ * @param {float} float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr moveLocal(GameObject gameObject, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setMoveLocal() );
+ }
-/**
-* Scale a GameObject to a certain size along the x-axis only
-*
-* @method LeanTween.scaleX
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
-* @param {float} scaleTo:float the size with which to scale to
-* @param {float} time:float the time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr scaleX(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_X, options() );
-}
+ /**
+ * Move a GameObject along a set of bezier curves, in local space Move a GameObject along a set of bezier curves, in local space
+ *
+ * @method LeanTween.moveLocal
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,...
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Javascript:
+ * 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);
+ * C#:
+ * 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);
+ */
+ public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time){
+ d = options().setMoveCurvedLocal();
+ if(d.optional.path==null)
+ d.optional.path = new LTBezierPath( to );
+ else
+ d.optional.path.setPoints( to );
+
+ return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, d );
+ }
-/**
-* Scale a GameObject to a certain size along the y-axis only
-*
-* @method LeanTween.scaleY
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
-* @param {float} scaleTo:float the size with which to scale to
-* @param {float} time:float the time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr scaleY(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Y, options() );
-}
+ public static LTDescr moveLocalX(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveLocalX() );
+ }
-/**
-* Scale a GameObject to a certain size along the z-axis only
-*
-* @method LeanTween.scaleZ
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
-* @param {float} scaleTo:float the size with which to scale to
-* @param {float} time:float the time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr scaleZ(GameObject gameObject, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Z, options());
-}
+ public static LTDescr moveLocalY(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveLocalY() );
+ }
-/**
-* Tween any particular value (float)
-*
-* @method LeanTween.value (float)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {float} from:float The original value to start the tween from
-* @param {Vector3} to:float The final float with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( function( val:float ){
-* Debug.Log("tweened val:"+val);
-* } );
-*
-* Example C#:
-* LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( (float val)=>{
-* Debug.Log("tweened val:"+val);
-* } );
-*/
-public static LTDescr value(GameObject gameObject, float from, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setFrom( new Vector3(from,0,0) ) );
-}
+ public static LTDescr moveLocalZ(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setMoveLocalZ() );
+ }
-/**
-* Tween any particular value (Vector2)
-*
-* @method LeanTween.value (Vector2)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {Vector2} from:Vector2 The original value to start the tween from
-* @param {Vector3} to:Vector2 The final Vector2 with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, new Vector2(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( function( val:Vector2 ){
-* Debug.Log("tweened val:"+val);
-* } );
-*
-* Example C#:
-* LeanTween.value( gameObject, new Vector3(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( (Vector2 val)=>{
-* Debug.Log("tweened val:"+val);
-* } );
-*/
-public static LTDescr value(GameObject gameObject, Vector2 from, Vector2 to, float time){
- return pushNewTween( gameObject, new Vector3(to.x,to.y,0), time, TweenAction.VALUE3, options().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0) ) );
-}
+ public static LTDescr moveLocal(GameObject gameObject, LTBezierPath to, float time) {
+ d = options().setMoveCurvedLocal();
+ d.optional.path = to;
-/**
-* Tween any particular value (Vector3)
-*
-* @method LeanTween.value (Vector3)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {Vector3} from:Vector3 The original value to start the tween from
-* @param {Vector3} to:Vector3 The final Vector3 with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( function( val:Vector3 ){
-* Debug.Log("tweened val:"+val);
-* } );
-*
-* Example C#:
-* LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( (Vector3 val)=>{
-* Debug.Log("tweened val:"+val);
-* } );
-*/
-public static LTDescr value(GameObject gameObject, Vector3 from, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.VALUE3, options().setFrom( from ) );
-}
+ return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
+ }
+ public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time) {
+ d = options().setMoveSplineLocal();
+ d.optional.spline = to;
-/**
-* Tween any particular value (Color)
-*
-* @method LeanTween.value (Color)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {Color} from:Color The original value to start the tween from
-* @param {Color} to:Color The final Color with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( function( val:Color ){
-* Debug.Log("tweened val:"+val);
-* } );
-*
-* Example C#:
-* LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( (Color val)=>{
-* Debug.Log("tweened val:"+val);
-* } );
-*/
-public static LTDescr value(GameObject gameObject, Color from, Color to, float time){
- return pushNewTween( gameObject, new Vector3(1f, to.a, 0f), time, TweenAction.CALLBACK_COLOR, options().setPoint( new Vector3(to.r, to.g, to.b) )
- .setFromColor(from).setHasInitialized(false)
- );
-}
+ return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
+ }
-/**
-* Tween any particular value, it does not need to be tied to any particular type or GameObject
-*
-* @method LeanTween.value (float)
-* @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
-* @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( float val ){ }
-* @param {float} float from The original value to start the tween from
-* @param {float} float to The value to end the tween on
-* @param {float} float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
-* function updateValueExampleCallback( val:float ){
-* Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");
-* }
-*
-* Example C#:
-* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
-* void updateValueExampleCallback( float val ){
-* Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");
-* }
-*/
+ /**
+ * Move a GameObject to another transform Move a GameObject to another transform
+ *
+ * @method LeanTween.move
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to move
+ * @param {Transform} destination:Transform Transform whose position the tween will finally end on
+ * @param {float} time:float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.move(gameObject, anotherTransform, 2.0f) .setEase( LeanTweenType.easeOutQuad );
+ */
+ public static LTDescr move(GameObject gameObject, Transform to, float time){
+ return pushNewTween(gameObject, Vector3.zero, time, options().setTo(to).setMoveToTransform() );
+ }
-public static LTDescr value(GameObject gameObject, Action callOnUpdate, float from, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setTo( new Vector3(to,0,0) ).setFrom( new Vector3(from,0,0) ).setOnUpdate(callOnUpdate) );
-}
+ /**
+ * Rotate a GameObject, to values are in passed in degrees Rotate a GameObject, to values are in passed in degrees
+ *
+ * @method LeanTween.rotate
+ * @param {GameObject} GameObject gameObject Gameobject that you wish to rotate
+ * @param {Vector3} Vector3 to The final rotation with which to rotate to
+ * @param {float} float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.rotate(cube, new Vector3(180f,30f,0f), 1.5f);
+ */
+
+ public static LTDescr rotate(GameObject gameObject, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setRotate() );
+ }
-/**
-* Tweens any float value, it does not need to be tied to any particular type or GameObject
-*
-* @method LeanTween.value (float)
-* @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
-* @param {Action} callOnUpdateRatio:Action Function that's called every Update frame. It must accept two float values ex: function updateValue( float val, float ratio){ }
-* @param {float} float from The original value to start the tween from
-* @param {float} float to The value to end the tween on
-* @param {float} float time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
-* function updateValueExampleCallback( val:float, ratio:float ){
-* Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);
-* }
-*
-* Example C#:
-* LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
-* void updateValueExampleCallback( float val, float ratio ){
-* Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);
-* }
-*/
+ /**
+ * Rotate a GUI element (using an LTRect object), to a value that is in degrees Rotate a GUI element (using an LTRect object), to a value that is in degrees
+ *
+ * @method LeanTween.rotate
+ * @param {LTRect} ltRect:LTRect LTRect that you wish to rotate
+ * @param {float} to:float The final rotation with which to rotate to
+ * @param {float} time:float The time to complete the tween in
+ * @param {Array} optional:Array Object Array where you can pass optional items.
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * if(GUI.Button(buttonRect.rect, "Rotate"))
+ * LeanTween.rotate( buttonRect4, 150.0f, 1.0f).setEase(LeanTweenType.easeOutElastic);
+ * GUI.matrix = Matrix4x4.identity;
+ */
+ public static LTDescr rotate(LTRect ltRect, float to, float time){
+ return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, options().setGUIRotate().setRect( ltRect ) );
+ }
-public static LTDescr value(GameObject gameObject, Action callOnUpdateRatio, float from, float to, float time) {
- return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.CALLBACK, options().setTo(new Vector3(to, 0, 0)).setFrom(new Vector3(from, 0, 0)).setOnUpdateRatio(callOnUpdateRatio));
-}
+ /**
+ * Rotate a GameObject in the objects local space (on the transforms localEulerAngles object) Rotate a GameObject in the objects local space (on the transforms localEulerAngles object)
+ *
+ * @method LeanTween.rotateLocal
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
+ * @param {Vector3} to:Vector3 The final rotation with which to rotate to
+ * @param {float} time:float The time to complete the rotation in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr rotateLocal(GameObject gameObject, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setRotateLocal() );
+ }
-/**
-* Tween from one color to another
-*
-* @method LeanTween.value (Color)
-* @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
-* @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a color value ex: function updateValue( Color val ){ }
-* @param {Color} Color from The original value to start the tween from
-* @param {Color} Color to The value to end the tween on
-* @param {Color} Color time The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example
-* Example Javascript:
-* LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);
-* function updateValueExampleCallback( val:Color ){
-* Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");
-* }
-*
-* Example C#:
-* LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);
-* void updateValueExampleCallback( Color val ){
-* Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");
-* }
-*/
+ /**
+ * Rotate a GameObject only on the X axis Rotate a GameObject only on the X axis
+ *
+ * @method LeanTween.rotateX
+ * @param {GameObject} GameObject Gameobject that you wish to rotate
+ * @param {float} to:float The final x-axis rotation with which to rotate
+ * @param {float} time:float The time to complete the rotation in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr rotateX(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setRotateX() );
+ }
-public static LTDescr value(GameObject gameObject, Action callOnUpdate, Color from, Color to, float time){
- return pushNewTween( gameObject, new Vector3(1.0f,to.a,0.0f), time, TweenAction.CALLBACK_COLOR, options().setPoint( new Vector3(to.r, to.g, to.b) )
- .setAxis( new Vector3(from.r, from.g, from.b) ).setFrom( new Vector3(0.0f, from.a, 0.0f) ).setHasInitialized(false).setOnUpdateColor(callOnUpdate) );
-}
+ /**
+ * Rotate a GameObject only on the Y axis Rotate a GameObject only on the Y axis
+ *
+ * @method LeanTween.rotateY
+ * @param {GameObject} GameObject Gameobject that you wish to rotate
+ * @param {float} to:float The final y-axis rotation with which to rotate
+ * @param {float} time:float The time to complete the rotation in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr rotateY(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setRotateY() );
+ }
-/**
-* Tween any particular value (Vector2), this could be used to tween an arbitrary value like offset property
-*
-* @method LeanTween.value (Vector2)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
-* @param {float} from:Vector2 The original value to start the tween from
-* @param {Vector2} to:Vector2 The final Vector3 with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr value(GameObject gameObject, Action callOnUpdate, Vector2 from, Vector2 to, float time){
- return pushNewTween( gameObject, new Vector3(to.x,to.y,0f), time, TweenAction.VALUE3, options().setTo( new Vector3(to.x,to.y,0f) ).setFrom( new Vector3(from.x,from.y,0f) ).setOnUpdateVector2(callOnUpdate) );
-}
+ /**
+ * Rotate a GameObject only on the Z axis Rotate a GameObject only on the Z axis
+ *
+ * @method LeanTween.rotateZ
+ * @param {GameObject} GameObject Gameobject that you wish to rotate
+ * @param {float} to:float The final z-axis rotation with which to rotate
+ * @param {float} time:float The time to complete the rotation in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr rotateZ(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setRotateZ() );
+ }
-/**
-* Tween any particular value (Vector3), this could be used to tween an arbitrary property that uses a Vector
-*
-* @method LeanTween.value (Vector3)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
-* @param {float} from:Vector3 The original value to start the tween from
-* @param {Vector3} to:Vector3 The final Vector3 with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr value(GameObject gameObject, Action callOnUpdate, Vector3 from, Vector3 to, float time){
- return pushNewTween( gameObject, to, time, TweenAction.VALUE3, options().setTo( to ).setFrom( from ).setOnUpdateVector3(callOnUpdate) );
-}
+ /**
+ * Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees) Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees)
+ *
+ * @method LeanTween.rotateAround
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
+ * @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
+ * @param {float} degrees:float the degrees in which to rotate
+ * @param {float} time:float time The time to complete the rotation in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example:
+ * LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
+ */
+ public static LTDescr rotateAround(GameObject gameObject, Vector3 axis, float add, float time){
+ return pushNewTween( gameObject, new Vector3(add,0f,0f), time, options().setAxis(axis).setRotateAround() );
+ }
-/**
-* Tween any particular value (float)
-*
-* @method LeanTween.value (float,object)
-* @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
-* @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val, object obj ){ }
-* @param {float} from:float The original value to start the tween from
-* @param {Vector3} to:float The final Vector3 with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-*/
-public static LTDescr value(GameObject gameObject, Action callOnUpdate, float from, float to, float time){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, options().setTo( new Vector3(to,0,0) ).setFrom( new Vector3(from,0,0) ).setOnUpdateObject(callOnUpdate) );
-}
+ /**
+ * Rotate a GameObject around a certain Axis in Local Space (the best method to use when you want to rotate beyond 180 degrees) Rotate a GameObject around a certain Axis in Local Space (the best method to use when you want to rotate beyond 180 degrees)
+ *
+ * @method LeanTween.rotateAroundLocal
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate
+ * @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up
+ * @param {float} degrees:float the degrees in which to rotate
+ * @param {float} time:float time The time to complete the rotation in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example:
+ * LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f );
+ */
+ public static LTDescr rotateAroundLocal(GameObject gameObject, Vector3 axis, float add, float time){
+ return pushNewTween( gameObject, new Vector3(add,0f,0f), time, options().setRotateAroundLocal().setAxis(axis) );
+ }
-public static LTDescr delayedSound( AudioClip audio, Vector3 pos, float volume ){
- //Debug.LogError("Delay sound??");
- return pushNewTween( tweenEmpty, pos, 0f, TweenAction.DELAYED_SOUND, options().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) );
-}
+ /**
+ * Scale a GameObject to a certain size Scale a GameObject to a certain size
+ *
+ * @method LeanTween.scale
+ * @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to scale
+ * @param {Vector3} vec:Vector3 to The size with which to tween to
+ * @param {float} time:float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr scale(GameObject gameObject, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setScale() );
+ }
-public static LTDescr delayedSound( GameObject gameObject, AudioClip audio, Vector3 pos, float volume ){
- //Debug.LogError("Delay sound??");
- return pushNewTween( gameObject, pos, 0f, TweenAction.DELAYED_SOUND, options().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) );
-}
+ /**
+ * Scale a GUI Element to a certain width and height Scale a GUI Element to a certain width and height
+ *
+ * @method LeanTween.scale (GUI)
+ * @param {LTRect} LTRect ltRect LTRect object that you wish to move
+ * @param {Vector2} Vector2 to The final width and height to scale to (pixel based)
+ * @param {float} float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
+ * LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 ).setEase(LeanTweenType.easeOutBounce);
+ * function OnGUI(){
+ * if(GUI.Button(bRect.rect, "Scale")){ }
+ * }
+ *
+ * Example C#:
+ * LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
+ * LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f ).setEase(LeanTweenType.easeOutBounce);
+ * void OnGUI(){
+ * if(GUI.Button(bRect.rect, "Scale")){ }
+ * }
+ */
+ public static LTDescr scale(LTRect ltRect, Vector2 to, float time){
+ return pushNewTween( tweenEmpty, to, time, options().setGUIScale().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
+ /**
+ * Scale a GameObject to a certain size along the x-axis only Scale a GameObject to a certain size along the x-axis only
+ *
+ * @method LeanTween.scaleX
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
+ * @param {float} scaleTo:float the size with which to scale to
+ * @param {float} time:float the time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr scaleX(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setScaleX() );
+ }
-/**
-* Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.move (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {Vector3} to:Vector3 The final Vector3 with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.move(gameObject.GetComponent<RectTransform>(), new Vector3(200f,-100f,0f), 1f).setDelay(1f);
-*/
-public static LTDescr move(RectTransform rectTrans, Vector3 to, float time){
- return pushNewTween( rectTrans.gameObject, to, time, TweenAction.CANVAS_MOVE, options().setRect( rectTrans ) );
-}
+ /**
+ * Scale a GameObject to a certain size along the y-axis only Scale a GameObject to a certain size along the y-axis only
+ *
+ * @method LeanTween.scaleY
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
+ * @param {float} scaleTo:float the size with which to scale to
+ * @param {float} time:float the time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr scaleY(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setScaleY() );
+ }
-/**
-* Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.moveX (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The final x location with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.moveX(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
-*/
-public static LTDescr moveX(RectTransform rectTrans, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_MOVE_X, options().setRect( rectTrans ) );
-}
+ /**
+ * Scale a GameObject to a certain size along the z-axis only Scale a GameObject to a certain size along the z-axis only
+ *
+ * @method LeanTween.scaleZ
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale
+ * @param {float} scaleTo:float the size with which to scale to
+ * @param {float} time:float the time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr scaleZ(GameObject gameObject, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setScaleZ());
+ }
-/**
-* Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.moveY (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The final y location with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.moveY(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
-*/
-public static LTDescr moveY(RectTransform rectTrans, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_MOVE_Y, options().setRect( rectTrans ) );
-}
+ /**
+ * Tween any particular value (float) Tween any particular value (float)
+ *
+ * @method LeanTween.value (float)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {float} from:float The original value to start the tween from
+ * @param {Vector3} to:float The final float with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( function( val:float ){
+ * Debug.Log("tweened val:"+val);
+ * } );
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( (float val)=>{
+ * Debug.Log("tweened val:"+val);
+ * } );
+ */
+ public static LTDescr value(GameObject gameObject, float from, float to, float time){
+ return pushNewTween( gameObject, new Vector3(to,0,0), time, options().setCallback().setFrom( new Vector3(from,0,0) ) );
+ }
+ public static LTDescr value(float from, float to, float time){
+ return pushNewTween( tweenEmpty, new Vector3(to,0,0), time, options().setCallback().setFrom( new Vector3(from,0,0) ) );
+ }
-/**
-* Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.moveZ (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The final x location with which to tween to
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.moveZ(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
-*/
-public static LTDescr moveZ(RectTransform rectTrans, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_MOVE_Z, options().setRect( rectTrans ) );
-}
+ /**
+ * Tween any particular value (Vector2)
+ *
+ * @method LeanTween.value (Vector2)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {Vector2} from:Vector2 The original value to start the tween from
+ * @param {Vector3} to:Vector2 The final Vector2 with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, new Vector2(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( function( val:Vector2 ){
+ * Debug.Log("tweened val:"+val);
+ * } );
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, new Vector3(1f,0f), new Vector3(5f,0f), 5f).setOnUpdate( (Vector2 val)=>{
+ * Debug.Log("tweened val:"+val);
+ * } );
+ */
+ public static LTDescr value(GameObject gameObject, Vector2 from, Vector2 to, float time){
+ 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) ) );
+ }
-/**
-* Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.rotate (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The degree with which to rotate the RectTransform
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.rotate(gameObject.GetComponent<RectTransform>(), 90f, 1f).setDelay(1f);
-*/
-public static LTDescr rotate(RectTransform rectTrans, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_ROTATEAROUND, options().setRect( rectTrans ).setAxis(Vector3.forward) );
-}
+ /**
+ * Tween any particular value (Vector3)
+ *
+ * @method LeanTween.value (Vector3)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {Vector3} from:Vector3 The original value to start the tween from
+ * @param {Vector3} to:Vector3 The final Vector3 with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( function( val:Vector3 ){
+ * Debug.Log("tweened val:"+val);
+ * } );
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, new Vector3(1f,0f,0f), new Vector3(5f,0f,0f), 5f).setOnUpdate( (Vector3 val)=>{
+ * Debug.Log("tweened val:"+val);
+ * } );
+ */
+ public static LTDescr value(GameObject gameObject, Vector3 from, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setValue3().setFrom( from ) );
+ }
-/**
-* Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.rotateAround (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {Vector3} axis:Vector3 The axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
-* @param {float} to:float The degree with which to rotate the RectTransform
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.rotateAround(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f);
-*/
-public static LTDescr rotateAround(RectTransform rectTrans, Vector3 axis, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_ROTATEAROUND, options().setRect( rectTrans ).setAxis(axis) );
-}
+ /**
+ * Tween any particular value (Color)
+ *
+ * @method LeanTween.value (Color)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {Color} from:Color The original value to start the tween from
+ * @param {Color} to:Color The final Color with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( function( val:Color ){
+ * Debug.Log("tweened val:"+val);
+ * } );
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, Color.red, Color.yellow, 5f).setOnUpdate( (Color val)=>{
+ * Debug.Log("tweened val:"+val);
+ * } );
+ */
+ public static LTDescr value(GameObject gameObject, Color from, Color to, float time){
+ LTDescr lt = pushNewTween( gameObject, new Vector3(1f, to.a, 0f), time, options().setCallbackColor().setPoint( new Vector3(to.r, to.g, to.b) )
+ .setFromColor(from).setHasInitialized(false) );
+
+ #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;
+ }
-/**
-* Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.rotateAroundLocal (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {Vector3} axis:Vector3 The local axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
-* @param {float} to:float The degree with which to rotate the RectTransform
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.rotateAroundLocal(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f);
-*/
-public static LTDescr rotateAroundLocal(RectTransform rectTrans, Vector3 axis, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_ROTATEAROUND_LOCAL, options().setRect( rectTrans ).setAxis(axis) );
-}
+ /**
+ * Tween any particular value, it does not need to be tied to any particular type or GameObject
+ *
+ * @method LeanTween.value (float)
+ * @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
+ * @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( float val ){ }
+ * @param {float} float from The original value to start the tween from
+ * @param {float} float to The value to end the tween on
+ * @param {float} float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
+ * function updateValueExampleCallback( val:float ){
+ * Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");
+ * }
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
+ * void updateValueExampleCallback( float val ){
+ * Debug.Log("tweened value:"+val+" set this to whatever variable you are tweening...");
+ * }
+ */
+
+ public static LTDescr value(GameObject gameObject, Action callOnUpdate, float from, float to, float time){
+ 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) );
+ }
-/**
-* Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.scale (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The final Vector3 with which to tween to (localScale)
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.scale(gameObject.GetComponent<RectTransform>(), gameObject.GetComponent<RectTransform>().localScale*2f, 1f).setDelay(1f);
-*/
-public static LTDescr scale(RectTransform rectTrans, Vector3 to, float time){
- return pushNewTween( rectTrans.gameObject, to, time, TweenAction.CANVAS_SCALE, options().setRect( rectTrans ) );
-}
+ /**
+ * Tweens any float value, it does not need to be tied to any particular type or GameObject
+ *
+ * @method LeanTween.value (float)
+ * @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
+ * @param {Action} callOnUpdateRatio:Action Function that's called every Update frame. It must accept two float values ex: function updateValue( float val, float ratio){ }
+ * @param {float} float from The original value to start the tween from
+ * @param {float} float to The value to end the tween on
+ * @param {float} float time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
+ * function updateValueExampleCallback( val:float, ratio:float ){
+ * Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);
+ * }
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, updateValueExampleCallback, 180f, 270f, 1f).setEase(LeanTweenType.easeOutElastic);
+ * void updateValueExampleCallback( float val, float ratio ){
+ * Debug.Log("tweened value:"+val+" percent complete:"+ratio*100);
+ * }
+ */
+
+ public static LTDescr value(GameObject gameObject, Action callOnUpdateRatio, float from, float to, float time) {
+ 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));
+ }
-/**
-* Alpha an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.alpha (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The final Vector3 with which to tween to (localScale)
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.alpha(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f);
-*/
-public static LTDescr alpha(RectTransform rectTrans, float to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, TweenAction.CANVAS_ALPHA, options().setRect( rectTrans ) );
-}
+ /**
+ * Tween from one color to another
+ *
+ * @method LeanTween.value (Color)
+ * @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
+ * @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a color value ex: function updateValue( Color val ){ }
+ * @param {Color} Color from The original value to start the tween from
+ * @param {Color} Color to The value to end the tween on
+ * @param {Color} Color time The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example
+ * Example Javascript:
+ * LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);
+ * function updateValueExampleCallback( val:Color ){
+ * Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");
+ * }
+ *
+ * Example C#:
+ * LeanTween.value( gameObject, updateValueExampleCallback, Color.red, Color.green, 1f).setEase(LeanTweenType.easeOutElastic);
+ * void updateValueExampleCallback( Color val ){
+ * Debug.Log("tweened color:"+val+" set this to whatever variable you are tweening...");
+ * }
+ */
+
+ public static LTDescr value(GameObject gameObject, Action callOnUpdate, Color from, Color to, float time){
+ return pushNewTween( gameObject, new Vector3(1.0f,to.a,0.0f), time, options().setCallbackColor().setPoint( new Vector3(to.r, to.g, to.b) )
+ .setAxis( new Vector3(from.r, from.g, from.b) ).setFrom( new Vector3(0.0f, from.a, 0.0f) ).setHasInitialized(false).setOnUpdateColor(callOnUpdate) );
+ }
+ public static LTDescr value(GameObject gameObject, Action callOnUpdate, Color from, Color to, float time){
+ return pushNewTween( gameObject, new Vector3(1.0f,to.a,0.0f), time, options().setCallbackColor().setPoint( new Vector3(to.r, to.g, to.b) )
+ .setAxis( new Vector3(from.r, from.g, from.b) ).setFrom( new Vector3(0.0f, from.a, 0.0f) ).setHasInitialized(false).setOnUpdateColor(callOnUpdate) );
+ }
-/**
-* Change the Color of an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
-*
-* @method LeanTween.alpha (RectTransform)
-* @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
-* @param {float} to:float The final Vector3 with which to tween to (localScale)
-* @param {float} time:float The time to complete the tween in
-* @return {LTDescr} LTDescr an object that distinguishes the tween
-* @example LeanTween.color(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f);
-*/
-public static LTDescr color(RectTransform rectTrans, Color to, float time){
- return pushNewTween( rectTrans.gameObject, new Vector3(1.0f, to.a, 0.0f), time, TweenAction.CANVAS_COLOR, options().setRect( rectTrans ).setPoint( new Vector3(to.r, to.g, to.b) ) );
-}
+ /**
+ * Tween any particular value (Vector2), this could be used to tween an arbitrary value like offset property
+ *
+ * @method LeanTween.value (Vector2)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
+ * @param {float} from:Vector2 The original value to start the tween from
+ * @param {Vector2} to:Vector2 The final Vector3 with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr value(GameObject gameObject, Action callOnUpdate, Vector2 from, Vector2 to, float time){
+ 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) );
+ }
-#endif
-
-#if LEANTWEEN_1
-// LeanTween 1.x Methods
-
-public static Hashtable h( object[] arr ){
- if(arr.Length%2==1){
- logError("LeanTween - You have attempted to create a Hashtable with an odd number of values.");
- return null;
- }
- Hashtable hash = new Hashtable();
- for(i = 0; i < arr.Length; i += 2){
- hash.Add(arr[i] as string, arr[i+1]);
- }
-
- return hash;
-}
+ /**
+ * Tween any particular value (Vector3), this could be used to tween an arbitrary property that uses a Vector
+ *
+ * @method LeanTween.value (Vector3)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val ){ }
+ * @param {float} from:Vector3 The original value to start the tween from
+ * @param {Vector3} to:Vector3 The final Vector3 with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr value(GameObject gameObject, Action callOnUpdate, Vector3 from, Vector3 to, float time){
+ return pushNewTween( gameObject, to, time, options().setValue3().setTo( to ).setFrom( from ).setOnUpdateVector3(callOnUpdate) );
+ }
-private static int idFromUnique( int uniqueId ){
- return uniqueId & 0xFFFF;
-}
+ /**
+ * Tween any particular value (float)
+ *
+ * @method LeanTween.value (float,object)
+ * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to
+ * @param {Action} callOnUpdate:Action The function that is called on every Update frame, this function needs to accept a float value ex: function updateValue( Vector3 val, object obj ){ }
+ * @param {float} from:float The original value to start the tween from
+ * @param {Vector3} to:float The final Vector3 with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ */
+ public static LTDescr value(GameObject gameObject, Action callOnUpdate, float from, float to, float time){
+ 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) );
+ }
-private static int pushNewTween( GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, Hashtable optional ){
- init(maxTweens);
- if(gameObject==null)
- return -1;
-
- j = 0;
- for(i = startSearch; j < maxTweens; i++){
- if(i>=maxTweens-1)
- i = 0;
- if(tweens[i].toggle==false){
- if(i+1>tweenMaxSearch)
- tweenMaxSearch = i+1;
- startSearch = i + 1;
- break;
- }
-
- j++;
- if(j>=maxTweens){
- 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)+" );");
- return -1;
- }
- }
- LTDescr tween = tweens[i];
- tween.toggle = true;
- tween.reset();
- tween.trans = gameObject.transform;
- tween.to = to;
- tween.time = time;
- tween.type = tweenAction;
- tween.optional = optional;
- tween.setId( (uint)i );
- //tween.hasPhysics = gameObject.rigidbody!=null;
-
- if(optional!=null){
- var ease = optional["ease"];
- //LeanTweenType ease;
- var optionsNotUsed = 0;
- if(ease!=null) {
- tween.tweenType = LeanTweenType.linear;
- if( ease.GetType() ==typeof( LeanTweenType) ){
- tween.tweenType = (LeanTweenType)ease;// Enum.Parse(typeof(LeanTweenType), optional["ease"].ToString());
- } else if(ease.GetType() == typeof(AnimationCurve)){
- tween.animationCurve = optional["ease"] as AnimationCurve;
- } else{
- string func = optional["ease"].ToString();
- if(func.Equals("easeOutQuad")){
- tween.tweenType = LeanTweenType.easeOutQuad;
- }else if(func.Equals("easeInQuad")){
- tween.tweenType = LeanTweenType.easeInQuad;
- }else if(func.Equals("easeInOutQuad")){
- tween.tweenType = LeanTweenType.easeInOutQuad;
- }
- }
- optionsNotUsed++;
- }
- if(optional["rect"]!=null){
- tween.ltRect = (LTRect)optional["rect"];
- optionsNotUsed++;
- }
- if(optional["path"]!=null){
- tween.path = (LTBezierPath)optional["path"];
- optionsNotUsed++;
- }
- if(optional["delay"]!=null){
- tween.delay = (float)optional["delay"];
- optionsNotUsed++;
- }
- if(optional["useEstimatedTime"]!=null){
- tween.useEstimatedTime =(bool) optional["useEstimatedTime"];
- optionsNotUsed++;
- }
- if(optional["useFrames"]!=null){
- tween.useFrames =(bool) optional["useFrames"];
- optionsNotUsed++;
- }
- if(optional["loopType"]!=null){
- tween.loopType = (LeanTweenType)optional["loopType"];
- optionsNotUsed++;
- }
- if(optional["repeat"]!=null){
- tween.loopCount = (int)optional["repeat"];
- if(tween.loopType==LeanTweenType.once)
- tween.loopType = LeanTweenType.clamp;
- optionsNotUsed++;
- }
- if(optional["point"]!=null){
- tween.point = (Vector3)optional["point"];
- optionsNotUsed++;
- }
- if(optional["axis"]!=null){
- tween.axis = (Vector3)optional["axis"];
- optionsNotUsed++;
- }
- if(optional.Count <= optionsNotUsed)
- tween.optional = null; // nothing else is used with the extra piece, so set to null
- }else{
- tween.optional = null;
- }
- //Debug.Log("pushing new tween["+i+"]:"+tweens[i]);
-
- return tweens[i].uniqueId;
-}
+ public static LTDescr delayedSound( AudioClip audio, Vector3 pos, float volume ){
+ //Debug.LogError("Delay sound??");
+ return pushNewTween( tweenEmpty, pos, 0f, options().setDelayedSound().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) );
+ }
-public static int value(string callOnUpdate, float from, float to, float time, Hashtable optional){
- return value( tweenEmpty, callOnUpdate, from, to, time, optional );
-}
-public static int value(GameObject gameObject, string callOnUpdate, float from, float to, float time){
- return value(gameObject, callOnUpdate, from, to, time, new Hashtable());
-}
-public static int value(GameObject gameObject, string callOnUpdate, float from, float to, float time, object[] optional){
- return value(gameObject, callOnUpdate, from, to, time, h(optional));
-}
-public static int value(GameObject gameObject, Action callOnUpdate, float from, float to, float time, object[] optional){
- return value(gameObject, callOnUpdate, from, to, time, h(optional));
-}
-public static int value(GameObject gameObject, Action callOnUpdate, float from, float to, float time, object[] optional){
- return value(gameObject, callOnUpdate, from, to, time, h(optional));
-}
-public static int value(GameObject gameObject,string callOnUpdate, float from, float to, float time, Hashtable optional){
- if(optional==null || optional.Count == 0)
- optional = new Hashtable();
-
- optional["onUpdate"] = callOnUpdate;
- int id = idFromUnique( pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, optional ) );
- tweens[id].from = new Vector3(from,0,0);
- return id;
-}
-public static int value(GameObject gameObject,Action callOnUpdate, float from, float to, float time, Hashtable optional){
- if(optional==null || optional.Count == 0)
- optional = new Hashtable();
-
- optional["onUpdate"] = callOnUpdate;
- int id = idFromUnique( pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, optional ) );
- tweens[id].from = new Vector3(from,0,0);
- return id;
-}
-public static int value(GameObject gameObject,Action callOnUpdate, float from, float to, float time, Hashtable optional){
- if(optional==null || optional.Count == 0)
- optional = new Hashtable();
-
- optional["onUpdate"] = callOnUpdate;
- int id = idFromUnique( pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.CALLBACK, optional ) );
- tweens[id].from = new Vector3(from,0,0);
- return id;
-}
-public static int value(GameObject gameObject, String callOnUpdate, Vector3 from, Vector3 to, float time, Hashtable optional){
- if(optional==null || optional.Count==0)
- optional = new Hashtable();
-
- optional["onUpdate"] = callOnUpdate;
- int id = idFromUnique( pushNewTween( gameObject, to, time, TweenAction.VALUE3, optional ) );
- tweens[id].from = from;
- return id;
-}
-public static int value(GameObject gameObject, String callOnUpdate, Vector3 from, Vector3 to, float time, object[] optional){
- return value(gameObject, callOnUpdate, from, to, time, h(optional));
-}
-public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, Hashtable optional){
- if(optional==null || optional.Count==0)
- optional = new Hashtable();
-
- optional["onUpdate"] = callOnUpdate;
- int id = idFromUnique( pushNewTween( gameObject, to, time, TweenAction.VALUE3, optional ) );
- tweens[id].from = from;
- return id;
-}
-public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, Hashtable optional){
- if(optional==null || optional.Count==0)
- optional = new Hashtable();
-
- optional["onUpdate"] = callOnUpdate;
- int id = idFromUnique( pushNewTween( gameObject, to, time, TweenAction.VALUE3, optional ) );
- tweens[id].from = from;
- return id;
-}
-public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, object[] optional){
- return value(gameObject, callOnUpdate, from, to, time, h(optional));
-}
-public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, object[] optional){
- return value(gameObject, callOnUpdate, from, to, time, h(optional));
-}
-public static int rotate(GameObject gameObject, Vector3 to, float time, Hashtable optional){
- return pushNewTween( gameObject, to, time, TweenAction.ROTATE, optional );
-}
-public static int rotate(GameObject gameObject, Vector3 to, float time, object[] optional){
- return rotate( gameObject, to, time, h( optional ) );
-}
-public static int rotate(LTRect ltRect, float to, float time, Hashtable optional){
- init();
- if( optional==null || optional.Count == 0 )
- optional = new Hashtable();
+ public static LTDescr delayedSound( GameObject gameObject, AudioClip audio, Vector3 pos, float volume ){
+ //Debug.LogError("Delay sound??");
+ return pushNewTween( gameObject, pos, 0f, options().setDelayedSound().setTo( pos ).setFrom( new Vector3(volume,0,0) ).setAudio( audio ) );
+ }
- optional["rect"] = ltRect;
- return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, TweenAction.GUI_ROTATE, optional );
-}
-public static int rotate(LTRect ltRect, float to, float time, object[] optional){
- return rotate( ltRect, to, time, h(optional) );
-}
-public static int rotateX(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ROTATE_X, optional );
-}
-public static int rotateX(GameObject gameObject, float to, float time, object[] optional){
- return rotateX( gameObject, to, time, h(optional) );
-}
-public static int rotateY(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ROTATE_Y, optional );
-}
-public static int rotateY(GameObject gameObject, float to, float time, object[] optional){
- return rotateY( gameObject, to, time, h(optional) );
-}
-public static int rotateZ(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ROTATE_Z, optional );
-}
-public static int rotateZ(GameObject gameObject, float to, float time, object[] optional){
- return rotateZ( gameObject, to, time, h(optional) );
-}
-public static int rotateLocal(GameObject gameObject, Vector3 to, float time, Hashtable optional){
- return pushNewTween( gameObject, to, time, TweenAction.ROTATE_LOCAL, optional );
-}
-public static int rotateLocal(GameObject gameObject, Vector3 to, float time, object[] optional){
- return rotateLocal( gameObject, to, time, h(optional) );
-}
-public static int rotateAround(GameObject gameObject, Vector3 axis, float add, float time, Hashtable optional){
- if(optional==null || optional.Count==0)
- optional = new Hashtable();
-
- optional["axis"] = axis;
- if(optional["point"]==null)
- optional["point"] = Vector3.zero;
-
- return pushNewTween( gameObject, new Vector3(add,0f,0f), time, TweenAction.ROTATE_AROUND, optional );
-}
-public static int rotateAround(GameObject gameObject, Vector3 axis, float add, float time, object[] optional){
- return rotateAround(gameObject, axis, add, time, h(optional));
-}
-public static int moveX(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_X, optional );
-}
-public static int moveX(GameObject gameObject, float to, float time, object[] optional){
- return moveX( gameObject, to, time, h(optional) );
-}
-public static int moveY(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_Y, optional );
-}
-public static int moveY(GameObject gameObject, float to, float time, object[] optional){
- return moveY( gameObject, to, time, h(optional) );
-}
-public static int moveZ(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_Z, optional );
-}
-public static int moveZ(GameObject gameObject, float to, float time, object[] optional){
- return moveZ( gameObject, to, time, h(optional) );
-}
-public static int move(GameObject gameObject, Vector3 to, float time, Hashtable optional){
- return pushNewTween( gameObject, to, time, TweenAction.MOVE, optional );
-}
-public static int move(GameObject gameObject, Vector3 to, float time, object[] optional){
- return move( gameObject, to, time, LeanTween.h( optional ) );
-}
-public static int move(GameObject gameObject, Vector3[] to, float time, Hashtable optional){
- if(to.Length<4){
- string errorMsg = "LeanTween - When passing values for a vector path, you must pass four or more values!";
- if(throwErrors) Debug.LogError(errorMsg); else Debug.Log(errorMsg);
- return -1;
- }
- if(to.Length%4!=0){
- string errorMsg2 = "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2...";
- if(throwErrors) Debug.LogError(errorMsg2); else Debug.Log(errorMsg2);
- return -1;
- }
-
- init();
- if( optional==null || optional.Count == 0 )
- optional = new Hashtable();
-
- LTBezierPath ltPath = new LTBezierPath( to );
- if(optional["orientToPath"]!=null)
- ltPath.orientToPath = true;
- optional["path"] = ltPath;
-
- return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED, optional );
-}
-public static int move(GameObject gameObject, Vector3[] to, float time, object[] optional){
- return move( gameObject, to, time, LeanTween.h( optional ) );
-}
+ #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
-public static int move(LTRect ltRect, Vector2 to, float time, Hashtable optional){
- init();
- if( optional==null || optional.Count == 0 )
- optional = new Hashtable();
+ /**
+ * Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Move a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.move (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {Vector3} to:Vector3 The final Vector3 with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.move(gameObject.GetComponent<RectTransform>(), new Vector3(200f,-100f,0f), 1f).setDelay(1f);
+ */
+ public static LTDescr move(RectTransform rectTrans, Vector3 to, float time){
+ return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasMove().setRect( rectTrans ) );
+ }
- optional["rect"] = ltRect;
- return pushNewTween( tweenEmpty, to, time, TweenAction.GUI_MOVE, optional );
-}
-public static int move(LTRect ltRect, Vector3 to, float time, object[] optional){
- return move( ltRect, to, time, LeanTween.h( optional ) );
-}
-
-public static int moveLocal(GameObject gameObject, Vector3 to, float time, Hashtable optional){
- return pushNewTween( gameObject, to, time, TweenAction.MOVE_LOCAL, optional );
-}
-public static int moveLocal(GameObject gameObject, Vector3 to, float time, object[] optional){
- return moveLocal( gameObject, to, time, LeanTween.h( optional ) );
-}
+ /**
+ * Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Move a RectTransform object affecting x-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.moveX (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {float} to:float The final x location with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.moveX(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
+ */
+ public static LTDescr moveX(RectTransform rectTrans, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasMoveX().setRect( rectTrans ) );
+ }
-public static int moveLocal(GameObject gameObject, Vector3[] to, float time, Hashtable optional){
- if(to.Length<4){
- string errorMsg = "LeanTween - When passing values for a vector path, you must pass four or more values!";
- if(throwErrors) Debug.LogError(errorMsg); else Debug.Log(errorMsg);
- return -1;
- }
- if(to.Length%4!=0){
- string errorMsg2 = "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2...";
- if(throwErrors) Debug.LogError(errorMsg2); else Debug.Log(errorMsg2);
- return -1;
- }
-
- init();
- if( optional == null )
- optional = new Hashtable();
-
- LTBezierPath ltPath = new LTBezierPath( to );
- if(optional["orientToPath"]!=null)
- ltPath.orientToPath = true;
- optional["path"] = ltPath;
-
- return pushNewTween( gameObject, new Vector3(1.0f,0.0f,0.0f), time, TweenAction.MOVE_CURVED_LOCAL, optional );
-}
-public static int moveLocal(GameObject gameObject, Vector3[] to, float time,object[] optional){
- return moveLocal( gameObject, to, time, LeanTween.h( optional ) );
-}
-public static int moveLocalX(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_X, optional );
-}
-public static int moveLocalX(GameObject gameObject, float to, float time, object[] optional){
- return moveLocalX( gameObject, to, time, h(optional) );
-}
-public static int moveLocalY(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_Y, optional );
-}
-public static int moveLocalY(GameObject gameObject, float to, float time, object[] optional){
- return moveLocalY( gameObject, to, time, h(optional) );
-}
-public static int moveLocalZ(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.MOVE_LOCAL_Z, optional );
-}
-public static int moveLocalZ(GameObject gameObject, float to, float time, object[] optional){
- return moveLocalZ( gameObject, to, time, h(optional) );
-}
-public static int scale(GameObject gameObject, Vector3 to, float time, Hashtable optional){
- return pushNewTween( gameObject, to, time, TweenAction.SCALE, optional );
-}
-public static int scale(GameObject gameObject, Vector3 to, float time, object[] optional){
- return scale( gameObject, to, time, h(optional) );
-}
-public static int scale(LTRect ltRect,Vector2 to, float time, Hashtable optional)
-{
- init();
- if( optional==null || optional.Count == 0 )
- optional = new Hashtable();
-
- optional["rect"] = ltRect;
- return pushNewTween( tweenEmpty, to, time, TweenAction.GUI_SCALE, optional );
-}
-public static int scale(LTRect ltRect, Vector2 to, float time, object[] optional){
- return scale( ltRect, to, time, h(optional) );
-}
-public static int alpha(LTRect ltRect, float to, float time, Hashtable optional){
- init();
- if( optional==null || optional.Count == 0 )
- optional = new Hashtable();
-
- ltRect.alphaEnabled = true;
- optional["rect"] = ltRect;
- return pushNewTween( tweenEmpty, new Vector3(to,0f,0f), time, TweenAction.GUI_ALPHA, optional );
-}
-public static int alpha(LTRect ltRect, float to, float time, object[] optional){
- return alpha( ltRect, to, time, h(optional) );
-}
-public static int scaleX(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_X, optional );
-}
-public static int scaleX(GameObject gameObject, float to, float time, object[] optional){
- return scaleX( gameObject, to, time, h(optional) );
-}
-public static int scaleY(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Y, optional );
-}
-public static int scaleY(GameObject gameObject, float to, float time, object[] optional){
- return scaleY( gameObject, to, time, h(optional) );
-}
-public static int scaleZ(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.SCALE_Z, optional );
-}
-public static int scaleZ(GameObject gameObject, float to, float time, object[] optional){
- return scaleZ( gameObject, to, time, h(optional) );
-}
-public static int delayedCall( float delayTime, string callback, Hashtable optional ){
- init();
- return delayedCall( tweenEmpty, delayTime, callback, optional );
-}
-public static int delayedCall( float delayTime, Action callback, object[] optional){
- init();
- return delayedCall( tweenEmpty, delayTime, callback, h(optional) );
-}
-public static int delayedCall( GameObject gameObject, float delayTime, string callback, object[] optional){
- return delayedCall( gameObject, delayTime, callback, h(optional) );
-}
-public static int delayedCall( GameObject gameObject, float delayTime, Action callback, object[] optional){
- return delayedCall( gameObject, delayTime, callback, h(optional) );
-}
-public static int delayedCall( GameObject gameObject, float delayTime, string callback, Hashtable optional){
- if(optional==null || optional.Count == 0)
- optional = new Hashtable();
- optional["onComplete"] = callback;
+ /**
+ * Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Move a RectTransform object affecting y-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.moveY (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {float} to:float The final y location with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.moveY(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
+ */
+ public static LTDescr moveY(RectTransform rectTrans, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasMoveY().setRect( rectTrans ) );
+ }
- return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional );
-}
-public static int delayedCall( GameObject gameObject, float delayTime, Action callback, Hashtable optional){
- if(optional==null)
- optional = new Hashtable();
- optional["onComplete"] = callback;
+ /**
+ * Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Move a RectTransform object affecting z-axis only (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)n
+ *
+ * @method LeanTween.moveZ (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {float} to:float The final x location with which to tween to
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.moveZ(gameObject.GetComponent<RectTransform>(), 200f, 1f).setDelay(1f);
+ */
+ public static LTDescr moveZ(RectTransform rectTrans, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasMoveZ().setRect( rectTrans ) );
+ }
- return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional );
-}
-public static int delayedCall( GameObject gameObject, float delayTime, Action callback, Hashtable optional){
- if(optional==null)
- optional = new Hashtable();
- optional["onComplete"] = callback;
+ /**
+ * Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.rotate (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {float} to:float The degree with which to rotate the RectTransform
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.rotate(gameObject.GetComponent<RectTransform>(), 90f, 1f).setDelay(1f);
+ */
+ public static LTDescr rotate(RectTransform rectTrans, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasRotateAround().setRect( rectTrans ).setAxis(Vector3.forward) );
+ }
- return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional );
-}
-public static int alpha(GameObject gameObject, float to, float time, Hashtable optional){
- return pushNewTween( gameObject, new Vector3(to,0,0), time, TweenAction.ALPHA, optional );
-}
-public static int alpha(GameObject gameObject, float to, float time, object[] optional){
- return alpha(gameObject, to, time, h(optional));
-}
-#endif
+ public static LTDescr rotate(RectTransform rectTrans, Vector3 to, float time){
+ return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasRotateAround().setRect( rectTrans ).setAxis(Vector3.forward) );
+ }
-// Tweening Functions - Thanks to Robert Penner and GFX47
+ /**
+ * Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Rotate a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.rotateAround (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {Vector3} axis:Vector3 The axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
+ * @param {float} to:float The degree with which to rotate the RectTransform
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.rotateAround(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f);
+ */
+ public static LTDescr rotateAround(RectTransform rectTrans, Vector3 axis, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasRotateAround().setRect( rectTrans ).setAxis(axis) );
+ }
-private static float tweenOnCurve( LTDescr tweenDescr, float ratioPassed ){
- // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed));
- return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed);
-}
+ /**
+ * Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Rotate a RectTransform object around it's local axis (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.rotateAroundLocal (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {Vector3} axis:Vector3 The local axis in which to rotate the RectTransform (Vector3.forward is most commonly used)
+ * @param {float} to:float The degree with which to rotate the RectTransform
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.rotateAroundLocal(gameObject.GetComponent<RectTransform>(), Vector3.forward, 90f, 1f).setDelay(1f);
+ */
+ public static LTDescr rotateAroundLocal(RectTransform rectTrans, Vector3 axis, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasRotateAroundLocal().setRect( rectTrans ).setAxis(axis) );
+ }
-private static Vector3 tweenOnCurveVector( LTDescr tweenDescr, float ratioPassed ){
- return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed),
- tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.animationCurve.Evaluate(ratioPassed),
- tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.animationCurve.Evaluate(ratioPassed) );
-}
+ /**
+ * Scale a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Scale a RectTransform object (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.scale (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {Vector3} to:Vector3 The final Vector3 with which to tween to (localScale)
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.scale(gameObject.GetComponent<RectTransform>(), gameObject.GetComponent<RectTransform>().localScale*2f, 1f).setDelay(1f);
+ */
+ public static LTDescr scale(RectTransform rectTrans, Vector3 to, float time){
+ return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasScale().setRect( rectTrans ) );
+ }
-private static float easeOutQuadOpt( float start, float diff, float ratioPassed ){
- return -diff * ratioPassed * (ratioPassed - 2) + start;
-}
+ /**
+ * Change the sizeDelta of a RectTransform object (used in Unity Canvas, for Buttons, Panel, Scrollbar, etc...) Change the sizeDelta of a RectTransform object (used in Unity Canvas, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.size (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {Vector2} to:Vector2 The final Vector2 the tween will end at for sizeDelta property
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.size(gameObject.GetComponent<RectTransform>(), gameObject.GetComponent<RectTransform>().sizeDelta*2f, 1f).setDelay(1f);
+ */
+ public static LTDescr size(RectTransform rectTrans, Vector2 to, float time){
+ return pushNewTween( rectTrans.gameObject, to, time, options().setCanvasSizeDelta().setRect( rectTrans ) );
+ }
-private static float easeInQuadOpt( float start, float diff, float ratioPassed ){
- return diff * ratioPassed * ratioPassed + start;
-}
+ /**
+ * Alpha an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Alpha an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.alpha (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {float} to:float The final Vector3 with which to tween to (localScale)
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.alpha(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f);
+ */
+ public static LTDescr alpha(RectTransform rectTrans, float to, float time){
+ return pushNewTween( rectTrans.gameObject, new Vector3(to,0f,0f), time, options().setCanvasAlpha().setRect( rectTrans ) );
+ }
-private static float easeInOutQuadOpt( float start, float diff, float ratioPassed ){
- ratioPassed /= .5f;
- if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
- ratioPassed--;
- return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
-}
+ /**
+ * Change the Color of an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...) Change the Color of an Image Component attached to a RectTransform (used in Unity GUI in 4.6+, for Buttons, Panel, Scrollbar, etc...)
+ *
+ * @method LeanTween.alpha (RectTransform)
+ * @param {RectTransform} rectTrans:RectTransform RectTransform that you wish to attach the tween to
+ * @param {float} to:float The final Vector3 with which to tween to (localScale)
+ * @param {float} time:float The time to complete the tween in
+ * @return {LTDescr} LTDescr an object that distinguishes the tween
+ * @example LeanTween.color(gameObject.GetComponent<RectTransform>(), 0.5f, 1f).setDelay(1f);
+ */
+ public static LTDescr color(RectTransform rectTrans, Color to, float time){
+ 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) ) );
+ }
-private static float linear(float start, float end, float val){
- return Mathf.Lerp(start, end, val);
-}
+ #endif
-private static float clerp(float start, float end, float val){
- float min = 0.0f;
- float max = 360.0f;
- float half = Mathf.Abs((max - min) / 2.0f);
- float retval = 0.0f;
- float diff = 0.0f;
- if ((end - start) < -half){
- diff = ((max - start) + end) * val;
- retval = start + diff;
- }else if ((end - start) > half){
- diff = -((max - end) + start) * val;
- retval = start + diff;
- }else retval = start + (end - start) * val;
- return retval;
-}
+ // Tweening Functions - Thanks to Robert Penner and GFX47
-private static float spring(float start, float end, float val ){
- val = Mathf.Clamp01(val);
- 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) ));
- return start + (end - start) * val;
-}
+ public static float tweenOnCurve( LTDescr tweenDescr, float ratioPassed ){
+ // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed));
+ return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed);
+ }
-private static float easeInQuad(float start, float end, float val){
- end -= start;
- return end * val * val + start;
-}
+ public static Vector3 tweenOnCurveVector( LTDescr tweenDescr, float ratioPassed ){
+ return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed),
+ tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed),
+ tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.optional.animationCurve.Evaluate(ratioPassed) );
+ }
-private static float easeOutQuad(float start, float end, float val){
- end -= start;
- return -end * val * (val - 2) + start;
-}
+ public static float easeOutQuadOpt( float start, float diff, float ratioPassed ){
+ return -diff * ratioPassed * (ratioPassed - 2) + start;
+ }
-private static float easeInOutQuad(float start, float end, float val){
- val /= .5f;
- end -= start;
- if (val < 1) return end / 2 * val * val + start;
- val--;
- return -end / 2 * (val * (val - 2) - 1) + start;
-}
+ public static float easeInQuadOpt( float start, float diff, float ratioPassed ){
+ return diff * ratioPassed * ratioPassed + start;
+ }
-private static float easeInCubic(float start, float end, float val){
- end -= start;
- return end * val * val * val + start;
-}
+ public static float easeInOutQuadOpt( float start, float diff, float ratioPassed ){
+ ratioPassed /= .5f;
+ if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
+ ratioPassed--;
+ return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
+ }
-private static float easeOutCubic(float start, float end, float val){
- val--;
- end -= start;
- return end * (val * val * val + 1) + start;
-}
+ public static Vector3 easeInOutQuadOpt( Vector3 start, Vector3 diff, float ratioPassed ){
+ ratioPassed /= .5f;
+ if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start;
+ ratioPassed--;
+ return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start;
+ }
-private static float easeInOutCubic(float start, float end, float val){
- val /= .5f;
- end -= start;
- if (val < 1) return end / 2 * val * val * val + start;
- val -= 2;
- return end / 2 * (val * val * val + 2) + start;
-}
+ public static float linear(float start, float end, float val){
+ return Mathf.Lerp(start, end, val);
+ }
-private static float easeInQuart(float start, float end, float val){
- end -= start;
- return end * val * val * val * val + start;
-}
+ public static float clerp(float start, float end, float val){
+ float min = 0.0f;
+ float max = 360.0f;
+ float half = Mathf.Abs((max - min) / 2.0f);
+ float retval = 0.0f;
+ float diff = 0.0f;
+ if ((end - start) < -half){
+ diff = ((max - start) + end) * val;
+ retval = start + diff;
+ }else if ((end - start) > half){
+ diff = -((max - end) + start) * val;
+ retval = start + diff;
+ }else retval = start + (end - start) * val;
+ return retval;
+ }
-private static float easeOutQuart(float start, float end, float val){
- val--;
- end -= start;
- return -end * (val * val * val * val - 1) + start;
-}
+ public static float spring(float start, float end, float val ){
+ val = Mathf.Clamp01(val);
+ 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) ));
+ return start + (end - start) * val;
+ }
+
+ public static float easeInQuad(float start, float end, float val){
+ end -= start;
+ return end * val * val + start;
+ }
+
+ public static float easeOutQuad(float start, float end, float val){
+ end -= start;
+ return -end * val * (val - 2) + start;
+ }
+
+ public static float easeInOutQuad(float start, float end, float val){
+ val /= .5f;
+ end -= start;
+ if (val < 1) return end / 2 * val * val + start;
+ val--;
+ return -end / 2 * (val * (val - 2) - 1) + start;
+ }
+
+
+ public static float easeInOutQuadOpt2(float start, float diffBy2, float val, float val2){
+ val /= .5f;
+ if (val < 1) return diffBy2 * val2 + start;
+ val--;
+ return -diffBy2 * ((val2 - 2) - 1f) + start;
+ }
+
+ public static float easeInCubic(float start, float end, float val){
+ end -= start;
+ return end * val * val * val + start;
+ }
+
+ public static float easeOutCubic(float start, float end, float val){
+ val--;
+ end -= start;
+ return end * (val * val * val + 1) + start;
+ }
+
+ public static float easeInOutCubic(float start, float end, float val){
+ val /= .5f;
+ end -= start;
+ if (val < 1) return end / 2 * val * val * val + start;
+ val -= 2;
+ return end / 2 * (val * val * val + 2) + start;
+ }
+
+ public static float easeInQuart(float start, float end, float val){
+ end -= start;
+ return end * val * val * val * val + start;
+ }
+
+ public static float easeOutQuart(float start, float end, float val){
+ val--;
+ end -= start;
+ return -end * (val * val * val * val - 1) + start;
+ }
+
+ public static float easeInOutQuart(float start, float end, float val){
+ val /= .5f;
+ end -= start;
+ if (val < 1) return end / 2 * val * val * val * val + start;
+ val -= 2;
+ return -end / 2 * (val * val * val * val - 2) + start;
+ }
+
+ public static float easeInQuint(float start, float end, float val){
+ end -= start;
+ return end * val * val * val * val * val + start;
+ }
+
+ public static float easeOutQuint(float start, float end, float val){
+ val--;
+ end -= start;
+ return end * (val * val * val * val * val + 1) + start;
+ }
+
+ public static float easeInOutQuint(float start, float end, float val){
+ val /= .5f;
+ end -= start;
+ if (val < 1) return end / 2 * val * val * val * val * val + start;
+ val -= 2;
+ return end / 2 * (val * val * val * val * val + 2) + start;
+ }
+
+ public static float easeInSine(float start, float end, float val){
+ end -= start;
+ return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start;
+ }
+
+ public static float easeOutSine(float start, float end, float val){
+ end -= start;
+ return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start;
+ }
+
+ public static float easeInOutSine(float start, float end, float val){
+ end -= start;
+ return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start;
+ }
+
+ public static float easeInExpo(float start, float end, float val){
+ end -= start;
+ return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start;
+ }
+
+ public static float easeOutExpo(float start, float end, float val){
+ end -= start;
+ return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start;
+ }
+
+ public static float easeInOutExpo(float start, float end, float val){
+ val /= .5f;
+ end -= start;
+ if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start;
+ val--;
+ return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start;
+ }
+
+ public static float easeInCirc(float start, float end, float val){
+ end -= start;
+ return -end * (Mathf.Sqrt(1 - val * val) - 1) + start;
+ }
+
+ public static float easeOutCirc(float start, float end, float val){
+ val--;
+ end -= start;
+ return end * Mathf.Sqrt(1 - val * val) + start;
+ }
+
+ public static float easeInOutCirc(float start, float end, float val){
+ val /= .5f;
+ end -= start;
+ if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start;
+ val -= 2;
+ return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start;
+ }
+
+ public static float easeInBounce(float start, float end, float val){
+ end -= start;
+ float d = 1f;
+ return end - easeOutBounce(0, end, d-val) + start;
+ }
+
+ public static float easeOutBounce(float start, float end, float val){
+ val /= 1f;
+ end -= start;
+ if (val < (1 / 2.75f)){
+ return end * (7.5625f * val * val) + start;
+ }else if (val < (2 / 2.75f)){
+ val -= (1.5f / 2.75f);
+ return end * (7.5625f * (val) * val + .75f) + start;
+ }else if (val < (2.5 / 2.75)){
+ val -= (2.25f / 2.75f);
+ return end * (7.5625f * (val) * val + .9375f) + start;
+ }else{
+ val -= (2.625f / 2.75f);
+ return end * (7.5625f * (val) * val + .984375f) + start;
+ }
+ }
+
+ public static float easeInOutBounce(float start, float end, float val){
+ end -= start;
+ float d= 1f;
+ if (val < d/2) return easeInBounce(0, end, val*2) * 0.5f + start;
+ else return easeOutBounce(0, end, val*2-d) * 0.5f + end*0.5f + start;
+ }
+
+ public static float easeInBack(float start, float end, float val, float overshoot = 1.0f){
+ end -= start;
+ val /= 1;
+ float s= 1.70158f * overshoot;
+ return end * (val) * val * ((s + 1) * val - s) + start;
+ }
+
+ public static float easeOutBack(float start, float end, float val, float overshoot = 1.0f){
+ float s = 1.70158f * overshoot;
+ end -= start;
+ val = (val / 1) - 1;
+ return end * ((val) * val * ((s + 1) * val + s) + 1) + start;
+ }
+
+ public static float easeInOutBack(float start, float end, float val, float overshoot = 1.0f){
+ float s = 1.70158f * overshoot;
+ end -= start;
+ val /= .5f;
+ if ((val) < 1){
+ s *= (1.525f) * overshoot;
+ return end / 2 * (val * val * (((s) + 1) * val - s)) + start;
+ }
+ val -= 2;
+ s *= (1.525f) * overshoot;
+ return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start;
+ }
+
+ public static float easeInElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){
+ end -= start;
+
+ float p = period;
+ float s = 0f;
+ float a = 0f;
+
+ if (val == 0f) return start;
+
+ if (val == 1f) return start + end;
+
+ if (a == 0f || a < Mathf.Abs(end)){
+ a = end;
+ s = p / 4f;
+ }else{
+ s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
+ }
+
+ if(overshoot>1f && val>0.6f )
+ overshoot = 1f + ((1f-val) / 0.4f * (overshoot-1f));
+ // Debug.Log("ease in elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
+
+ val = val-1f;
+ return start-(a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
+ }
+
+ public static float easeOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){
+ end -= start;
+
+ float p = period;
+ float s = 0f;
+ float a = 0f;
+
+ if (val == 0f) return start;
+
+ // Debug.Log("ease out elastic val:"+val+" a:"+a);
+ if (val == 1f) return start + end;
+
+ if (a == 0f || a < Mathf.Abs(end)){
+ a = end;
+ s = p / 4f;
+ }else{
+ s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
+ }
+ if(overshoot>1f && val<0.4f )
+ overshoot = 1f + (val / 0.4f * (overshoot-1f));
+ // Debug.Log("ease out elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
+
+ return start + end + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * overshoot;
+ }
+
+ public static float easeInOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f)
+ {
+ end -= start;
-private static float easeInOutQuart(float start, float end, float val){
- val /= .5f;
- end -= start;
- if (val < 1) return end / 2 * val * val * val * val + start;
- val -= 2;
- return -end / 2 * (val * val * val * val - 2) + start;
+ float p = period;
+ float s = 0f;
+ float a = 0f;
+
+ if (val == 0f) return start;
+
+ val = val / (1f/2f);
+ if (val == 2f) return start + end;
+
+ if (a == 0f || a < Mathf.Abs(end)){
+ a = end;
+ s = p / 4f;
+ }else{
+ s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
+ }
+
+ if(overshoot>1f){
+ if( val<0.2f ){
+ overshoot = 1f + (val / 0.2f * (overshoot-1f));
+ }else if( val > 0.8f ){
+ overshoot = 1f + ((1f-val) / 0.2f * (overshoot-1f));
+ }
+ }
+
+ if (val < 1f){
+ val = val-1f;
+ return start - 0.5f * (a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
+ }
+ val = val-1f;
+ return end + start + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * 0.5f * overshoot;
+ }
+
+ // LeanTween Listening/Dispatch
+
+ private static System.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;
+
+ public static void addListener( int eventId, System.Action callback ){
+ addListener(tweenEmpty, eventId, callback);
+ }
+
+ /**
+ * Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called
+ *
+ * @method LeanTween.addListener
+ * @param {GameObject} caller:GameObject the gameObject the listener is attached to
+ * @param {int} eventId:int a unique int that describes the event (best to use an enum)
+ * @param {System.Action} callback:System.Action the method to call when the event has been dispatched
+ * @example
+ * LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);
+ *
+ * void jumpUp( LTEvent e ){ Debug.Log("jump!"); }
+ */
+ public static void addListener( GameObject caller, int eventId, System.Action callback ){
+ if(eventListeners==null){
+ INIT_LISTENERS_MAX = LISTENERS_MAX;
+ eventListeners = new System.Action[ EVENTS_MAX * LISTENERS_MAX ];
+ goListeners = new GameObject[ EVENTS_MAX * LISTENERS_MAX ];
+ }
+ // Debug.Log("searching for an empty space for:"+caller + " eventid:"+event);
+ for(i = 0; i < INIT_LISTENERS_MAX; i++){
+ int point = eventId*INIT_LISTENERS_MAX + i;
+ if(goListeners[ point ]==null || eventListeners[ point ]==null){
+ eventListeners[ point ] = callback;
+ goListeners[ point ] = caller;
+ if(i>=eventsMaxSearch)
+ eventsMaxSearch = i+1;
+ // Debug.Log("adding event for:"+caller.name);
+
+ return;
+ }
+ #if UNITY_FLASH
+ if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback)){
+ // Debug.Log("This event is already being listened for.");
+ return;
+ }
+ #else
+ if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback)){
+ // Debug.Log("This event is already being listened for.");
+ return;
+ }
+ #endif
+ }
+ Debug.LogError("You ran out of areas to add listeners, consider increasing LISTENERS_MAX, ex: LeanTween.LISTENERS_MAX = "+(LISTENERS_MAX*2));
+ }
+
+ public static bool removeListener( int eventId, System.Action callback ){
+ return removeListener( tweenEmpty, eventId, callback);
+ }
+
+ public static bool removeListener( int eventId ){
+ int point = eventId*INIT_LISTENERS_MAX + i;
+ eventListeners[ point ] = null;
+ goListeners[ point ] = null;
+ return true;
+ }
+
+
+ /**
+ * Remove an event listener you have added
+ * @method LeanTween.removeListener
+ * @param {GameObject} caller:GameObject the gameObject the listener is attached to
+ * @param {int} eventId:int a unique int that describes the event (best to use an enum)
+ * @param {System.Action} callback:System.Action the method that was specified to call when the event has been dispatched
+ * @example
+ * LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);
+ *
+ * void jumpUp( LTEvent e ){ }
+ */
+ public static bool removeListener( GameObject caller, int eventId, System.Action callback ){
+ for(i = 0; i < eventsMaxSearch; i++){
+ int point = eventId*INIT_LISTENERS_MAX + i;
+ #if UNITY_FLASH
+ if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback) ){
+ #else
+ if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback) ){
+ #endif
+ eventListeners[ point ] = null;
+ goListeners[ point ] = null;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tell the added listeners that you are dispatching the event
+ * @method LeanTween.dispatchEvent
+ * @param {int} eventId:int a unique int that describes the event (best to use an enum)
+ * @example
+ * LeanTween.dispatchEvent( (int)MyEvents.JUMP );
+ */
+ public static void dispatchEvent( int eventId ){
+ dispatchEvent( eventId, null);
+ }
+
+ /**
+ * Tell the added listeners that you are dispatching the event
+ * @method LeanTween.dispatchEvent
+ * @param {int} eventId:int a unique int that describes the event (best to use an enum)
+ * @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object
+ * @example
+ * LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );
+ *
+ * void jumpUp( LTEvent e ){
+ * Transform tran = (Transform)e.data;
+ * }
+ */
+ public static void dispatchEvent( int eventId, object data ){
+ for(int k = 0; k < eventsMaxSearch; k++){
+ int point = eventId*INIT_LISTENERS_MAX + k;
+ if(eventListeners[ point ]!=null){
+ if(goListeners[point]){
+ eventListeners[ point ]( new LTEvent(eventId, data) );
+ }else{
+ eventListeners[ point ] = null;
+ }
+ }
+ }
+ }
+
+
+} // End LeanTween class
+
+public class LTUtility {
+
+ public static Vector3[] reverse( Vector3[] arr ){
+ int length = arr.Length;
+ int left = 0;
+ int right = length - 1;
+
+ for (; left < right; left += 1, right -= 1){
+ Vector3 temporary = arr[left];
+ arr[left] = arr[right];
+ arr[right] = temporary;
+ }
+ return arr;
+ }
}
-private static float easeInQuint(float start, float end, float val){
- end -= start;
- return end * val * val * val * val * val + start;
+public class LTBezier {
+ public float length;
+
+ private Vector3 a;
+ private Vector3 aa;
+ private Vector3 bb;
+ private Vector3 cc;
+ private float len;
+ private float[] arcLengths;
+
+ public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision){
+ this.a = a;
+ aa = (-a + 3*(b-c) + d);
+ bb = 3*(a+c) - 6*b;
+ cc = 3*(b-a);
+
+ this.len = 1.0f / precision;
+ arcLengths = new float[(int)this.len + (int)1];
+ arcLengths[0] = 0;
+
+ Vector3 ov = a;
+ Vector3 v;
+ float clen = 0.0f;
+ for(int i = 1; i <= this.len; i++) {
+ v = bezierPoint(i * precision);
+ clen += (ov - v).magnitude;
+ this.arcLengths[i] = clen;
+ ov = v;
+ }
+ this.length = clen;
+ }
+
+ private float map(float u) {
+ float targetLength = u * this.arcLengths[(int)this.len];
+ int low = 0;
+ int high = (int)this.len;
+ int index = 0;
+ while (low < high) {
+ index = low + ((int)((high - low) / 2.0f) | 0);
+ if (this.arcLengths[index] < targetLength) {
+ low = index + 1;
+ } else {
+ high = index;
+ }
+ }
+ if(this.arcLengths[index] > targetLength)
+ index--;
+ if(index<0)
+ index = 0;
+
+ return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len;
+ }
+
+ private Vector3 bezierPoint(float t){
+ return ((aa* t + (bb))* t + cc)* t + a;
+ }
+
+ public Vector3 point(float t){
+ return bezierPoint( map(t) );
+ }
}
-private static float easeOutQuint(float start, float end, float val){
- val--;
- end -= start;
- return end * (val * val * val * val * val + 1) + start;
+/**
+* Manually animate along a bezier path with this class
+* @class LTBezierPath
+* @constructor
+* @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)
+* It goes in the order: startPoint,endControl,startControl,endPoint - Note: the control for the end and start are reversed! This is just a *quirk* of the API.
+*
+* @example
+* 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)} );
+* LeanTween.move(lt, ltPath.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
+* Vector3 pt = ltPath.point( 0.6f ); // retrieve a point along the path
+*/
+public class LTBezierPath {
+ public Vector3[] pts;
+ public float length;
+ public bool orientToPath;
+ public bool orientToPath2d;
+
+ private LTBezier[] beziers;
+ private float[] lengthRatio;
+ private int currentBezier=0,previousBezier=0;
+
+ public LTBezierPath(){ }
+ public LTBezierPath( Vector3[] pts_ ){
+ setPoints( pts_ );
+ }
+
+ public void setPoints( Vector3[] pts_ ){
+ if(pts_.Length<4)
+ LeanTween.logError( "LeanTween - When passing values for a vector path, you must pass four or more values!" );
+ if(pts_.Length%4!=0)
+ LeanTween.logError( "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..." );
+
+ pts = pts_;
+
+ int k = 0;
+ beziers = new LTBezier[ pts.Length / 4 ];
+ lengthRatio = new float[ beziers.Length ];
+ int i;
+ length = 0;
+ for(i = 0; i < pts.Length; i+=4){
+ beziers[k] = new LTBezier(pts[i+0],pts[i+2],pts[i+1],pts[i+3],0.05f);
+ length += beziers[k].length;
+ k++;
+ }
+ // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers);
+ for(i = 0; i < beziers.Length; i++){
+ lengthRatio[i] = beziers[i].length / length;
+ }
+ }
+
+ /**
+ * @property {float} distance distance of the path (in unity units)
+ */
+ public float distance{
+ get{
+ return length;
+ }
+ }
+
+ /**
+ * Retrieve a point along a path Move a GameObject to a certain location
+ *
+ * @method point
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @return {Vector3} Vector3 position of the point along the path
+ * @example
+ * transform.position = ltPath.point( 0.6f );
+ */
+ public Vector3 point( float ratio ){
+ float added = 0.0f;
+ for(int i = 0; i < lengthRatio.Length; i++){
+ added += lengthRatio[i];
+ if(added >= ratio)
+ return beziers[i].point( (ratio-(added-lengthRatio[i])) / lengthRatio[i] );
+ }
+ return beziers[lengthRatio.Length-1].point( 1.0f );
+ }
+
+ public void place2d( Transform transform, float ratio ){
+ transform.position = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f){
+ Vector3 v3Dir = point( ratio ) - transform.position;
+ float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
+ transform.eulerAngles = new Vector3(0, 0, angle);
+ }
+ }
+
+ public void placeLocal2d( Transform transform, float ratio ){
+ transform.localPosition = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f){
+ Vector3 v3Dir = point( ratio ) - transform.localPosition;
+ float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
+ transform.localEulerAngles = new Vector3(0, 0, angle);
+ }
+ }
+
+ /**
+ * Place an object along a certain point on the path (facing the direction perpendicular to the path) Move a GameObject to a certain location
+ *
+ * @method place
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @example
+ * ltPath.place( transform, 0.6f );
+ */
+ public void place( Transform transform, float ratio ){
+ place( transform, ratio, Vector3.up );
+
+ }
+
+ /**
+ * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path Move a GameObject to a certain location
+ *
+ * @method place
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
+ * @example
+ * ltPath.place( transform, 0.6f, Vector3.left );
+ */
+ public void place( Transform transform, float ratio, Vector3 worldUp ){
+ transform.position = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f)
+ transform.LookAt( point( ratio ), worldUp );
+
+ }
+
+ /**
+ * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space Move a GameObject to a certain location
+ *
+ * @method placeLocal
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @example
+ * ltPath.placeLocal( transform, 0.6f );
+ */
+ public void placeLocal( Transform transform, float ratio ){
+ placeLocal( transform, ratio, Vector3.up );
+ }
+
+ /**
+ * 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 Move a GameObject to a certain location
+ *
+ * @method placeLocal
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
+ * @example
+ * ltPath.placeLocal( transform, 0.6f, Vector3.left );
+ */
+ public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){
+ // Debug.Log("place ratio:" + ratio + " greater:"+(ratio>1f));
+ ratio = Mathf.Clamp01(ratio);
+ transform.localPosition = point( ratio );
+ // Debug.Log("ratio:" + ratio + " +:" + (ratio + 0.001f));
+ ratio = Mathf.Clamp01(ratio + 0.001f);
+
+ if(ratio<=1.0f)
+ transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp );
+ }
+
+ public void gizmoDraw(float t = -1.0f)
+ {
+ Vector3 prevPt = point(0);
+
+ for (int i = 1; i <= 120; i++)
+ {
+ float pm = (float)i / 120f;
+ Vector3 currPt2 = point(pm);
+ //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
+ Gizmos.color = (previousBezier == currentBezier) ? Color.magenta : Color.grey;
+ Gizmos.DrawLine(currPt2, prevPt);
+ prevPt = currPt2;
+ previousBezier = currentBezier;
+ }
+ }
}
-private static float easeInOutQuint(float start, float end, float val){
- val /= .5f;
- end -= start;
- if (val < 1) return end / 2 * val * val * val * val * val + start;
- val -= 2;
- return end / 2 * (val * val * val * val * val + 2) + start;
-}
+/**
+* Animate along a set of points that need to be in the format: controlPoint, point1, point2.... pointLast, endControlPoint Move a GameObject to a certain location
+* @class LTSpline
+* @constructor
+* @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)
+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.
+* @example
+* 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)} );
+* LeanTween.moveSpline(lt, ltSpline.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
+* Vector3 pt = ltSpline.point( 0.6f ); // retrieve a point along the path
+*/
+[System.Serializable]
+public class LTSpline {
+ public static int DISTANCE_COUNT = 3; // increase for a more accurate constant speed
+ public static int SUBLINE_COUNT = 20; // increase for a more accurate smoothing of the curves into lines
+
+ /**
+ * @property {float} distance distance of the spline (in unity units)
+ */
+ public float distance = 0f;
+
+ public bool constantSpeed = true;
+
+ public Vector3[] pts;
+ [System.NonSerialized]
+ public Vector3[] ptsAdj;
+ public int ptsAdjLength;
+ public bool orientToPath;
+ public bool orientToPath2d;
+ private int numSections;
+ private int currPt;
+
+ public LTSpline( Vector3[] pts ){
+ init( pts, true);
+ }
+
+ public LTSpline( Vector3[] pts, bool constantSpeed ) {
+ this.constantSpeed = constantSpeed;
+ init(pts, constantSpeed);
+ }
+
+ private void init( Vector3[] pts, bool constantSpeed){
+ if(pts.Length<4){
+ LeanTween.logError( "LeanTween - When passing values for a spline path, you must pass four or more values!" );
+ return;
+ }
+
+ this.pts = new Vector3[pts.Length];
+ System.Array.Copy(pts, this.pts, pts.Length);
+
+ numSections = pts.Length - 3;
+
+ float minSegment = float.PositiveInfinity;
+ Vector3 earlierPoint = this.pts[1];
+ float totalDistance = 0f;
+ for(int i=1; i < this.pts.Length-1; i++){
+ // float pointDistance = (this.pts[i]-earlierPoint).sqrMagnitude;
+ float pointDistance = Vector3.Distance(this.pts[i], earlierPoint);
+ //Debug.Log("pointDist:"+pointDistance);
+ if(pointDistance < minSegment){
+ minSegment = pointDistance;
+ }
+
+ totalDistance += pointDistance;
+ }
+
+ if(constantSpeed){
+ minSegment = totalDistance / (numSections*SUBLINE_COUNT);
+ //Debug.Log("minSegment:"+minSegment+" numSections:"+numSections);
+
+ float minPrecision = minSegment / SUBLINE_COUNT; // number of subdivisions in each segment
+ int precision = (int)Mathf.Ceil(totalDistance / minPrecision) * DISTANCE_COUNT;
+ // Debug.Log("precision:"+precision);
+ if(precision<=1) // precision has to be greater than one
+ precision = 2;
+
+ ptsAdj = new Vector3[ precision ];
+ earlierPoint = interp( 0f );
+ int num = 1;
+ ptsAdj[0] = earlierPoint;
+ distance = 0f;
+ for(int i = 0; i < precision + 1; i++){
+ float fract = ((float)(i)) / precision;
+ // Debug.Log("fract:"+fract);
+ Vector3 point = interp( fract );
+ float dist = Vector3.Distance(point, earlierPoint);
+
+ // float dist = (point-earlierPoint).sqrMagnitude;
+ if(dist>=minPrecision || fract>=1.0f){
+ ptsAdj[num] = point;
+ distance += dist; // only add it to the total distance once we know we are adding it as an adjusted point
+
+ earlierPoint = point;
+ // Debug.Log("fract:"+fract+" point:"+point);
+ num++;
+ }
+ }
+ // make sure there is a point at the very end
+ /*num++;
+ Vector3 endPoint = interp( 1f );
+ ptsAdj[num] = endPoint;*/
+ // Debug.Log("fract 1f endPoint:"+endPoint);
+
+ ptsAdjLength = num;
+ }
+ // Debug.Log("map 1f:"+map(1f)+" end:"+ptsAdj[ ptsAdjLength-1 ]);
+
+ // Debug.Log("ptsAdjLength:"+ptsAdjLength+" minPrecision:"+minPrecision+" precision:"+precision);
+ }
+
+ public Vector3 map( float u ){
+ if(u>=1f)
+ return pts[ pts.Length - 2];
+ float t = u * (ptsAdjLength-1);
+ int first = (int)Mathf.Floor( t );
+ int next = (int)Mathf.Ceil( t );
+
+ if(first<0)
+ first = 0;
+
+ Vector3 val = ptsAdj[ first ];
+
+
+ Vector3 nextVal = ptsAdj[ next ];
+ float diff = t - first;
+
+ // Debug.Log("u:"+u+" val:"+val +" nextVal:"+nextVal+" diff:"+diff+" first:"+first+" next:"+next);
+
+ val = val + (nextVal - val) * diff;
+
+ return val;
+ }
+
+ public Vector3 interp(float t) {
+ currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
+ float u = t * (float) numSections - (float) currPt;
+
+ //Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length );
+ Vector3 a = pts[currPt];
+ Vector3 b = pts[currPt + 1];
+ Vector3 c = pts[currPt + 2];
+ Vector3 d = pts[currPt + 3];
+
+ Vector3 val = (.5f * (
+ (-a + 3f * b - 3f * c + d) * (u * u * u)
+ + (2f * a - 5f * b + 4f * c - d) * (u * u)
+ + (-a + c) * u
+ + 2f * b));
+ // Debug.Log("currPt:"+currPt+" t:"+t+" val.x"+val.x+" y:"+val.y+" z:"+val.z);
+
+ return val;
+ }
+
+ /**
+ * Retrieve a point along a path Move a GameObject to a certain location
+ *
+ * @method ratioAtPoint
+ * @param {Vector3} point:Vector3 given a current location it makes the best approximiation of where it is along the path ratio-wise (0-1)
+ * @return {float} float of ratio along the path
+ * @example
+ * ratioIter = ltSpline.ratioAtPoint( transform.position );
+ */
+ public float ratioAtPoint( Vector3 pt ){
+ float closestDist = float.MaxValue;
+ int closestI = 0;
+ for (int i = 0; i < ptsAdjLength; i++) {
+ float dist = Vector3.Distance(pt, ptsAdj[i]);
+ // Debug.Log("i:"+i+" dist:"+dist);
+ if(distMove a GameObject to a certain location
+ *
+ * @method point
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @return {Vector3} Vector3 position of the point along the path
+ * @example
+ * transform.position = ltSpline.point( 0.6f );
+ */
+ public Vector3 point( float ratio ){
+ float t = ratio>1f?1f:ratio;
+ return constantSpeed ? map(t) : interp(t);
+ }
+
+ public void place2d( Transform transform, float ratio ){
+ transform.position = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f){
+ Vector3 v3Dir = point( ratio ) - transform.position;
+ float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
+ transform.eulerAngles = new Vector3(0, 0, angle);
+ }
+ }
+
+ public void placeLocal2d( Transform transform, float ratio ){
+ Transform trans = transform.parent;
+ if(trans==null){ // this has no parent, just do a regular transform
+ place2d(transform, ratio);
+ return;
+ }
+ transform.localPosition = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f){
+ Vector3 ptAhead = point( ratio );//trans.TransformPoint( );
+ Vector3 v3Dir = ptAhead - transform.localPosition;
+ float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
+ transform.localEulerAngles = new Vector3(0, 0, angle);
+ }
+ }
-private static float easeInSine(float start, float end, float val){
- end -= start;
- return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start;
-}
-private static float easeOutSine(float start, float end, float val){
- end -= start;
- return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start;
-}
+ /**
+ * Place an object along a certain point on the path (facing the direction perpendicular to the path) Move a GameObject to a certain location
+ *
+ * @method place
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @example
+ * ltPath.place( transform, 0.6f );
+ */
+ public void place( Transform transform, float ratio ){
+ place(transform, ratio, Vector3.up);
+ }
-private static float easeInOutSine(float start, float end, float val){
- end -= start;
- return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start;
-}
+ /**
+ * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path Move a GameObject to a certain location
+ *
+ * @method place
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
+ * @example
+ * ltPath.place( transform, 0.6f, Vector3.left );
+ */
+ public void place( Transform transform, float ratio, Vector3 worldUp ){
+ // ratio = Mathf.Repeat(ratio, 1.0f); // make sure ratio is always between 0-1
+ transform.position = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f)
+ transform.LookAt( point( ratio ), worldUp );
-private static float easeInExpo(float start, float end, float val){
- end -= start;
- return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start;
-}
+ }
-private static float easeOutExpo(float start, float end, float val){
- end -= start;
- return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start;
-}
+ /**
+ * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space Move a GameObject to a certain location
+ *
+ * @method placeLocal
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @example
+ * ltPath.placeLocal( transform, 0.6f );
+ */
+ public void placeLocal( Transform transform, float ratio ){
+ placeLocal( transform, ratio, Vector3.up );
+ }
-private static float easeInOutExpo(float start, float end, float val){
- val /= .5f;
- end -= start;
- if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start;
- val--;
- return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start;
-}
+ /**
+ * 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 Move a GameObject to a certain location
+ *
+ * @method placeLocal
+ * @param {Transform} transform:Transform the transform of the object you wish to place along the path
+ * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
+ * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
+ * @example
+ * ltPath.placeLocal( transform, 0.6f, Vector3.left );
+ */
+ public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){
+ transform.localPosition = point( ratio );
+ ratio += 0.001f;
+ if(ratio<=1.0f)
+ transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp );
+ }
-private static float easeInCirc(float start, float end, float val){
- end -= start;
- return -end * (Mathf.Sqrt(1 - val * val) - 1) + start;
-}
+ public void gizmoDraw(float t = -1.0f) {
+ if(ptsAdj==null || ptsAdj.Length<=0)
+ return;
-private static float easeOutCirc(float start, float end, float val){
- val--;
- end -= start;
- return end * Mathf.Sqrt(1 - val * val) + start;
-}
+ Vector3 prevPt = ptsAdj[0];
-private static float easeInOutCirc(float start, float end, float val){
- val /= .5f;
- end -= start;
- if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start;
- val -= 2;
- return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start;
-}
+ for (int i = 0; i < ptsAdjLength; i++) {
+ Vector3 currPt2 = ptsAdj[i];
+ // Debug.Log("currPt2:"+currPt2);
+ //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
+ Gizmos.DrawLine(prevPt, currPt2);
+ prevPt = currPt2;
+ }
+ }
-private static float easeInBounce(float start, float end, float val){
- end -= start;
- float d = 1f;
- return end - easeOutBounce(0, end, d-val) + start;
-}
+ public void drawGizmo( Color color ) {
+ if( this.ptsAdjLength>=4){
-private static float easeOutBounce(float start, float end, float val){
- val /= 1f;
- end -= start;
- if (val < (1 / 2.75f)){
- return end * (7.5625f * val * val) + start;
- }else if (val < (2 / 2.75f)){
- val -= (1.5f / 2.75f);
- return end * (7.5625f * (val) * val + .75f) + start;
- }else if (val < (2.5 / 2.75)){
- val -= (2.25f / 2.75f);
- return end * (7.5625f * (val) * val + .9375f) + start;
- }else{
- val -= (2.625f / 2.75f);
- return end * (7.5625f * (val) * val + .984375f) + start;
- }
-}
+ Vector3 prevPt = this.ptsAdj[0];
-/*private static float easeOutBounce( float start, float end, float val, float overshoot = 1.0f ){
- end -= start;
- float baseAmt = 2.75f * overshoot;
- float baseAmt2 = baseAmt * baseAmt;
- Debug.Log("val:"+val); // 1f, 0.75f, 0.5f, 0.25f, 0.125f
- if (val < ((baseAmt-(baseAmt - 1f)) / baseAmt)){ // 0.36
- return end * (baseAmt2 * val * val) + start; // 1 - 1/1
-
- }else if (val < ((baseAmt-0.75f) / baseAmt)){ // .72
- val -= ((baseAmt-(baseAmt - 1f - 0.5f)) / baseAmt); // 1.25f
- return end * (baseAmt2 * val * val + .75f) + start; // 1 - 1/(4)
-
- }else if (val < ((baseAmt-(baseAmt - 1f - 0.5f - 0.25f)) / baseAmt)){ // .909
- val -= ((baseAmt-0.5f) / baseAmt); // 0.5
- return end * (baseAmt2 * val * val + .9375f) + start; // 1 - 1/(4*4)
-
- }else{ // x
- // Debug.Log("else val:"+val);
- val -= ((baseAmt-0.125f) / baseAmt); // 0.125
- return end * (baseAmt2 * val * val + .984375f) + start; // 1 - 1/(4*4*4)
-
- }
-}*/
-
-private static float easeInOutBounce(float start, float end, float val){
- end -= start;
- float d= 1f;
- if (val < d/2) return easeInBounce(0, end, val*2) * 0.5f + start;
- else return easeOutBounce(0, end, val*2-d) * 0.5f + end*0.5f + start;
-}
+ Color colorBefore = Gizmos.color;
+ Gizmos.color = color;
+ for (int i = 0; i < this.ptsAdjLength; i++) {
+ Vector3 currPt2 = this.ptsAdj[i];
+ // Debug.Log("currPt2:"+currPt2);
-private static float easeInBack(float start, float end, float val, float overshoot = 1.0f){
- end -= start;
- val /= 1;
- float s= 1.70158f * overshoot;
- return end * (val) * val * ((s + 1) * val - s) + start;
-}
+ Gizmos.DrawLine(prevPt, currPt2);
+ prevPt = currPt2;
+ }
+ Gizmos.color = colorBefore;
+ }
+ }
-private static float easeOutBack(float start, float end, float val, float overshoot = 1.0f){
- float s = 1.70158f * overshoot;
- end -= start;
- val = (val / 1) - 1;
- return end * ((val) * val * ((s + 1) * val + s) + 1) + start;
-}
+ public static void drawGizmo(Transform[] arr, Color color) {
+ if(arr.Length>=4){
+ Vector3[] vec3s = new Vector3[arr.Length];
+ for(int i = 0; i < arr.Length; i++){
+ vec3s[i] = arr[i].position;
+ }
+ LTSpline spline = new LTSpline(vec3s);
+ Vector3 prevPt = spline.ptsAdj[0];
-private static float easeInOutBack(float start, float end, float val, float overshoot = 1.0f){
- float s = 1.70158f * overshoot;
- end -= start;
- val /= .5f;
- if ((val) < 1){
- s *= (1.525f) * overshoot;
- return end / 2 * (val * val * (((s) + 1) * val - s)) + start;
- }
- val -= 2;
- s *= (1.525f) * overshoot;
- return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start;
-}
+ Color colorBefore = Gizmos.color;
+ Gizmos.color = color;
+ for (int i = 0; i < spline.ptsAdjLength; i++) {
+ Vector3 currPt2 = spline.ptsAdj[i];
+ // Debug.Log("currPt2:"+currPt2);
-private static float easeInElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){
- end -= start;
-
- float p = period;
- float s = 0f;
- float a = 0f;
-
- if (val == 0f) return start;
-
- if (val == 1f) return start + end;
-
- if (a == 0f || a < Mathf.Abs(end)){
- a = end;
- s = p / 4f;
- }else{
- s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
- }
-
- if(overshoot>1f && val>0.6f )
- overshoot = 1f + ((1f-val) / 0.4f * (overshoot-1f));
- // Debug.Log("ease in elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
-
- val = val-1f;
- return start-(a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
-}
-
-private static float easeOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f){
- end -= start;
-
- float p = period;
- float s = 0f;
- float a = 0f;
-
- if (val == 0f) return start;
-
- // Debug.Log("ease out elastic val:"+val+" a:"+a);
- if (val == 1f) return start + end;
-
- if (a == 0f || a < Mathf.Abs(end)){
- a = end;
- s = p / 4f;
- }else{
- s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
- }
- if(overshoot>1f && val<0.4f )
- overshoot = 1f + (val / 0.4f * (overshoot-1f));
- // Debug.Log("ease out elastic val:"+val+" a:"+a+" overshoot:"+overshoot);
-
- return start + end + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * overshoot;
-}
-
-private static float easeInOutElastic(float start, float end, float val, float overshoot = 1.0f, float period = 0.3f)
-{
- end -= start;
-
- float p = period;
- float s = 0f;
- float a = 0f;
-
- if (val == 0f) return start;
-
- val = val / (1f/2f);
- if (val == 2f) return start + end;
-
- if (a == 0f || a < Mathf.Abs(end)){
- a = end;
- s = p / 4f;
- }else{
- s = p / (2f * Mathf.PI) * Mathf.Asin(end / a);
- }
-
- if(overshoot>1f){
- if( val<0.2f ){
- overshoot = 1f + (val / 0.2f * (overshoot-1f));
- }else if( val > 0.8f ){
- overshoot = 1f + ((1f-val) / 0.2f * (overshoot-1f));
- }
- }
-
- if (val < 1f){
- val = val-1f;
- return start - 0.5f * (a * Mathf.Pow(2f, 10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p)) * overshoot;
- }
- val = val-1f;
- return end + start + a * Mathf.Pow(2f, -10f * val) * Mathf.Sin((val - s) * (2f * Mathf.PI) / p) * 0.5f * overshoot;
-}
+ Gizmos.DrawLine(prevPt, currPt2);
+ prevPt = currPt2;
+ }
+ Gizmos.color = colorBefore;
+ }
+ }
-// LeanTween Listening/Dispatch
-private static System.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;
+ public static void drawLine(Transform[] arr, float width, Color color) {
+ if(arr.Length>=4){
-public static void addListener( int eventId, System.Action callback ){
- addListener(tweenEmpty, eventId, callback);
-}
+ }
+ }
-/**
-* Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called
-*
-* @method LeanTween.addListener
-* @param {GameObject} caller:GameObject the gameObject the listener is attached to
-* @param {int} eventId:int a unique int that describes the event (best to use an enum)
-* @param {System.Action} callback:System.Action the method to call when the event has been dispatched
-* @example
-* LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);
-*
-* void jumpUp( LTEvent e ){ Debug.Log("jump!"); }
-*/
-public static void addListener( GameObject caller, int eventId, System.Action callback ){
- if(eventListeners==null){
- INIT_LISTENERS_MAX = LISTENERS_MAX;
- eventListeners = new System.Action[ EVENTS_MAX * LISTENERS_MAX ];
- goListeners = new GameObject[ EVENTS_MAX * LISTENERS_MAX ];
- }
- // Debug.Log("searching for an empty space for:"+caller + " eventid:"+event);
- for(i = 0; i < INIT_LISTENERS_MAX; i++){
- int point = eventId*INIT_LISTENERS_MAX + i;
- if(goListeners[ point ]==null || eventListeners[ point ]==null){
- eventListeners[ point ] = callback;
- goListeners[ point ] = caller;
- if(i>=eventsMaxSearch)
- eventsMaxSearch = i+1;
- // Debug.Log("adding event for:"+caller.name);
-
- return;
- }
- #if UNITY_FLASH
- if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback)){
- // Debug.Log("This event is already being listened for.");
- return;
- }
- #else
- if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback)){
- // Debug.Log("This event is already being listened for.");
- return;
- }
- #endif
- }
- Debug.LogError("You ran out of areas to add listeners, consider increasing INIT_LISTENERS_MAX, ex: LeanTween.INIT_LISTENERS_MAX = "+(INIT_LISTENERS_MAX*2));
-}
+ /*public Vector3 Velocity(float t) {
+ t = map( t );
+
+ int numSections = pts.Length - 3;
+ int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
+ float u = t * (float) numSections - (float) currPt;
+
+ Vector3 a = pts[currPt];
+ Vector3 b = pts[currPt + 1];
+ Vector3 c = pts[currPt + 2];
+ Vector3 d = pts[currPt + 3];
+
+ return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u)
+ + (2f * a -5f * b + 4f * c - d) * u
+ + .5f * c - .5f * a;
+ }*/
+
+ public void drawLinesGLLines(Material outlineMaterial, Color color, float width){
+ GL.PushMatrix();
+ outlineMaterial.SetPass(0);
+ GL.LoadPixelMatrix();
+ GL.Begin(GL.LINES);
+ GL.Color(color);
+
+ if (constantSpeed) {
+ if (this.ptsAdjLength >= 4) {
+
+ Vector3 prevPt = this.ptsAdj[0];
+
+ for (int i = 0; i < this.ptsAdjLength; i++) {
+ Vector3 currPt2 = this.ptsAdj[i];
+ GL.Vertex(prevPt);
+ GL.Vertex(currPt2);
+
+ prevPt = currPt2;
+ }
+ }
-public static bool removeListener( int eventId, System.Action callback ){
- return removeListener( tweenEmpty, eventId, callback);
-}
+ } else {
+ if (this.pts.Length >= 4) {
-/**
-* Remove an event listener you have added
-* @method LeanTween.removeListener
-* @param {GameObject} caller:GameObject the gameObject the listener is attached to
-* @param {int} eventId:int a unique int that describes the event (best to use an enum)
-* @param {System.Action} callback:System.Action the method that was specified to call when the event has been dispatched
-* @example
-* LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);
-*
-* void jumpUp( LTEvent e ){ }
-*/
-public static bool removeListener( GameObject caller, int eventId, System.Action callback ){
- for(i = 0; i < eventsMaxSearch; i++){
- int point = eventId*INIT_LISTENERS_MAX + i;
- #if UNITY_FLASH
- if(goListeners[ point ] == caller && System.Object.ReferenceEquals( eventListeners[ point ], callback) ){
- #else
- if(goListeners[ point ] == caller && System.Object.Equals( eventListeners[ point ], callback) ){
- #endif
- eventListeners[ point ] = null;
- goListeners[ point ] = null;
- return true;
- }
- }
- return false;
-}
+ Vector3 prevPt = this.pts[0];
-/**
-* Tell the added listeners that you are dispatching the event
-* @method LeanTween.dispatchEvent
-* @param {int} eventId:int a unique int that describes the event (best to use an enum)
-* @example
-* LeanTween.dispatchEvent( (int)MyEvents.JUMP );
-*/
-public static void dispatchEvent( int eventId ){
- dispatchEvent( eventId, null);
-}
+ float split = 1f / ((float)this.pts.Length * 10f);
-/**
-* Tell the added listeners that you are dispatching the event
-* @method LeanTween.dispatchEvent
-* @param {int} eventId:int a unique int that describes the event (best to use an enum)
-* @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object
-* @example
-* LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );
-*
-* void jumpUp( LTEvent e ){
-* Transform tran = (Transform)e.data;
-* }
-*/
-public static void dispatchEvent( int eventId, object data ){
- for(int k = 0; k < eventsMaxSearch; k++){
- int point = eventId*INIT_LISTENERS_MAX + k;
- if(eventListeners[ point ]!=null){
- if(goListeners[point]){
- eventListeners[ point ]( new LTEvent(eventId, data) );
- }else{
- eventListeners[ point ] = null;
- }
- }
- }
-}
+ float iter = 0f;
+ while (iter < 1f) {
+ float at = iter / 1f;
+ Vector3 currPt2 = interp(at);
+ // Debug.Log("currPt2:"+currPt2);
-} // End LeanTween class
+ GL.Vertex(prevPt);
+ GL.Vertex(currPt2);
-public class LTBezier {
- public float length;
-
- private Vector3 a;
- private Vector3 aa;
- private Vector3 bb;
- private Vector3 cc;
- private float len;
- private float[] arcLengths;
-
- public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision){
- this.a = a;
- aa = (-a + 3*(b-c) + d);
- bb = 3*(a+c) - 6*b;
- cc = 3*(b-a);
-
- this.len = 1.0f / precision;
- arcLengths = new float[(int)this.len + (int)1];
- arcLengths[0] = 0;
-
- Vector3 ov = a;
- Vector3 v;
- float clen = 0.0f;
- for(int i = 1; i <= this.len; i++) {
- v = bezierPoint(i * precision);
- clen += (ov - v).magnitude;
- this.arcLengths[i] = clen;
- ov = v;
- }
- this.length = clen;
- }
+ prevPt = currPt2;
- private float map(float u) {
- float targetLength = u * this.arcLengths[(int)this.len];
- int low = 0;
- int high = (int)this.len;
- int index = 0;
- while (low < high) {
- index = low + ((int)((high - low) / 2.0f) | 0);
- if (this.arcLengths[index] < targetLength) {
- low = index + 1;
- } else {
- high = index;
+ iter += split;
+ }
}
}
- if(this.arcLengths[index] > targetLength)
- index--;
- if(index<0)
- index = 0;
- return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len;
- }
- private Vector3 bezierPoint(float t){
- return ((aa* t + (bb))* t + cc)* t + a;
- }
+ GL.End();
+ GL.PopMatrix();
- public Vector3 point(float t){
- return bezierPoint( map(t) );
}
-}
-/**
-* Manually animate along a bezier path with this class
-* @class LTBezierPath
-* @constructor
-* @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)
-* @example
-* 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)} );
-* LeanTween.move(lt, ltPath.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
-* Vector3 pt = ltPath.point( 0.6f ); // retrieve a point along the path
-*/
-public class LTBezierPath {
- public Vector3[] pts;
- public float length;
- public bool orientToPath;
- public bool orientToPath2d;
-
- private LTBezier[] beziers;
- private float[] lengthRatio;
- private int currentBezier=0,previousBezier=0;
-
- public LTBezierPath(){ }
- public LTBezierPath( Vector3[] pts_ ){
- setPoints( pts_ );
- }
-
- public void setPoints( Vector3[] pts_ ){
- if(pts_.Length<4)
- LeanTween.logError( "LeanTween - When passing values for a vector path, you must pass four or more values!" );
- if(pts_.Length%4!=0)
- LeanTween.logError( "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..." );
-
- pts = pts_;
-
- int k = 0;
- beziers = new LTBezier[ pts.Length / 4 ];
- lengthRatio = new float[ beziers.Length ];
- int i;
- length = 0;
- for(i = 0; i < pts.Length; i+=4){
- beziers[k] = new LTBezier(pts[i+0],pts[i+2],pts[i+1],pts[i+3],0.05f);
- length += beziers[k].length;
- k++;
- }
- // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers);
- for(i = 0; i < beziers.Length; i++){
- lengthRatio[i] = beziers[i].length / length;
- }
- }
-
- /**
- * Retrieve a point along a path
- *
- * @method point
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @return {Vector3} Vector3 position of the point along the path
- * @example
- * transform.position = ltPath.point( 0.6f );
- */
- public Vector3 point( float ratio ){
- float added = 0.0f;
- for(int i = 0; i < lengthRatio.Length; i++){
- added += lengthRatio[i];
- if(added >= ratio)
- return beziers[i].point( (ratio-(added-lengthRatio[i])) / lengthRatio[i] );
- }
- return beziers[lengthRatio.Length-1].point( 1.0f );
- }
-
- public void place2d( Transform transform, float ratio ){
- transform.position = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f){
- Vector3 v3Dir = point( ratio ) - transform.position;
- float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
- transform.eulerAngles = new Vector3(0, 0, angle);
- }
- }
-
- public void placeLocal2d( Transform transform, float ratio ){
- transform.localPosition = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f){
- Vector3 v3Dir = transform.parent.TransformPoint( point( ratio ) ) - transform.localPosition;
- float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
- transform.eulerAngles = new Vector3(0, 0, angle);
- }
- }
-
- /**
- * Place an object along a certain point on the path (facing the direction perpendicular to the path)
- *
- * @method place
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @example
- * ltPath.place( transform, 0.6f );
- */
- public void place( Transform transform, float ratio ){
- place( transform, ratio, Vector3.up );
-
- }
-
- /**
- * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path
- *
- * @method place
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
- * @example
- * ltPath.place( transform, 0.6f, Vector3.left );
- */
- public void place( Transform transform, float ratio, Vector3 worldUp ){
- transform.position = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f)
- transform.LookAt( point( ratio ), worldUp );
-
- }
-
- /**
- * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space
- *
- * @method placeLocal
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @example
- * ltPath.placeLocal( transform, 0.6f );
- */
- public void placeLocal( Transform transform, float ratio ){
- placeLocal( transform, ratio, Vector3.up );
- }
-
- /**
- * 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
- *
- * @method placeLocal
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
- * @example
- * ltPath.placeLocal( transform, 0.6f, Vector3.left );
- */
- public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){
- transform.localPosition = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f)
- transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp );
- }
-
- public void gizmoDraw(float t = -1.0f)
- {
- Vector3 prevPt = point(0);
+ public Vector3[] generateVectors(){
+ if (this.pts.Length >= 4) {
+ List meshPoints = new List();
+ Vector3 prevPt = this.pts[0];
+ meshPoints.Add(prevPt);
- for (int i = 1; i <= 120; i++)
- {
- float pm = (float)i / 120f;
- Vector3 currPt2 = point(pm);
- //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
- Gizmos.color = (previousBezier == currentBezier) ? Color.magenta : Color.grey;
- Gizmos.DrawLine(currPt2, prevPt);
- prevPt = currPt2;
- previousBezier = currentBezier;
+ float split = 1f / ((float)this.pts.Length * 10f);
+
+ float iter = 0f;
+ while (iter < 1f) {
+ float at = iter / 1f;
+ Vector3 currPt2 = interp(at);
+ // Debug.Log("currPt2:"+currPt2);
+
+ // GL.Vertex(prevPt);
+ // GL.Vertex(currPt2);
+ meshPoints.Add(currPt2);
+
+ // prevPt = currPt2;
+
+ iter += split;
+ }
+
+ meshPoints.ToArray();
}
+ return null;
}
}
/**
-* Animate along a set of points that need to be in the format: controlPoint, point1, point2.... pointLast, endControlPoint
-* @class LTSpline
-* @constructor
-* @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)
-* @example
-* 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)} );
-* LeanTween.moveSpline(lt, ltSpline.vec3, 4.0f).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
-* Vector3 pt = ltSpline.point( 0.6f ); // retrieve a point along the path
-*/
-[System.Serializable]
-public class LTSpline {
- public static int DISTANCE_COUNT = 30; // increase for a more accurate constant speed
- public static int SUBLINE_COUNT = 50; // increase for a more accurate smoothing of the curves into lines
-
- public Vector3[] pts;
- public Vector3[] ptsAdj;
- public int ptsAdjLength;
- public bool orientToPath;
- public bool orientToPath2d;
- private int numSections;
- private int currPt;
- private float totalLength;
-
- public LTSpline(params Vector3[] pts) {
- this.pts = new Vector3[pts.Length];
- System.Array.Copy(pts, this.pts, pts.Length);
-
- numSections = pts.Length - 3;
-
- float minSegment = float.PositiveInfinity;
- Vector3 earlierPoint = this.pts[1];
- float totalDistance = 0f;
- for(int i=2; i < this.pts.Length-2; i++){
- float pointDistance = Vector3.Distance(this.pts[i], earlierPoint);
- if(pointDistance < minSegment){
- minSegment = pointDistance;
- }
-
- totalDistance += pointDistance;
- }
-
- float minPrecision = minSegment / SUBLINE_COUNT; // number of subdivisions in each segment
- int precision = (int)Mathf.Ceil(totalDistance / minPrecision) * DISTANCE_COUNT;
-
- ptsAdj = new Vector3[ precision ];
- earlierPoint = interp( 0f );
- int num = 0;
- for(int i = 0; i < precision; i++){
- float fract = ((float)(i+1f)) / precision;
- Vector3 point = interp( fract );
- float dist = Vector3.Distance(point, earlierPoint);
- if(dist>=minPrecision){
- ptsAdj[num] = point;
-
- earlierPoint = point;
- // Debug.Log("fract:"+fract+" point:"+point);
- num++;
- }
- }
- // make sure there is a point at the very end
- /*num++;
- Vector3 endPoint = interp( 1f );
- ptsAdj[num] = endPoint;*/
- // Debug.Log("fract 1f endPoint:"+endPoint);
-
- ptsAdjLength = num;
- // Debug.Log("map 1f:"+map(1f)+" end:"+ptsAdj[ ptsAdjLength-1 ]);
-
- // Debug.Log("ptsAdjLength:"+ptsAdjLength+" minPrecision:"+minPrecision+" precision:"+precision);
-
- }
-
- public Vector3 map( float u ){
- if(u>=1f)
- return pts[ pts.Length - 2];
- float t = u * (ptsAdjLength-1);
- int first = (int)Mathf.Floor( t );
- int next = (int)Mathf.Ceil( t );
-
- Vector3 val = ptsAdj[ first ];
-
-
- Vector3 nextVal = ptsAdj[ next ];
- float diff = t - first;
-
- // Debug.Log("u:"+u+" val:"+val +" nextVal:"+nextVal+" diff:"+diff+" first:"+first+" next:"+next);
-
- val = val + (nextVal - val) * diff;
-
- return val;
- }
-
- public Vector3 interp(float t) {
- currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
- float u = t * (float) numSections - (float) currPt;
-
- // Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length );
- Vector3 a = pts[currPt];
- Vector3 b = pts[currPt + 1];
- Vector3 c = pts[currPt + 2];
- Vector3 d = pts[currPt + 3];
-
- return .5f * (
- (-a + 3f * b - 3f * c + d) * (u * u * u)
- + (2f * a - 5f * b + 4f * c - d) * (u * u)
- + (-a + c) * u
- + 2f * b
- );
- }
-
- /**
- * Retrieve a point along a path
- *
- * @method point
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @return {Vector3} Vector3 position of the point along the path
- * @example
- * transform.position = ltSpline.point( 0.6f );
- */
- public Vector3 point( float ratio ){
- float t = ratio>1f?1f:ratio;
-
- return map(t);
- }
-
- public void place2d( Transform transform, float ratio ){
- transform.position = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f){
- Vector3 v3Dir = point( ratio ) - transform.position;
- float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
- transform.eulerAngles = new Vector3(0, 0, angle);
- }
- }
-
- public void placeLocal2d( Transform transform, float ratio ){
- transform.localPosition = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f){
- Vector3 v3Dir = transform.parent.TransformPoint( point( ratio ) ) - transform.localPosition;
- float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
- transform.eulerAngles = new Vector3(0, 0, angle);
- }
- }
-
-
- /**
- * Place an object along a certain point on the path (facing the direction perpendicular to the path)
- *
- * @method place
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @example
- * ltPath.place( transform, 0.6f );
- */
- public void place( Transform transform, float ratio ){
- place(transform, ratio, Vector3.up);
- }
-
- /**
- * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path
- *
- * @method place
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
- * @example
- * ltPath.place( transform, 0.6f, Vector3.left );
- */
- public void place( Transform transform, float ratio, Vector3 worldUp ){
- transform.position = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f)
- transform.LookAt( point( ratio ), worldUp );
-
- }
-
- /**
- * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space
- *
- * @method placeLocal
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @example
- * ltPath.placeLocal( transform, 0.6f );
- */
- public void placeLocal( Transform transform, float ratio ){
- placeLocal( transform, ratio, Vector3.up );
- }
-
- /**
- * 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
- *
- * @method placeLocal
- * @param {Transform} transform:Transform the transform of the object you wish to place along the path
- * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1)
- * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up
- * @example
- * ltPath.placeLocal( transform, 0.6f, Vector3.left );
- */
- public void placeLocal( Transform transform, float ratio, Vector3 worldUp ){
- transform.localPosition = point( ratio );
- ratio += 0.001f;
- if(ratio<=1.0f)
- transform.LookAt( transform.parent.TransformPoint( point( ratio ) ), worldUp );
- }
-
- public void gizmoDraw(float t = -1.0f) {
-
- Vector3 prevPt = point(0);
-
- for (int i = 1; i <= 120; i++) {
- float pm = (float) i / 120f;
- Vector3 currPt2 = point(pm);
- //Gizmos.color = new Color(UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),UnityEngine.Random.Range(0f,1f),1);
- Gizmos.DrawLine(currPt2, prevPt);
- prevPt = currPt2;
- }
-
- }
-
- /*public Vector3 Velocity(float t) {
- t = map( t );
-
- int numSections = pts.Length - 3;
- int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
- float u = t * (float) numSections - (float) currPt;
-
- Vector3 a = pts[currPt];
- Vector3 b = pts[currPt + 1];
- Vector3 c = pts[currPt + 2];
- Vector3 d = pts[currPt + 3];
-
- return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u)
- + (2f * a -5f * b + 4f * c - d) * u
- + .5f * c - .5f * a;
- }*/
-}
-
-/**
-* Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method
-* Example Javascript: var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
-* LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );
-* function OnGUI(){
-* if(GUI.Button(bRect.rect, "Scale")){ }
-* }
-*
-* Example C#:
-* LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
-* LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f );
-* void OnGUI(){
-* if(GUI.Button(bRect.rect, "Scale")){ }
-* }
+* Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method