├── .gitignore ├── Assets ├── Flow.meta ├── Flow │ ├── DetectSimplePan.cs │ ├── DetectSimplePan.cs.meta │ ├── DetectTap.cs │ ├── DetectTap.cs.meta │ ├── Flow.unity │ ├── Flow.unity.meta │ ├── FlowView.cs │ ├── FlowView.cs.meta │ ├── Materials.meta │ ├── Materials │ │ ├── 1.mat │ │ ├── 1.mat.meta │ │ ├── 2.mat │ │ ├── 2.mat.meta │ │ ├── 3.mat │ │ ├── 3.mat.meta │ │ ├── 4.mat │ │ ├── 4.mat.meta │ │ ├── 5.mat │ │ ├── 5.mat.meta │ │ ├── 6.mat │ │ └── 6.mat.meta │ ├── Singleton.cs │ ├── Singleton.cs.meta │ ├── SmoothLookAt.cs │ └── SmoothLookAt.cs.meta ├── LeanTween.meta ├── LeanTween │ ├── LeanTween.cs │ └── LeanTween.cs.meta ├── TouchScript.meta └── TouchScript │ ├── Editor.meta │ ├── Editor │ ├── TouchScript.Editor.dll │ └── TouchScript.Editor.dll.meta │ ├── Plugins.meta │ └── Plugins │ ├── TouchScript.dll │ └── TouchScript.dll.meta ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Temp* 2 | Obj* 3 | Library* 4 | UpgradeLog.* 5 | *.csproj 6 | *.unityproj 7 | *.sln 8 | *.suo 9 | *.userprefs 10 | -* -------------------------------------------------------------------------------- /Assets/Flow.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 530dd6f66172b2b4f9cd782b84a26cf8 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Flow/DetectSimplePan.cs: -------------------------------------------------------------------------------- 1 | using TouchScript.Gestures; 2 | using TouchScript.Gestures.Simple; 3 | using UnityEngine; 4 | namespace ca.HenrySoftware.CoverFlow 5 | { 6 | public class DetectSimplePan : MonoBehaviour 7 | { 8 | public float Threshold = 0.1f; 9 | public void OnEnable() 10 | { 11 | GetComponent().StateChanged += HandleSimplePanStateChanged; 12 | } 13 | public void OnDisable() 14 | { 15 | GetComponent().StateChanged -= HandleSimplePanStateChanged; 16 | } 17 | private void HandleSimplePanStateChanged(object sender, TouchScript.Events.GestureStateChangeEventArgs e) 18 | { 19 | SimplePanGesture target = sender as SimplePanGesture; 20 | switch (e.State) 21 | { 22 | case Gesture.GestureState.Began: 23 | case Gesture.GestureState.Changed: 24 | if (target.LocalDeltaPosition != Vector3.zero) 25 | FlowView.Instance.Flow(target.LocalDeltaPosition.x); 26 | break; 27 | case Gesture.GestureState.Ended: 28 | float velocity = (target.LocalTransformCenter.x - target.PreviousLocalTransformCenter.x) * 0.5f; 29 | if (Mathf.Abs(velocity) > Threshold) 30 | FlowView.Instance.Inertia(velocity); 31 | else 32 | FlowView.Instance.Flow(); 33 | break; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Assets/Flow/DetectSimplePan.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4cb380670a94a24980c62f280886545 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Flow/DetectTap.cs: -------------------------------------------------------------------------------- 1 | using TouchScript.Gestures; 2 | using TouchScript.Gestures.Simple; 3 | using UnityEngine; 4 | namespace ca.HenrySoftware.CoverFlow 5 | { 6 | public class DetectTap : MonoBehaviour 7 | { 8 | public float Scale = 1.1f; 9 | public float Time = 0.333f; 10 | private Vector3 _origiginalScale; 11 | private int _tweenUp; 12 | private int _tweenDown; 13 | public void OnEnable() 14 | { 15 | GetComponent().StateChanged += HandleTap; 16 | GetComponent().StateChanged += HandlePress; 17 | GetComponent().StateChanged += HandleRelease; 18 | } 19 | public void OnDisable() 20 | { 21 | GetComponent().StateChanged -= HandleTap; 22 | GetComponent().StateChanged -= HandlePress; 23 | GetComponent().StateChanged -= HandleRelease; 24 | } 25 | protected void Awake() 26 | { 27 | _origiginalScale = gameObject.transform.localScale; 28 | } 29 | private void HandleTap(object sender, TouchScript.Events.GestureStateChangeEventArgs e) 30 | { 31 | if (e.State == Gesture.GestureState.Recognized) 32 | { 33 | FlowView.Instance.Flow(gameObject); 34 | } 35 | } 36 | private void HandlePress(object sender, TouchScript.Events.GestureStateChangeEventArgs e) 37 | { 38 | if (e.State == Gesture.GestureState.Recognized) 39 | { 40 | FlowView.Instance.StopInertia(); 41 | PressGesture gesture = sender as PressGesture; 42 | ScaleUp(gesture.gameObject); 43 | } 44 | } 45 | private void ScaleUp(GameObject o) 46 | { 47 | LeanTween.cancel(o, _tweenUp); 48 | LeanTween.cancel(o, _tweenDown); 49 | Vector3 to = Vector3.Scale(_origiginalScale, new Vector3(Scale, Scale, 1.0f)); 50 | _tweenUp = LeanTween.scale(o, to, Time).setEase(LeanTweenType.easeSpring).id; 51 | } 52 | private void HandleRelease(object sender, TouchScript.Events.GestureStateChangeEventArgs e) 53 | { 54 | if (e.State == Gesture.GestureState.Recognized) 55 | { 56 | ReleaseGesture gesture = sender as ReleaseGesture; 57 | ScaleDown(gesture.gameObject); 58 | } 59 | } 60 | private void ScaleDown(GameObject o) 61 | { 62 | _tweenDown = LeanTween.scale(o, _origiginalScale, Time).setEase(LeanTweenType.easeSpring).id; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Assets/Flow/DetectTap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 423e3ed39171f334b976439b9cf2f41e 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Flow/Flow.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/Assets/Flow/Flow.unity -------------------------------------------------------------------------------- /Assets/Flow/Flow.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f666fdd7d96db4a4bb78165ade20821d 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/FlowView.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | namespace ca.HenrySoftware.CoverFlow 3 | { 4 | public class FlowView : Singleton 5 | { 6 | public float Time = 0.333f; 7 | public int Offset = 1; 8 | public bool Clamp = true; 9 | public GameObject[] Views; 10 | private int _clamp; 11 | private int _current; 12 | private int _tweenInertia; 13 | protected void Start() 14 | { 15 | _clamp = Views.Length * Offset + 1; 16 | } 17 | public int GetClosestIndex() 18 | { 19 | int closestIndex = -1; 20 | float closestDistance = float.MaxValue; 21 | for (int i = 0; i < Views.Length; i++) 22 | { 23 | float distance = (Vector3.zero - Views[i].transform.localPosition).sqrMagnitude; 24 | if (distance < closestDistance) 25 | { 26 | closestIndex = i; 27 | closestDistance = distance; 28 | } 29 | } 30 | return closestIndex; 31 | } 32 | public void Flow() 33 | { 34 | Flow(GetClosestIndex()); 35 | } 36 | private int GetIndex(GameObject view) 37 | { 38 | int found = -1; 39 | for (int i = 0; i < Views.Length; i++) 40 | { 41 | if (view == Views[i]) 42 | { 43 | found = i; 44 | } 45 | } 46 | return found; 47 | } 48 | public void Flow(GameObject target) 49 | { 50 | int found = GetIndex(target); 51 | if (found != -1) 52 | { 53 | Flow(found); 54 | } 55 | } 56 | public void Flow(int target) 57 | { 58 | for (int i = 0; i < Views.Length; i++) 59 | { 60 | int delta = (target - i) * -1; 61 | Vector3 to = new Vector3(delta * Offset, 0.0f, Mathf.Abs(delta) * Offset); 62 | LeanTween.moveLocal(Views[i], to, Time).setEase(LeanTweenType.easeSpring); 63 | } 64 | _current = target; 65 | } 66 | public void Flow(float offset) 67 | { 68 | for (int i = 0; i < Views.Length; i++) 69 | { 70 | Vector3 p = Views[i].transform.localPosition; 71 | float newX = p.x + offset; 72 | bool negative = newX < 0; 73 | Vector3 newP; 74 | if (Clamp) 75 | { 76 | float clampX = Mathf.Clamp(newX, ClampXMin(i, negative), ClampXMax(i, negative)); 77 | float clampZ = Mathf.Clamp(Mathf.Abs(newX), 0.0f, ClampXMax(i, negative)); 78 | newP = new Vector3(clampX, p.y, clampZ); 79 | } 80 | else 81 | { 82 | newP = new Vector3(newX, p.y, Mathf.Abs(newX)); 83 | } 84 | Views[i].transform.localPosition = newP; 85 | } 86 | } 87 | private float ClampXMin(int index, bool negative) 88 | { 89 | float newIndex = negative ? index : newIndex = Views.Length - index - 1; 90 | return -(_clamp - (Offset * newIndex)); 91 | } 92 | private float ClampXMax(int index, bool negative) 93 | { 94 | float newIndex = negative ? index : newIndex = Views.Length - index - 1; 95 | return _clamp - (Offset * newIndex); 96 | } 97 | public void Inertia(float velocity) 98 | { 99 | _tweenInertia = LeanTween.value(gameObject, Flow, velocity, 0, 0.5f).setEase(LeanTweenType.easeInExpo).setOnComplete(Flow).id; 100 | } 101 | public void StopInertia() 102 | { 103 | LeanTween.cancel(gameObject, _tweenInertia); 104 | } 105 | protected void OnGUI() 106 | { 107 | if (GUI.Button(new Rect(10.0f, 10.0f, 64.0f, 64.0f), "<")) 108 | { 109 | if (_current > 0) 110 | { 111 | Flow(_current - 1); 112 | } 113 | } 114 | if (GUI.Button(new Rect(10.0f, 64.0f, 64.0f, 64.0f), ">")) 115 | { 116 | if (_current < Views.Length - 1) 117 | { 118 | Flow(_current + 1); 119 | } 120 | } 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Assets/Flow/FlowView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf09649b0f3e4a24fa8cd183d8efe591 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Flow/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2a1e8fd294e7a34d97eeae4eee2c445 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/1.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 3 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: 1 10 | m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: [] 12 | m_CustomRenderQueue: -1 13 | m_SavedProperties: 14 | serializedVersion: 2 15 | m_TexEnvs: 16 | data: 17 | first: 18 | name: _MainTex 19 | second: 20 | m_Texture: {fileID: 0} 21 | m_Scale: {x: 1, y: 1} 22 | m_Offset: {x: 0, y: 0} 23 | m_Floats: {} 24 | m_Colors: 25 | data: 26 | first: 27 | name: _Color 28 | second: {r: 1, g: 1, b: 1, a: 1} 29 | --- !u!1002 &2100001 30 | EditorExtensionImpl: 31 | serializedVersion: 6 32 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/1.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e446e70014b404f8ab25d0c0336c31c2 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/2.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 3 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: 2 10 | m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: [] 12 | m_CustomRenderQueue: -1 13 | m_SavedProperties: 14 | serializedVersion: 2 15 | m_TexEnvs: 16 | data: 17 | first: 18 | name: _MainTex 19 | second: 20 | m_Texture: {fileID: 0} 21 | m_Scale: {x: 1, y: 1} 22 | m_Offset: {x: 0, y: 0} 23 | m_Floats: {} 24 | m_Colors: 25 | data: 26 | first: 27 | name: _Color 28 | second: {r: 1, g: 0, b: 0, a: 1} 29 | --- !u!1002 &2100001 30 | EditorExtensionImpl: 31 | serializedVersion: 6 32 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/2.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4228a8c5856d4a7e87eda3e070bfa3d 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/3.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 3 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: 3 10 | m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: [] 12 | m_CustomRenderQueue: -1 13 | m_SavedProperties: 14 | serializedVersion: 2 15 | m_TexEnvs: 16 | data: 17 | first: 18 | name: _MainTex 19 | second: 20 | m_Texture: {fileID: 0} 21 | m_Scale: {x: 1, y: 1} 22 | m_Offset: {x: 0, y: 0} 23 | m_Floats: {} 24 | m_Colors: 25 | data: 26 | first: 27 | name: _Color 28 | second: {r: .10224995, g: .235882103, b: .76119405, a: 1} 29 | --- !u!1002 &2100001 30 | EditorExtensionImpl: 31 | serializedVersion: 6 32 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/3.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7637574f0b43642c89a9f4c98b2db420 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/4.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 3 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: 4 10 | m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: [] 12 | m_CustomRenderQueue: -1 13 | m_SavedProperties: 14 | serializedVersion: 2 15 | m_TexEnvs: 16 | data: 17 | first: 18 | name: _MainTex 19 | second: 20 | m_Texture: {fileID: 0} 21 | m_Scale: {x: 1, y: 1} 22 | m_Offset: {x: 0, y: 0} 23 | m_Floats: {} 24 | m_Colors: 25 | data: 26 | first: 27 | name: _Color 28 | second: {r: .138115376, g: .597014904, b: .48148784, a: 1} 29 | --- !u!1002 &2100001 30 | EditorExtensionImpl: 31 | serializedVersion: 6 32 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/4.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84472d48cb4114d65a98cbea44b3385e 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/5.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 3 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: 5 10 | m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: [] 12 | m_CustomRenderQueue: -1 13 | m_SavedProperties: 14 | serializedVersion: 2 15 | m_TexEnvs: 16 | data: 17 | first: 18 | name: _MainTex 19 | second: 20 | m_Texture: {fileID: 0} 21 | m_Scale: {x: 1, y: 1} 22 | m_Offset: {x: 0, y: 0} 23 | m_Floats: {} 24 | m_Colors: 25 | data: 26 | first: 27 | name: _Color 28 | second: {r: .0571396798, g: .402985096, b: .0837431103, a: 1} 29 | --- !u!1002 &2100001 30 | EditorExtensionImpl: 31 | serializedVersion: 6 32 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/5.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 740ef90dbbac8449a85e50cc03fb8380 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/6.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 3 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: 6 10 | m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: [] 12 | m_CustomRenderQueue: -1 13 | m_SavedProperties: 14 | serializedVersion: 2 15 | m_TexEnvs: 16 | data: 17 | first: 18 | name: _MainTex 19 | second: 20 | m_Texture: {fileID: 0} 21 | m_Scale: {x: 1, y: 1} 22 | m_Offset: {x: 0, y: 0} 23 | m_Floats: {} 24 | m_Colors: 25 | data: 26 | first: 27 | name: _Color 28 | second: {r: .690456271, g: .708955228, b: .0476163998, a: 1} 29 | --- !u!1002 &2100001 30 | EditorExtensionImpl: 31 | serializedVersion: 6 32 | -------------------------------------------------------------------------------- /Assets/Flow/Materials/6.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a505d5be7e407418b878b8b9325235c5 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Flow/Singleton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | namespace ca.HenrySoftware.CoverFlow 3 | { 4 | public class Singleton : MonoBehaviour where T : MonoBehaviour 5 | { 6 | protected static T instance; 7 | public static T Instance 8 | { 9 | get 10 | { 11 | if (instance == null) 12 | { 13 | instance = (T)FindObjectOfType(typeof(T)); 14 | if (instance == null) 15 | { 16 | Debug.LogError("An instance of " + typeof(T) + " is needed in the scene, but there is none."); 17 | } 18 | } 19 | return instance; 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Assets/Flow/Singleton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a75b7c27a9c60e4087a3faaf1b1599c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Flow/SmoothLookAt.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | public class SmoothLookAt : MonoBehaviour 4 | { 5 | public Transform Target; 6 | public float Damping = 6.0f; 7 | public bool Smooth = true; 8 | private void Start() 9 | { 10 | if (rigidbody) 11 | rigidbody.freezeRotation = true; 12 | } 13 | protected void LateUpdate() 14 | { 15 | if (Target) 16 | { 17 | if (Smooth) 18 | { 19 | var rotation = Quaternion.LookRotation(Target.position - transform.position); 20 | transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping); 21 | } 22 | else 23 | { 24 | transform.LookAt(Target); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/Flow/SmoothLookAt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 713aefa41020bfb4eafa817c68a9625b 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/LeanTween.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a3f1b53a79c3014285a9a3699db58e3 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/LeanTween/LeanTween.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Russell Savage - Dented Pixel 2 | // 3 | // LeanTween version 2.12 - http://dentedpixel.com/developer-diary/ 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | /* 24 | TERMS OF USE - EASING EQUATIONS# 25 | Open source under the BSD License. 26 | Copyright (c)2001 Robert Penner 27 | All rights reserved. 28 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 29 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 30 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 31 | Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /** 36 | * Pass this to the "ease" parameter in the optional hashtable, to get a different easing behavior

37 | * Example:
LeanTween.rotateX(gameObject, 270.0f, 1.5f).setEase(LeanTweenType.easeInBack); 38 | * 39 | * @class LeanTweenType 40 | */ 41 | 42 | using System; 43 | using System.Collections; 44 | /** 45 | * @property {integer} linear 46 | */ 47 | /** 48 | * @property {integer} easeOutQuad 49 | */ 50 | /** 51 | * @property {integer} easeInQuad 52 | */ 53 | /** 54 | * @property {integer} easeInOutQuad 55 | */ 56 | /** 57 | * @property {integer} easeInCubic 58 | */ 59 | /** 60 | * @property {integer} easeOutCubic 61 | */ 62 | /** 63 | * @property {integer} easeInOutCubic 64 | */ 65 | /** 66 | * @property {integer} easeInQuart 67 | */ 68 | /** 69 | * @property {integer} easeOutQuart 70 | */ 71 | /** 72 | * @property {integer} easeInOutQuart 73 | */ 74 | /** 75 | * @property {integer} easeInQuint 76 | */ 77 | /** 78 | * @property {integer} easeOutQuint 79 | */ 80 | /** 81 | * @property {integer} easeInOutQuint 82 | */ 83 | /** 84 | * @property {integer} easeInSine 85 | */ 86 | /** 87 | * @property {integer} easeOutSine 88 | */ 89 | /** 90 | * @property {integer} easeInOutSine 91 | */ 92 | /** 93 | * @property {integer} easeInExpo 94 | */ 95 | /** 96 | * @property {integer} easeOutExpo 97 | */ 98 | /** 99 | * @property {integer} easeInOutExpo 100 | */ 101 | /** 102 | * @property {integer} easeInCirc 103 | */ 104 | /** 105 | * @property {integer} easeOutCirc 106 | */ 107 | /** 108 | * @property {integer} easeInOutCirc 109 | */ 110 | /** 111 | * @property {integer} easeInBounce 112 | */ 113 | /** 114 | * @property {integer} easeOutBounce 115 | */ 116 | /** 117 | * @property {integer} easeInOutBounce 118 | */ 119 | /** 120 | * @property {integer} easeInBack 121 | */ 122 | /** 123 | * @property {integer} easeOutBack 124 | */ 125 | /** 126 | * @property {integer} easeInOutBack 127 | */ 128 | /** 129 | * @property {integer} easeInElastic 130 | */ 131 | /** 132 | * @property {integer} easeOutElastic 133 | */ 134 | /** 135 | * @property {integer} easeInOutElastic 136 | */ 137 | /** 138 | * @property {integer} punch 139 | */ 140 | using UnityEngine; 141 | public enum LeanTweenType 142 | { 143 | notUsed, linear, easeOutQuad, easeInQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, 144 | easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, 145 | easeInBounce, easeOutBounce, easeInOutBounce, easeInBack, easeOutBack, easeInOutBack, easeInElastic, easeOutElastic, easeInOutElastic, easeSpring, easeShake, punch, once, clamp, pingPong, animationCurve 146 | } 147 | 148 | /** 149 | * Internal Representation of a Tween
150 | *
151 | * This class represents all of the optional parameters you can pass to a method (it also represents the internal representation of the tween).

152 | * Optional Parameters are passed at the end of every method:
153 | *
154 | *   Example:
155 | *   LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
156 | *
157 | * You can pass the optional parameters in any order, and chain on as many as you wish.
158 | * You can also pass parameters at a later time by saving a reference to what is returned.
159 | *
160 | *   Example:
161 | *   LTDescr d = LeanTween.moveX(gameObject, 1f, 1f);
162 | *     ...later set some parameters
163 | *   d.setOnComplete( onCompleteFunc ).setEase( LeanTweenType.easeInOutBack );
164 | *
165 | * Retrieve a unique id for the tween by using the "id" property. You can pass this to LeanTween.pause, LeanTween.resume, LeanTween.cancel methods
166 | *
167 | *   Example:
168 | *   int id = LeanTween.moveX(gameObject, 1f, 3f).id;
169 | *   LeanTween.pause( id );
170 | * @class LTDescr 171 | * @constructor 172 | */ 173 | public class LTDescr 174 | { 175 | public bool toggle; 176 | public bool useEstimatedTime; 177 | public bool useFrames; 178 | public bool hasInitiliazed; 179 | public bool hasPhysics; 180 | public float passed; 181 | public float delay; 182 | public float time; 183 | public float lastVal; 184 | private uint _id; 185 | public int loopCount; 186 | public uint counter; 187 | public float direction; 188 | public bool destroyOnComplete; 189 | public Transform trans; 190 | public LTRect ltRect; 191 | public Vector3 from; 192 | public Vector3 to; 193 | public Vector3 diff; 194 | public Vector3 point; 195 | public Vector3 axis; 196 | public Quaternion origRotation; 197 | public LTBezierPath path; 198 | public TweenAction type; 199 | public LeanTweenType tweenType; 200 | public AnimationCurve animationCurve; 201 | public LeanTweenType loopType; 202 | public Action onUpdateFloat; 203 | public Action onUpdateFloatObject; 204 | public Action onUpdateVector3; 205 | public Action onUpdateVector3Object; 206 | public Action onComplete; 207 | public Action onCompleteObject; 208 | public object onCompleteParam; 209 | public object onUpdateParam; 210 | #if !UNITY_METRO 211 | public Hashtable optional; 212 | #endif 213 | 214 | private static uint global_counter = 0; 215 | 216 | public override string ToString() 217 | { 218 | return (trans != null ? "gameObject:" + trans.gameObject : "gameObject:null") + " toggle:" + toggle + " passed:" + passed + " time:" + time + " delay:" + delay + " from:" + from + " to:" + to + " type:" + type + " useEstimatedTime:" + useEstimatedTime + " id:" + id + " hasInitiliazed:" + hasInitiliazed; 219 | } 220 | 221 | public LTDescr() 222 | { 223 | } 224 | 225 | /** 226 | * Cancel a tween 227 | * 228 | * @method cancel 229 | * @return {LTDescr} LTDescr an object that distinguishes the tween 230 | */ 231 | public LTDescr cancel() 232 | { 233 | LeanTween.removeTween((int)this._id); 234 | return this; 235 | } 236 | 237 | public int uniqueId 238 | { 239 | get 240 | { 241 | uint toId = _id | counter << 16; 242 | 243 | /*uint backId = toId & 0xFFFF; 244 | uint backCounter = toId >> 16; 245 | if(_id!=backId || backCounter!=counter){ 246 | Debug.LogError("BAD CONVERSION toId:"+_id); 247 | }*/ 248 | 249 | return (int)toId; 250 | } 251 | } 252 | 253 | public int id 254 | { 255 | get 256 | { 257 | return uniqueId; 258 | } 259 | } 260 | 261 | public void reset() 262 | { 263 | this.toggle = true; 264 | #if !UNITY_METRO 265 | this.optional = null; 266 | #endif 267 | this.destroyOnComplete = false; 268 | this.passed = this.delay = 0.0f; 269 | this.useEstimatedTime = this.useFrames = this.hasInitiliazed = false; 270 | this.animationCurve = null; 271 | this.tweenType = LeanTweenType.linear; 272 | this.loopType = LeanTweenType.once; 273 | this.loopCount = 0; 274 | this.direction = this.lastVal = 1.0f; 275 | this.onUpdateFloat = null; 276 | this.onUpdateVector3 = null; 277 | this.onUpdateFloatObject = null; 278 | this.onUpdateVector3Object = null; 279 | this.onComplete = null; 280 | this.onCompleteObject = null; 281 | this.onCompleteParam = null; 282 | this.point = Vector3.zero; 283 | } 284 | 285 | /** 286 | * Pause a tween 287 | * 288 | * @method pause 289 | * @return {LTDescr} LTDescr an object that distinguishes the tween 290 | */ 291 | public LTDescr pause() 292 | { 293 | if (this.direction != 0.0f) 294 | { // check if tween is already paused 295 | this.lastVal = this.direction; 296 | this.direction = 0.0f; 297 | } 298 | 299 | return this; 300 | } 301 | 302 | /** 303 | * Resume a paused tween 304 | * 305 | * @method resume 306 | * @return {LTDescr} LTDescr an object that distinguishes the tween 307 | */ 308 | public LTDescr resume() 309 | { 310 | this.direction = this.lastVal; 311 | return this; 312 | } 313 | 314 | public LTDescr setAxis(Vector3 axis) 315 | { 316 | this.axis = axis; 317 | return this; 318 | } 319 | 320 | /** 321 | * Delay the start of a tween 322 | * 323 | * @method setDelay 324 | * @param {float} float time The time to complete the tween in 325 | * @return {LTDescr} LTDescr an object that distinguishes the tween 326 | * @example 327 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setDelay( 1.5f ); 328 | */ 329 | public LTDescr setDelay(float delay) 330 | { 331 | if (this.useEstimatedTime) 332 | { 333 | this.delay = delay; 334 | } 335 | else 336 | { 337 | this.delay = delay * Time.timeScale; 338 | } 339 | 340 | return this; 341 | } 342 | 343 | /** 344 | * Set the type of easing used for the tween.
345 | * 348 | * 349 | * @method setEase 350 | * @param {LeanTweenType} easeType:LeanTweenType the easing type to use 351 | * @return {LTDescr} LTDescr an object that distinguishes the tween 352 | * @example 353 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce ); 354 | */ 355 | public LTDescr setEase(LeanTweenType easeType) 356 | { 357 | this.tweenType = easeType; 358 | return this; 359 | } 360 | 361 | /** 362 | * Set the type of easing used for the tween with a custom curve.
363 | * @method setEase (AnimationCurve) 364 | * @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 365 | * @return {LTDescr} LTDescr an object that distinguishes the tween 366 | * @example 367 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeInBounce ); 368 | */ 369 | public LTDescr setEase(AnimationCurve easeCurve) 370 | { 371 | this.animationCurve = easeCurve; 372 | return this; 373 | } 374 | 375 | public LTDescr setTo(Vector3 to) 376 | { 377 | this.to = to; 378 | return this; 379 | } 380 | 381 | public LTDescr setFrom(Vector3 from) 382 | { 383 | this.from = from; 384 | this.hasInitiliazed = true; // this is set, so that the "from" value isn't overwritten later on when the tween starts 385 | this.diff = this.to - this.from; 386 | return this; 387 | } 388 | 389 | public LTDescr setId(uint id) 390 | { 391 | this._id = id; 392 | this.counter = global_counter; 393 | return this; 394 | } 395 | 396 | /** 397 | * Set the tween to repeat a number of times. 398 | * @method setRepeat 399 | * @param {int} repeatNum:int the number of times to repeat the tween. -1 to repeat infinite times 400 | * @return {LTDescr} LTDescr an object that distinguishes the tween 401 | * @example 402 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 10 ).setLoopPingPong(); 403 | */ 404 | public LTDescr setRepeat(int repeat) 405 | { 406 | this.loopCount = repeat; 407 | if ((repeat > 1 && this.loopType == LeanTweenType.once) || (repeat < 0 && this.loopType == LeanTweenType.once)) 408 | { 409 | this.loopType = LeanTweenType.clamp; 410 | } 411 | return this; 412 | } 413 | 414 | public LTDescr setLoopType(LeanTweenType loopType) 415 | { 416 | this.loopType = loopType; 417 | return this; 418 | } 419 | 420 | /** 421 | * Use estimated time when tweening an object. Great for pause screens, when you want all other action to be stopped (or slowed down) 422 | * @method setUseEstimatedTime 423 | * @param {bool} useEstimatedTime:bool whether to use estimated time or not 424 | * @return {LTDescr} LTDescr an object that distinguishes the tween 425 | * @example 426 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseEstimatedTime( true ); 427 | */ 428 | public LTDescr setUseEstimatedTime(bool useEstimatedTime) 429 | { 430 | this.useEstimatedTime = useEstimatedTime; 431 | return this; 432 | } 433 | 434 | /** 435 | * Use frames when tweening an object, when you don't want the animation to be time-frame independent... 436 | * @method setUseFrames 437 | * @param {bool} useFrames:bool whether to use estimated time or not 438 | * @return {LTDescr} LTDescr an object that distinguishes the tween 439 | * @example 440 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat( 2 ).setUseFrames( true ); 441 | */ 442 | public LTDescr setUseFrames(bool useFrames) 443 | { 444 | this.useFrames = useFrames; 445 | return this; 446 | } 447 | 448 | public LTDescr setLoopCount(int loopCount) 449 | { 450 | this.loopCount = loopCount; 451 | return this; 452 | } 453 | 454 | /** 455 | * No looping involved, just run once (the default) 456 | * @method setLoopOnce 457 | * @return {LTDescr} LTDescr an object that distinguishes the tween 458 | * @example 459 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setLoopOnce(); 460 | */ 461 | public LTDescr setLoopOnce() 462 | { 463 | this.loopType = LeanTweenType.once; return this; 464 | } 465 | 466 | /** 467 | * When the animation gets to the end it starts back at where it began 468 | * @method setLoopClamp 469 | * @return {LTDescr} LTDescr an object that distinguishes the tween 470 | * @example 471 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat(2).setLoopClamp(); 472 | */ 473 | public LTDescr setLoopClamp() 474 | { 475 | this.loopType = LeanTweenType.clamp; 476 | if (this.loopCount == 0) 477 | this.loopCount = -1; 478 | return this; 479 | } 480 | 481 | /** 482 | * When the animation gets to the end it then tweens back to where it started (and on, and on) 483 | * @method setLoopPingPong 484 | * @return {LTDescr} LTDescr an object that distinguishes the tween 485 | * @example 486 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setRepeat(2).setLoopPingPong(); 487 | */ 488 | public LTDescr setLoopPingPong() 489 | { 490 | this.loopType = LeanTweenType.pingPong; 491 | if (this.loopCount == 0) 492 | this.loopCount = -1; 493 | return this; 494 | } 495 | 496 | /** 497 | * Have a method called when the tween finishes 498 | * @method setOnComplete 499 | * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished(){ } 500 | * @return {LTDescr} LTDescr an object that distinguishes the tween 501 | * @example 502 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); 503 | */ 504 | public LTDescr setOnComplete(Action onComplete) 505 | { 506 | this.onComplete = onComplete; 507 | return this; 508 | } 509 | 510 | /** 511 | * Have a method called when the tween finishes 512 | * @method setOnComplete (object) 513 | * @param {Action} onComplete:Action the method that should be called when the tween is finished ex: tweenFinished( object myObj ){ } 514 | * @return {LTDescr} LTDescr an object that distinguishes the tween 515 | * @example 516 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); 517 | */ 518 | public LTDescr setOnComplete(Action onComplete) 519 | { 520 | this.onCompleteObject = onComplete; 521 | return this; 522 | } 523 | public LTDescr setOnComplete(Action onComplete, object onCompleteParam) 524 | { 525 | this.onCompleteObject = onComplete; 526 | if (onCompleteParam != null) 527 | this.onCompleteParam = onCompleteParam; 528 | return this; 529 | } 530 | 531 | /** 532 | * Pass an object to along with the onComplete Function 533 | * @method setOnCompleteParam 534 | * @param {object} onComplete:object an object that 535 | * @return {LTDescr} LTDescr an object that distinguishes the tween 536 | * @example 537 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished ); 538 | */ 539 | public LTDescr setOnCompleteParam(object onCompleteParam) 540 | { 541 | this.onCompleteParam = onCompleteParam; 542 | return this; 543 | } 544 | 545 | /** 546 | * Have a method called on each frame that the tween is being animated (passes a float value) 547 | * @method setOnUpdate 548 | * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object 549 | * @return {LTDescr} LTDescr an object that distinguishes the tween 550 | * @example 551 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );
552 | *
553 | * void tweenMoved( float val ){ }
554 | */ 555 | public LTDescr setOnUpdate(Action onUpdate) 556 | { 557 | this.onUpdateFloat = onUpdate; 558 | return this; 559 | } 560 | 561 | public LTDescr setOnUpdateObject(Action onUpdate) 562 | { 563 | this.onUpdateFloatObject = onUpdate; 564 | return this; 565 | } 566 | public LTDescr setOnUpdateVector3(Action onUpdate) 567 | { 568 | this.onUpdateVector3 = onUpdate; 569 | return this; 570 | } 571 | 572 | #if !UNITY_FLASH 573 | /** 574 | * Have a method called on each frame that the tween is being animated (passes a float value and a object) 575 | * @method setOnUpdate (object) 576 | * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object, and an object of the person's choosing 577 | * @return {LTDescr} LTDescr an object that distinguishes the tween 578 | * @example 579 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );
580 | *
581 | * void tweenMoved( float val, object obj ){ }
582 | */ 583 | public LTDescr setOnUpdate(Action onUpdate, object onUpdateParam = null) 584 | { 585 | this.onUpdateFloatObject = onUpdate; 586 | if (onUpdateParam != null) 587 | this.onUpdateParam = onUpdateParam; 588 | return this; 589 | } 590 | 591 | public LTDescr setOnUpdate(Action onUpdate, object onUpdateParam = null) 592 | { 593 | this.onUpdateVector3Object = onUpdate; 594 | if (onUpdateParam != null) 595 | this.onUpdateParam = onUpdateParam; 596 | return this; 597 | } 598 | 599 | /** 600 | * Have a method called on each frame that the tween is being animated (passes a float value) 601 | * @method setOnUpdate (Vector3) 602 | * @param {Action} onUpdate:Action a method that will be called on every frame with the float value of the tweened object 603 | * @return {LTDescr} LTDescr an object that distinguishes the tween 604 | * @example 605 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved );
606 | *
607 | * void tweenMoved( Vector3 val ){ }
608 | */ 609 | public LTDescr setOnUpdate(Action onUpdate, object onUpdateParam = null) 610 | { 611 | this.onUpdateVector3 = onUpdate; 612 | if (onUpdateParam != null) 613 | this.onUpdateParam = onUpdateParam; 614 | return this; 615 | } 616 | #endif 617 | 618 | /** 619 | * Have an object passed along with the onUpdate method 620 | * @method setOnUpdateParam 621 | * @param {object} onUpdateParam:object an object that will be passed along with the onUpdate method 622 | * @return {LTDescr} LTDescr an object that distinguishes the tween 623 | * @example 624 | * LeanTween.moveX(gameObject, 5f, 2.0f ).setOnUpdate( tweenMoved ).setOnUpdateParam( myObject );
625 | *
626 | * void tweenMoved( float val, object obj ){ }
627 | */ 628 | public LTDescr setOnUpdateParam(object onUpdateParam) 629 | { 630 | this.onUpdateParam = onUpdateParam; 631 | return this; 632 | } 633 | 634 | /** 635 | * While tweening along a curve, set this property to true, to be perpendicalur to the path it is moving upon 636 | * @method setOrientToPath 637 | * @param {bool} doesOrient:bool whether the gameobject will orient to the path it is animating along 638 | * @return {LTDescr} LTDescr an object that distinguishes the tween 639 | * @example 640 | * LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true);
641 | */ 642 | public LTDescr setOrientToPath(bool doesOrient) 643 | { 644 | if (this.path == null) 645 | this.path = new LTBezierPath(); 646 | this.path.orientToPath = doesOrient; 647 | return this; 648 | } 649 | 650 | public LTDescr setRect(LTRect rect) 651 | { 652 | this.ltRect = rect; 653 | return this; 654 | } 655 | 656 | public LTDescr setRect(Rect rect) 657 | { 658 | this.ltRect = new LTRect(rect); 659 | return this; 660 | } 661 | 662 | public LTDescr setPath(LTBezierPath path) 663 | { 664 | this.path = path; 665 | return this; 666 | } 667 | 668 | /** 669 | * Set the point at which the GameObject will be rotated around 670 | * @method setPoint 671 | * @param {Vector3} point:Vector3 point at which you want the object to rotate around (local space) 672 | * @return {LTDescr} LTDescr an object that distinguishes the tween 673 | * @example 674 | * LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ) .setPoint( new Vector3(1f,0f,0f) ) .setEase( LeanTweenType.easeInOutBounce );
675 | */ 676 | public LTDescr setPoint(Vector3 point) 677 | { 678 | this.point = point; 679 | return this; 680 | } 681 | 682 | public LTDescr setDestroyOnComplete(bool doesDestroy) 683 | { 684 | this.destroyOnComplete = doesDestroy; 685 | return this; 686 | } 687 | } 688 | 689 | /** 690 | * Animate GUI Elements by creating this object and passing the *.rect variable to the GUI method

691 | * Example Javascript:
var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
692 | * LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );
693 | * function OnGUI(){
694 | *   if(GUI.Button(bRect.rect, "Scale")){ }
695 | * }
696 | *
697 | * Example C#:
698 | * LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
699 | * LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f );
700 | * void OnGUI(){
701 | *   if(GUI.Button(bRect.rect, "Scale")){ }
702 | * }
703 | * 704 | * @class LTRect 705 | * @constructor 706 | * @param {float} x:float X location 707 | * @param {float} y:float Y location 708 | * @param {float} width:float Width 709 | * @param {float} height:float Height 710 | * @param {float} alpha:float (Optional) initial alpha amount (0-1) 711 | * @param {float} rotation:float (Optional) initial rotation in degrees (0-360) 712 | */ 713 | 714 | [System.Serializable] 715 | public class LTRect : System.Object 716 | { 717 | /** 718 | * Pass this value to the GUI Methods 719 | * 720 | * @property rect 721 | * @type {Rect} rect:Rect Rect object that controls the positioning and size 722 | */ 723 | public Rect _rect; 724 | public float alpha = 1f; 725 | public float rotation; 726 | public Vector2 pivot; 727 | public Vector2 margin; 728 | public Rect relativeRect; 729 | 730 | public bool rotateEnabled; 731 | [HideInInspector] 732 | public bool rotateFinished; 733 | public bool alphaEnabled; 734 | public string labelStr; 735 | public LTGUI.Element_Type type; 736 | public GUIStyle style; 737 | public bool useColor = false; 738 | public Color color = Color.white; 739 | public bool fontScaleToFit; 740 | public bool useSimpleScale; 741 | public bool sizeByHeight; 742 | 743 | public Texture texture; 744 | 745 | private int _id = -1; 746 | [HideInInspector] 747 | public int counter; 748 | 749 | public static bool colorTouched; 750 | 751 | public LTRect() 752 | { 753 | reset(); 754 | this.rotateEnabled = this.alphaEnabled = true; 755 | _rect = new Rect(0f, 0f, 1f, 1f); 756 | } 757 | 758 | public LTRect(Rect rect) 759 | { 760 | _rect = rect; 761 | reset(); 762 | } 763 | 764 | public LTRect(float x, float y, float width, float height) 765 | { 766 | _rect = new Rect(x, y, width, height); 767 | this.alpha = 1.0f; 768 | this.rotation = 0.0f; 769 | this.rotateEnabled = this.alphaEnabled = false; 770 | } 771 | 772 | public LTRect(float x, float y, float width, float height, float alpha) 773 | { 774 | _rect = new Rect(x, y, width, height); 775 | this.alpha = alpha; 776 | this.rotation = 0.0f; 777 | this.rotateEnabled = this.alphaEnabled = false; 778 | } 779 | 780 | public LTRect(float x, float y, float width, float height, float alpha, float rotation) 781 | { 782 | _rect = new Rect(x, y, width, height); 783 | this.alpha = alpha; 784 | this.rotation = rotation; 785 | this.rotateEnabled = this.alphaEnabled = false; 786 | if (rotation != 0.0f) 787 | { 788 | this.rotateEnabled = true; 789 | resetForRotation(); 790 | } 791 | } 792 | 793 | public bool hasInitiliazed 794 | { 795 | get 796 | { 797 | return _id != -1; 798 | } 799 | } 800 | 801 | public int id 802 | { 803 | get 804 | { 805 | int toId = _id | counter << 16; 806 | 807 | /*uint backId = toId & 0xFFFF; 808 | uint backCounter = toId >> 16; 809 | if(_id!=backId || backCounter!=counter){ 810 | Debug.LogError("BAD CONVERSION toId:"+_id); 811 | }*/ 812 | 813 | return toId; 814 | } 815 | } 816 | 817 | public void setId(int id, int counter) 818 | { 819 | this._id = id; 820 | this.counter = counter; 821 | } 822 | 823 | public void reset() 824 | { 825 | this.alpha = 1.0f; 826 | this.rotation = 0.0f; 827 | this.rotateEnabled = this.alphaEnabled = false; 828 | this.margin = Vector2.zero; 829 | this.sizeByHeight = false; 830 | this.useColor = false; 831 | } 832 | 833 | public void resetForRotation() 834 | { 835 | Vector3 scale = new Vector3(GUI.matrix[0, 0], GUI.matrix[1, 1], GUI.matrix[2, 2]); 836 | if (pivot == Vector2.zero) 837 | { 838 | pivot = new Vector2((_rect.x + ((_rect.width) * 0.5f)) * scale.x + GUI.matrix[0, 3], (_rect.y + ((_rect.height) * 0.5f)) * scale.y + GUI.matrix[1, 3]); 839 | } 840 | } 841 | 842 | public float x 843 | { 844 | get { return _rect.x; } 845 | set { _rect.x = value; } 846 | } 847 | 848 | public float y 849 | { 850 | get { return _rect.y; } 851 | set { _rect.y = value; } 852 | } 853 | 854 | public float width 855 | { 856 | get { return _rect.width; } 857 | set { _rect.width = value; } 858 | } 859 | 860 | public float height 861 | { 862 | get { return _rect.height; } 863 | set { _rect.height = value; } 864 | } 865 | 866 | public Rect rect 867 | { 868 | get 869 | { 870 | if (colorTouched) 871 | { 872 | colorTouched = false; 873 | GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 1.0f); 874 | } 875 | if (rotateEnabled) 876 | { 877 | if (rotateFinished) 878 | { 879 | rotateFinished = false; 880 | rotateEnabled = false; 881 | //this.rotation = 0.0f; 882 | pivot = Vector2.zero; 883 | } 884 | else 885 | { 886 | GUIUtility.RotateAroundPivot(rotation, pivot); 887 | } 888 | } 889 | if (alphaEnabled) 890 | { 891 | GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha); 892 | colorTouched = true; 893 | } 894 | if (fontScaleToFit) 895 | { 896 | if (this.useSimpleScale) 897 | { 898 | style.fontSize = (int)(_rect.height * this.relativeRect.height); 899 | } 900 | else 901 | { 902 | style.fontSize = (int)_rect.height; 903 | } 904 | } 905 | return _rect; 906 | } 907 | 908 | set 909 | { 910 | _rect = value; 911 | } 912 | } 913 | 914 | public LTRect setStyle(GUIStyle style) 915 | { 916 | this.style = style; 917 | return this; 918 | } 919 | 920 | public LTRect setFontScaleToFit(bool fontScaleToFit) 921 | { 922 | this.fontScaleToFit = fontScaleToFit; 923 | return this; 924 | } 925 | 926 | public LTRect setColor(Color color) 927 | { 928 | this.color = color; 929 | this.useColor = true; 930 | return this; 931 | } 932 | 933 | public LTRect setAlpha(float alpha) 934 | { 935 | this.alpha = alpha; 936 | return this; 937 | } 938 | 939 | public LTRect setLabel(String str) 940 | { 941 | this.labelStr = str; 942 | return this; 943 | } 944 | 945 | public LTRect setUseSimpleScale(bool useSimpleScale, Rect relativeRect) 946 | { 947 | this.useSimpleScale = useSimpleScale; 948 | this.relativeRect = relativeRect; 949 | return this; 950 | } 951 | 952 | public LTRect setUseSimpleScale(bool useSimpleScale) 953 | { 954 | this.useSimpleScale = useSimpleScale; 955 | this.relativeRect = new Rect(0f, 0f, Screen.width, Screen.height); 956 | return this; 957 | } 958 | 959 | public LTRect setSizeByHeight(bool sizeByHeight) 960 | { 961 | this.sizeByHeight = sizeByHeight; 962 | return this; 963 | } 964 | 965 | public override string ToString() 966 | { 967 | return "x:" + _rect.x + " y:" + _rect.y + " width:" + _rect.width + " height:" + _rect.height; 968 | } 969 | } 970 | 971 | public class LTBezier 972 | { 973 | public float length; 974 | 975 | private Vector3 a; 976 | private Vector3 aa; 977 | private Vector3 bb; 978 | private Vector3 cc; 979 | private float len; 980 | private float[] arcLengths; 981 | 982 | public LTBezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float precision) 983 | { 984 | this.a = a; 985 | aa = (-a + 3 * (b - c) + d); 986 | bb = 3 * (a + c) - 6 * b; 987 | cc = 3 * (b - a); 988 | 989 | this.len = 1.0f / precision; 990 | arcLengths = new float[(int)this.len + (int)1]; 991 | arcLengths[0] = 0; 992 | 993 | Vector3 ov = a; 994 | Vector3 v; 995 | float clen = 0.0f; 996 | for (int i = 1; i <= this.len; i++) 997 | { 998 | v = bezierPoint(i * precision); 999 | clen += (ov - v).magnitude; 1000 | this.arcLengths[i] = clen; 1001 | ov = v; 1002 | } 1003 | this.length = clen; 1004 | } 1005 | 1006 | private float map(float u) 1007 | { 1008 | float targetLength = u * this.arcLengths[(int)this.len]; 1009 | int low = 0; 1010 | int high = (int)this.len; 1011 | int index = 0; 1012 | while (low < high) 1013 | { 1014 | index = low + ((int)((high - low) / 2.0f) | 0); 1015 | if (this.arcLengths[index] < targetLength) 1016 | { 1017 | low = index + 1; 1018 | } 1019 | else 1020 | { 1021 | high = index; 1022 | } 1023 | } 1024 | if (this.arcLengths[index] > targetLength) 1025 | index--; 1026 | if (index < 0) 1027 | index = 0; 1028 | 1029 | return (index + (targetLength - arcLengths[index]) / (arcLengths[index + 1] - arcLengths[index])) / this.len; 1030 | } 1031 | 1032 | private Vector3 bezierPoint(float t) 1033 | { 1034 | return ((aa * t + (bb)) * t + cc) * t + a; 1035 | } 1036 | 1037 | public Vector3 point(float t) 1038 | { 1039 | return bezierPoint(map(t)); 1040 | } 1041 | } 1042 | 1043 | /** 1044 | * Manually animate along a bezier path with this class 1045 | * @class LTBezierPath 1046 | * @constructor 1047 | * @param {float} pts:Vector3[] 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) 1048 | * @example 1049 | * 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)} );

1050 | * LeanTween.move(lt, ltPath.vec3, 4.0).setOrientToPath(true).setDelay(1f).setEase(LeanTweenType.easeInOutQuad); // animate
1051 | * float pt = ltPath.point( 0.6 ); // retrieve a point along the path 1052 | */ 1053 | public class LTBezierPath 1054 | { 1055 | public Vector3[] pts; 1056 | public float length; 1057 | public bool orientToPath; 1058 | 1059 | private LTBezier[] beziers; 1060 | private float[] lengthRatio; 1061 | 1062 | public LTBezierPath() 1063 | { 1064 | } 1065 | public LTBezierPath(Vector3[] pts_) 1066 | { 1067 | setPoints(pts_); 1068 | } 1069 | 1070 | public void setPoints(Vector3[] pts_) 1071 | { 1072 | if (pts_.Length < 4) 1073 | LeanTween.logError("LeanTween - When passing values for a vector path, you must pass four or more values!"); 1074 | if (pts_.Length % 4 != 0) 1075 | LeanTween.logError("LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..."); 1076 | 1077 | pts = pts_; 1078 | 1079 | int k = 0; 1080 | beziers = new LTBezier[pts.Length / 4]; 1081 | lengthRatio = new float[beziers.Length]; 1082 | int i; 1083 | length = 0; 1084 | for (i = 0; i < pts.Length; i += 4) 1085 | { 1086 | beziers[k] = new LTBezier(pts[i + 0], pts[i + 2], pts[i + 1], pts[i + 3], 0.05f); 1087 | length += beziers[k].length; 1088 | k++; 1089 | } 1090 | // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers); 1091 | for (i = 0; i < beziers.Length; i++) 1092 | { 1093 | lengthRatio[i] = beziers[i].length / length; 1094 | } 1095 | } 1096 | 1097 | /** 1098 | * Retrieve a point along a path 1099 | * 1100 | * @method point 1101 | * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) 1102 | * @return {Vector3} Vector3 position of the point along the path 1103 | * @example 1104 | * transform.position = ltPath.point( 0.6f ); 1105 | */ 1106 | public Vector3 point(float ratio) 1107 | { 1108 | float added = 0.0f; 1109 | for (int i = 0; i < lengthRatio.Length; i++) 1110 | { 1111 | added += lengthRatio[i]; 1112 | if (added >= ratio) 1113 | return beziers[i].point((ratio - (added - lengthRatio[i])) / lengthRatio[i]); 1114 | } 1115 | return beziers[lengthRatio.Length - 1].point(1.0f); 1116 | } 1117 | 1118 | /** 1119 | * Place an object along a certain point on the path (facing the direction perpendicular to the path) 1120 | * 1121 | * @method place 1122 | * @param {Transform} transform:Transform the transform of the object you wish to place along the path 1123 | * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) 1124 | * @example 1125 | * ltPath.place( transform, 0.6f ); 1126 | */ 1127 | public void place(Transform transform, float ratio) 1128 | { 1129 | place(transform, ratio, Vector3.up); 1130 | } 1131 | 1132 | /** 1133 | * Place an object along a certain point on the path, with it facing a certain direction perpendicular to the path 1134 | * 1135 | * @method place 1136 | * @param {Transform} transform:Transform the transform of the object you wish to place along the path 1137 | * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) 1138 | * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up 1139 | * @example 1140 | * ltPath.place( transform, 0.6f, Vector3.left ); 1141 | */ 1142 | public void place(Transform transform, float ratio, Vector3 worldUp) 1143 | { 1144 | transform.position = point(ratio); 1145 | ratio += 0.001f; 1146 | if (ratio <= 1.0f) 1147 | transform.LookAt(point(ratio), worldUp); 1148 | } 1149 | 1150 | /** 1151 | * Place an object along a certain point on the path (facing the direction perpendicular to the path) - Local Space, not world-space 1152 | * 1153 | * @method placeLocal 1154 | * @param {Transform} transform:Transform the transform of the object you wish to place along the path 1155 | * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) 1156 | * @example 1157 | * ltPath.placeLocal( transform, 0.6f ); 1158 | */ 1159 | public void placeLocal(Transform transform, float ratio) 1160 | { 1161 | placeLocal(transform, ratio, Vector3.up); 1162 | } 1163 | 1164 | /** 1165 | * 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 1166 | * 1167 | * @method placeLocal 1168 | * @param {Transform} transform:Transform the transform of the object you wish to place along the path 1169 | * @param {float} ratio:float ratio of the point along the path you wish to receive (0-1) 1170 | * @param {Vector3} rotation:Vector3 the direction in which to place the transform ex: Vector3.up 1171 | * @example 1172 | * ltPath.placeLocal( transform, 0.6f, Vector3.left ); 1173 | */ 1174 | public void placeLocal(Transform transform, float ratio, Vector3 worldUp) 1175 | { 1176 | transform.localPosition = point(ratio); 1177 | ratio += 0.001f; 1178 | if (ratio <= 1.0f) 1179 | transform.LookAt(transform.parent.TransformPoint(point(ratio)), worldUp); 1180 | } 1181 | } 1182 | 1183 | [System.Serializable] 1184 | public class LTSpline 1185 | { 1186 | public Vector3[] pts; 1187 | private float[] lengthRatio; 1188 | private float[] lengths; 1189 | private int numSections; 1190 | private int currPt; 1191 | private float totalLength; 1192 | 1193 | public LTSpline(params Vector3[] pts) 1194 | { 1195 | this.pts = new Vector3[pts.Length]; 1196 | System.Array.Copy(pts, this.pts, pts.Length); 1197 | 1198 | numSections = pts.Length - 3; 1199 | int precision = 20; 1200 | lengthRatio = new float[numSections]; 1201 | lengths = new float[precision]; 1202 | 1203 | Vector3 lastPoint = new Vector3(Mathf.Infinity, 0, 0); 1204 | 1205 | totalLength = 0f; 1206 | for (int i = 0; i < precision; i++) 1207 | { 1208 | //Debug.Log("i:"+i); 1209 | float fract = (i * 1f) / precision; 1210 | Vector3 point = interp(fract); 1211 | 1212 | if (i >= 1) 1213 | { 1214 | lengths[i] = (point - lastPoint).magnitude; 1215 | // Debug.Log("fract:"+fract+" mag:"+lengths[ i ] + " i:"+i); 1216 | } 1217 | totalLength += lengths[i]; 1218 | 1219 | lastPoint = point; 1220 | } 1221 | 1222 | for (int i = 0; i < lengths.Length; i++) 1223 | { 1224 | float t = i * 1f / lengths.Length; 1225 | currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections), numSections - 1); 1226 | 1227 | lengthRatio[currPt] += lengths[i] / totalLength; 1228 | Debug.Log("lengthRatio[" + currPt + "]:" + lengthRatio[currPt] + " lengths[" + i + "]:" + lengths[i]); 1229 | } 1230 | } 1231 | 1232 | public float map(float t) 1233 | { 1234 | float added = 0.0f; 1235 | //Debug.Log("map t:"+t); 1236 | for (int i = 0; i < lengthRatio.Length; i++) 1237 | { 1238 | //Debug.Log("lengthRatio["+i+"]:"+lengthRatio[i]); 1239 | 1240 | if (added + lengthRatio[i] >= t) 1241 | { 1242 | return added + (t - added) / lengthRatio[i] * lengthRatio[i]; 1243 | } 1244 | added += lengthRatio[i]; 1245 | } 1246 | return 1f; 1247 | } 1248 | 1249 | public Vector3 interp(float t) 1250 | { 1251 | currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections), numSections - 1); 1252 | float u = t * (float)numSections - (float)currPt; 1253 | 1254 | // Debug.Log("currPt:"+currPt+" numSections:"+numSections+" pts.Length :"+pts.Length ); 1255 | Vector3 a = pts[currPt]; 1256 | Vector3 b = pts[currPt + 1]; 1257 | Vector3 c = pts[currPt + 2]; 1258 | Vector3 d = pts[currPt + 3]; 1259 | 1260 | return .5f * ( 1261 | (-a + 3f * b - 3f * c + d) * (u * u * u) 1262 | + (2f * a - 5f * b + 4f * c - d) * (u * u) 1263 | + (-a + c) * u 1264 | + 2f * b 1265 | ); 1266 | } 1267 | 1268 | public Vector3 point(float ratio) 1269 | { 1270 | //float t = map( ratio ); 1271 | //Debug.Log("t:"+t+" ratio:"+ratio); 1272 | return interp(ratio); 1273 | } 1274 | 1275 | public void gizmoDraw(float t = -1.0f) 1276 | { 1277 | if (lengthRatio != null && lengthRatio.Length > 0) 1278 | { 1279 | Gizmos.color = Color.white; 1280 | Vector3 prevPt = point(0); 1281 | 1282 | for (int i = 1; i <= 120; i++) 1283 | { 1284 | float pm = (float)i / 120f; 1285 | Vector3 currPt = point(pm); 1286 | Gizmos.DrawLine(currPt, prevPt); 1287 | prevPt = currPt; 1288 | } 1289 | 1290 | if (t >= 0f) 1291 | { 1292 | Gizmos.color = Color.blue; 1293 | Vector3 pos = point(t); 1294 | Gizmos.DrawLine(pos, pos + Velocity(t)); 1295 | } 1296 | } 1297 | } 1298 | 1299 | public Vector3 Velocity(float t) 1300 | { 1301 | t = map(t); 1302 | 1303 | int numSections = pts.Length - 3; 1304 | int currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections), numSections - 1); 1305 | float u = t * (float)numSections - (float)currPt; 1306 | 1307 | Vector3 a = pts[currPt]; 1308 | Vector3 b = pts[currPt + 1]; 1309 | Vector3 c = pts[currPt + 2]; 1310 | Vector3 d = pts[currPt + 3]; 1311 | 1312 | return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u) 1313 | + (2f * a - 5f * b + 4f * c - d) * u 1314 | + .5f * c - .5f * a; 1315 | } 1316 | } 1317 | 1318 | public enum TweenAction 1319 | { 1320 | MOVE_X, 1321 | MOVE_Y, 1322 | MOVE_Z, 1323 | MOVE_LOCAL_X, 1324 | MOVE_LOCAL_Y, 1325 | MOVE_LOCAL_Z, 1326 | MOVE_CURVED, 1327 | MOVE_CURVED_LOCAL, 1328 | SCALE_X, 1329 | SCALE_Y, 1330 | SCALE_Z, 1331 | ROTATE_X, 1332 | ROTATE_Y, 1333 | ROTATE_Z, 1334 | ROTATE_AROUND, 1335 | ALPHA, 1336 | ALPHA_VERTEX, 1337 | CALLBACK, 1338 | MOVE, 1339 | MOVE_LOCAL, 1340 | ROTATE, 1341 | ROTATE_LOCAL, 1342 | SCALE, 1343 | VALUE3, 1344 | GUI_MOVE, 1345 | GUI_MOVE_MARGIN, 1346 | GUI_SCALE, 1347 | GUI_ALPHA, 1348 | GUI_ROTATE 1349 | } 1350 | 1351 | /** 1352 | * LeanTween is an efficient tweening engine for Unity3d

1353 | * Index of All Methods | Optional Paramaters that can be passed

1354 | * Optional Parameters are passed at the end of every method
1355 | *
1356 | * Example:
1357 | * LeanTween.moveX( gameObject, 1f, 1f).setEase( LeanTweenType.easeInQuad ).setDelay(1f);
1358 | *
1359 | * You can pass the optional parameters in any order, and chain on as many as you wish.
1360 | * You can also pass parameters at a later time by saving a reference to what is returned.
1361 | *
1362 | * Example:
1363 | * LTDescr d = LeanTween.moveX(gameObject, 1f, 1f);
1364 | *   ...later set some parameters
1365 | * d.setOnComplete( onCompleteFunc ).setEase( LeanTweenType.easeInOutBack );
1366 | * 1367 | * @class LeanTween 1368 | */ 1369 | 1370 | public class LeanTween : MonoBehaviour 1371 | { 1372 | public static bool throwErrors = true; 1373 | 1374 | private static LTDescr[] tweens; 1375 | private static int tweenMaxSearch = 0; 1376 | private static int maxTweens = 400; 1377 | private static int frameRendered = -1; 1378 | private static GameObject _tweenEmpty; 1379 | private static float dtEstimated; 1380 | private static float previousRealTime; 1381 | private static float dt; 1382 | private static float dtActual; 1383 | private static LTDescr tween; 1384 | private static int i; 1385 | private static int j; 1386 | private static AnimationCurve punch = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.112586f, 0.9976035f), new Keyframe(0.3120486f, -0.1720615f), new Keyframe(0.4316337f, 0.07030682f), new Keyframe(0.5524869f, -0.03141804f), new Keyframe(0.6549395f, 0.003909959f), new Keyframe(0.770987f, -0.009817753f), new Keyframe(0.8838775f, 0.001939224f), new Keyframe(1.0f, 0.0f)); 1387 | private static AnimationCurve shake = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(0.75f, -1f), new Keyframe(1f, 0f)); 1388 | 1389 | public static void init() 1390 | { 1391 | init(maxTweens); 1392 | } 1393 | 1394 | /** 1395 | * This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400). This must be called before any use of LeanTween is made for it to be effective. 1396 | * 1397 | * @method LeanTween.init 1398 | * @param {integer} maxSimultaneousTweens:int The maximum number of tweens you will use, make sure you don't go over this limit, otherwise the code will throw an error 1399 | * @example 1400 | * LeanTween.init( 800 ); 1401 | */ 1402 | public static void init(int maxSimultaneousTweens) 1403 | { 1404 | if (tweens == null) 1405 | { 1406 | maxTweens = maxSimultaneousTweens; 1407 | tweens = new LTDescr[maxTweens]; 1408 | _tweenEmpty = new GameObject(); 1409 | _tweenEmpty.name = "~LeanTween"; 1410 | _tweenEmpty.AddComponent(typeof(LeanTween)); 1411 | _tweenEmpty.isStatic = true; 1412 | #if !UNITY_EDITOR 1413 | _tweenEmpty.hideFlags = HideFlags.HideAndDontSave; 1414 | #endif 1415 | DontDestroyOnLoad(_tweenEmpty); 1416 | for (int i = 0; i < maxTweens; i++) 1417 | { 1418 | tweens[i] = new LTDescr(); 1419 | } 1420 | } 1421 | } 1422 | 1423 | public static void reset() 1424 | { 1425 | tweens = null; 1426 | } 1427 | 1428 | public void Update() 1429 | { 1430 | LeanTween.update(); 1431 | } 1432 | 1433 | public void OnLevelWasLoaded(int lvl) 1434 | { 1435 | // Debug.Log("reseting gui"); 1436 | LTGUI.reset(); 1437 | } 1438 | 1439 | private static Transform trans; 1440 | private static float timeTotal; 1441 | private static TweenAction tweenAction; 1442 | private static float ratioPassed; 1443 | private static float from; 1444 | private static float to; 1445 | private static float val; 1446 | private static Vector3 newVect; 1447 | private static bool isTweenFinished; 1448 | private static GameObject target; 1449 | private static GameObject customTarget; 1450 | 1451 | public static void update() 1452 | { 1453 | if (frameRendered != Time.frameCount) 1454 | { // make sure update is only called once per frame 1455 | init(); 1456 | 1457 | dtEstimated = Time.realtimeSinceStartup - previousRealTime; 1458 | if (dtEstimated > 0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large 1459 | dtEstimated = 0.2f; 1460 | previousRealTime = Time.realtimeSinceStartup; 1461 | dtActual = Time.deltaTime * Time.timeScale; 1462 | // if(tweenMaxSearch>1500) 1463 | // Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens); 1464 | for (int i = 0; i < tweenMaxSearch && i < maxTweens; i++) 1465 | { 1466 | //Debug.Log("tweens["+i+"].toggle:"+tweens[i].toggle); 1467 | if (tweens[i].toggle) 1468 | { 1469 | tween = tweens[i]; 1470 | trans = tween.trans; 1471 | timeTotal = tween.time; 1472 | tweenAction = tween.type; 1473 | 1474 | dt = dtActual; 1475 | if (tween.useEstimatedTime) 1476 | { 1477 | dt = dtEstimated; 1478 | timeTotal = tween.time; 1479 | } 1480 | else if (tween.useFrames) 1481 | { 1482 | dt = 1; 1483 | } 1484 | else if (tween.direction == 0f) 1485 | { 1486 | dt = 0f; 1487 | } 1488 | 1489 | if (trans == null) 1490 | { 1491 | removeTween(i); 1492 | continue; 1493 | } 1494 | //Debug.Log("i:"+i+" tween:"+tween+" dt:"+dt); 1495 | 1496 | // Check for tween finished 1497 | isTweenFinished = false; 1498 | if (tween.delay <= 0) 1499 | { 1500 | if ((tween.passed + dt > timeTotal && tween.direction > 0.0f)) 1501 | { 1502 | isTweenFinished = true; 1503 | tween.passed = tween.time; // Set to the exact end time so that it can finish tween exactly on the end value 1504 | } 1505 | else if (tween.direction < 0.0f && tween.passed - dt < 0.0f) 1506 | { 1507 | isTweenFinished = true; 1508 | tween.passed = Mathf.Epsilon; 1509 | } 1510 | } 1511 | 1512 | if (!tween.hasInitiliazed && ((tween.passed == 0.0 && tween.delay == 0.0) || tween.passed > 0.0)) 1513 | { 1514 | tween.hasInitiliazed = true; 1515 | // Initialize From Values 1516 | switch (tweenAction) 1517 | { 1518 | case TweenAction.MOVE: 1519 | tween.from = trans.position; break; 1520 | case TweenAction.MOVE_X: 1521 | tween.from.x = trans.position.x; break; 1522 | case TweenAction.MOVE_Y: 1523 | tween.from.x = trans.position.y; break; 1524 | case TweenAction.MOVE_Z: 1525 | tween.from.x = trans.position.z; break; 1526 | case TweenAction.MOVE_LOCAL_X: 1527 | tweens[i].from.x = trans.localPosition.x; break; 1528 | case TweenAction.MOVE_LOCAL_Y: 1529 | tweens[i].from.x = trans.localPosition.y; break; 1530 | case TweenAction.MOVE_LOCAL_Z: 1531 | tweens[i].from.x = trans.localPosition.z; break; 1532 | case TweenAction.SCALE_X: 1533 | tween.from.x = trans.localScale.x; break; 1534 | case TweenAction.SCALE_Y: 1535 | tween.from.x = trans.localScale.y; break; 1536 | case TweenAction.SCALE_Z: 1537 | tween.from.x = trans.localScale.z; break; 1538 | case TweenAction.ALPHA: 1539 | #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 1540 | tween.from.x = trans.gameObject.renderer.material.color.a; 1541 | break; 1542 | #else 1543 | SpriteRenderer ren = trans.gameObject.GetComponent(); 1544 | tween.from.x = (ren != null) ? ren.color.a : trans.gameObject.renderer.material.color.a; 1545 | break; 1546 | #endif 1547 | case TweenAction.MOVE_LOCAL: 1548 | tween.from = trans.localPosition; break; 1549 | case TweenAction.MOVE_CURVED: 1550 | // tween.path.pts[0] = trans.position; 1551 | tween.from.x = 0; break; 1552 | case TweenAction.MOVE_CURVED_LOCAL: 1553 | // tween.path.pts[0] = trans.localPosition; 1554 | tween.from.x = 0; break; 1555 | case TweenAction.ROTATE: 1556 | tween.from = trans.eulerAngles; 1557 | tween.to = new Vector3(LeanTween.closestRot(tween.from.x, tween.to.x), LeanTween.closestRot(tween.from.y, tween.to.y), LeanTween.closestRot(tween.from.z, tween.to.z)); 1558 | break; 1559 | case TweenAction.ROTATE_X: 1560 | tween.from.x = trans.eulerAngles.x; 1561 | tween.to.x = LeanTween.closestRot(tween.from.x, tween.to.x); 1562 | break; 1563 | case TweenAction.ROTATE_Y: 1564 | tween.from.x = trans.eulerAngles.y; 1565 | tween.to.x = LeanTween.closestRot(tween.from.x, tween.to.x); 1566 | break; 1567 | case TweenAction.ROTATE_Z: 1568 | tween.from.x = trans.eulerAngles.z; 1569 | tween.to.x = LeanTween.closestRot(tween.from.x, tween.to.x); 1570 | break; 1571 | case TweenAction.ROTATE_AROUND: 1572 | tween.lastVal = 0.0f; // optional["last"] 1573 | tween.origRotation = trans.rotation; // optional["origRotation" 1574 | break; 1575 | case TweenAction.ROTATE_LOCAL: 1576 | tween.from = trans.localEulerAngles; 1577 | tween.to = new Vector3(LeanTween.closestRot(tween.from.x, tween.to.x), LeanTween.closestRot(tween.from.y, tween.to.y), LeanTween.closestRot(tween.from.z, tween.to.z)); 1578 | break; 1579 | case TweenAction.SCALE: 1580 | tween.from = trans.localScale; break; 1581 | case TweenAction.GUI_MOVE: 1582 | tween.from = new Vector3(tween.ltRect.rect.x, tween.ltRect.rect.y, 0); break; 1583 | case TweenAction.GUI_MOVE_MARGIN: 1584 | tween.from = new Vector2(tween.ltRect.margin.x, tween.ltRect.margin.y); break; 1585 | case TweenAction.GUI_SCALE: 1586 | tween.from = new Vector3(tween.ltRect.rect.width, tween.ltRect.rect.height, 0); break; 1587 | case TweenAction.GUI_ALPHA: 1588 | tween.from.x = tween.ltRect.alpha; break; 1589 | case TweenAction.GUI_ROTATE: 1590 | if (tween.ltRect.rotateEnabled == false) 1591 | { 1592 | tween.ltRect.rotateEnabled = true; 1593 | tween.ltRect.resetForRotation(); 1594 | } 1595 | 1596 | tween.from.x = tween.ltRect.rotation; break; 1597 | case TweenAction.ALPHA_VERTEX: 1598 | tween.from.x = trans.GetComponent().mesh.colors32[0].a; 1599 | break; 1600 | } 1601 | tween.diff = tween.to - tween.from; 1602 | } 1603 | if (tween.delay <= 0) 1604 | { 1605 | // Move Values 1606 | if (timeTotal <= 0f) 1607 | { 1608 | //Debug.LogError("time total is zero Time.timeScale:"+Time.timeScale+" useEstimatedTime:"+tween.useEstimatedTime); 1609 | ratioPassed = 0f; 1610 | } 1611 | else 1612 | { 1613 | ratioPassed = tween.passed / timeTotal; 1614 | } 1615 | 1616 | if (ratioPassed > 1.0) 1617 | ratioPassed = 1.0f; 1618 | 1619 | if (tweenAction >= TweenAction.MOVE_X && tweenAction <= TweenAction.CALLBACK) 1620 | { 1621 | if (tween.animationCurve != null) 1622 | { 1623 | val = tweenOnCurve(tween, ratioPassed); 1624 | } 1625 | else 1626 | { 1627 | switch (tween.tweenType) 1628 | { 1629 | case LeanTweenType.linear: 1630 | val = tween.from.x + tween.diff.x * ratioPassed; break; 1631 | case LeanTweenType.easeOutQuad: 1632 | val = easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break; 1633 | case LeanTweenType.easeInQuad: 1634 | val = easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break; 1635 | case LeanTweenType.easeInOutQuad: 1636 | val = easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break; 1637 | case LeanTweenType.easeInCubic: 1638 | val = easeInCubic(tween.from.x, tween.to.x, ratioPassed); break; 1639 | case LeanTweenType.easeOutCubic: 1640 | val = easeOutCubic(tween.from.x, tween.to.x, ratioPassed); break; 1641 | case LeanTweenType.easeInOutCubic: 1642 | val = easeInOutCubic(tween.from.x, tween.to.x, ratioPassed); break; 1643 | case LeanTweenType.easeInQuart: 1644 | val = easeInQuart(tween.from.x, tween.to.x, ratioPassed); break; 1645 | case LeanTweenType.easeOutQuart: 1646 | val = easeOutQuart(tween.from.x, tween.to.x, ratioPassed); break; 1647 | case LeanTweenType.easeInOutQuart: 1648 | val = easeInOutQuart(tween.from.x, tween.to.x, ratioPassed); break; 1649 | case LeanTweenType.easeInQuint: 1650 | val = easeInQuint(tween.from.x, tween.to.x, ratioPassed); break; 1651 | case LeanTweenType.easeOutQuint: 1652 | val = easeOutQuint(tween.from.x, tween.to.x, ratioPassed); break; 1653 | case LeanTweenType.easeInOutQuint: 1654 | val = easeInOutQuint(tween.from.x, tween.to.x, ratioPassed); break; 1655 | case LeanTweenType.easeInSine: 1656 | val = easeInSine(tween.from.x, tween.to.x, ratioPassed); break; 1657 | case LeanTweenType.easeOutSine: 1658 | val = easeOutSine(tween.from.x, tween.to.x, ratioPassed); break; 1659 | case LeanTweenType.easeInOutSine: 1660 | val = easeInOutSine(tween.from.x, tween.to.x, ratioPassed); break; 1661 | case LeanTweenType.easeInExpo: 1662 | val = easeInExpo(tween.from.x, tween.to.x, ratioPassed); break; 1663 | case LeanTweenType.easeOutExpo: 1664 | val = easeOutExpo(tween.from.x, tween.to.x, ratioPassed); break; 1665 | case LeanTweenType.easeInOutExpo: 1666 | val = easeInOutExpo(tween.from.x, tween.to.x, ratioPassed); break; 1667 | case LeanTweenType.easeInCirc: 1668 | val = easeInCirc(tween.from.x, tween.to.x, ratioPassed); break; 1669 | case LeanTweenType.easeOutCirc: 1670 | val = easeOutCirc(tween.from.x, tween.to.x, ratioPassed); break; 1671 | case LeanTweenType.easeInOutCirc: 1672 | val = easeInOutCirc(tween.from.x, tween.to.x, ratioPassed); break; 1673 | case LeanTweenType.easeInBounce: 1674 | val = easeInBounce(tween.from.x, tween.to.x, ratioPassed); break; 1675 | case LeanTweenType.easeOutBounce: 1676 | val = easeOutBounce(tween.from.x, tween.to.x, ratioPassed); break; 1677 | case LeanTweenType.easeInOutBounce: 1678 | val = easeInOutBounce(tween.from.x, tween.to.x, ratioPassed); break; 1679 | case LeanTweenType.easeInBack: 1680 | val = easeInBack(tween.from.x, tween.to.x, ratioPassed); break; 1681 | case LeanTweenType.easeOutBack: 1682 | val = easeOutBack(tween.from.x, tween.to.x, ratioPassed); break; 1683 | case LeanTweenType.easeInOutBack: 1684 | val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break; 1685 | case LeanTweenType.easeInElastic: 1686 | val = easeInElastic(tween.from.x, tween.to.x, ratioPassed); break; 1687 | case LeanTweenType.easeOutElastic: 1688 | val = easeOutElastic(tween.from.x, tween.to.x, ratioPassed); break; 1689 | case LeanTweenType.easeInOutElastic: 1690 | val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break; 1691 | case LeanTweenType.punch: 1692 | case LeanTweenType.easeShake: 1693 | if (tween.tweenType == LeanTweenType.punch) 1694 | { 1695 | tween.animationCurve = LeanTween.punch; 1696 | } 1697 | else if (tween.tweenType == LeanTweenType.easeShake) 1698 | { 1699 | tween.animationCurve = LeanTween.shake; 1700 | } 1701 | tween.to.x = tween.from.x + tween.to.x; 1702 | tween.diff.x = tween.to.x - tween.from.x; 1703 | val = tweenOnCurve(tween, ratioPassed); break; 1704 | case LeanTweenType.easeSpring: 1705 | val = spring(tween.from.x, tween.to.x, ratioPassed); break; 1706 | default: 1707 | { 1708 | val = tween.from.x + tween.diff.x * ratioPassed; break; 1709 | } 1710 | } 1711 | } 1712 | 1713 | //Debug.Log("from:"+from+" to:"+to+" val:"+val+" ratioPassed:"+ratioPassed); 1714 | if (tweenAction == TweenAction.MOVE_X) 1715 | { 1716 | trans.position = new Vector3(val, trans.position.y, trans.position.z); 1717 | } 1718 | else if (tweenAction == TweenAction.MOVE_Y) 1719 | { 1720 | trans.position = new Vector3(trans.position.x, val, trans.position.z); 1721 | } 1722 | else if (tweenAction == TweenAction.MOVE_Z) 1723 | { 1724 | trans.position = new Vector3(trans.position.x, trans.position.y, val); 1725 | } if (tweenAction == TweenAction.MOVE_LOCAL_X) 1726 | { 1727 | trans.localPosition = new Vector3(val, trans.localPosition.y, trans.localPosition.z); 1728 | } 1729 | else if (tweenAction == TweenAction.MOVE_LOCAL_Y) 1730 | { 1731 | trans.localPosition = new Vector3(trans.localPosition.x, val, trans.localPosition.z); 1732 | } 1733 | else if (tweenAction == TweenAction.MOVE_LOCAL_Z) 1734 | { 1735 | trans.localPosition = new Vector3(trans.localPosition.x, trans.localPosition.y, val); 1736 | } 1737 | else if (tweenAction == TweenAction.MOVE_CURVED) 1738 | { 1739 | if (tween.path.orientToPath) 1740 | { 1741 | tween.path.place(trans, val); 1742 | } 1743 | else 1744 | { 1745 | trans.position = tween.path.point(val); 1746 | } 1747 | // Debug.Log("val:"+val+" trans.position:"+trans.position + " 0:"+ tween.curves[0] +" 1:"+tween.curves[1] +" 2:"+tween.curves[2] +" 3:"+tween.curves[3]); 1748 | } 1749 | else if ((TweenAction)tweenAction == TweenAction.MOVE_CURVED_LOCAL) 1750 | { 1751 | if (tween.path.orientToPath) 1752 | { 1753 | tween.path.placeLocal(trans, val); 1754 | } 1755 | else 1756 | { 1757 | trans.localPosition = tween.path.point(val); 1758 | } 1759 | // Debug.Log("val:"+val+" trans.position:"+trans.position); 1760 | } 1761 | else if (tweenAction == TweenAction.SCALE_X) 1762 | { 1763 | trans.localScale = new Vector3(val, trans.localScale.y, trans.localScale.z); 1764 | } 1765 | else if (tweenAction == TweenAction.SCALE_Y) 1766 | { 1767 | trans.localScale = new Vector3(trans.localScale.x, val, trans.localScale.z); 1768 | } 1769 | else if (tweenAction == TweenAction.SCALE_Z) 1770 | { 1771 | trans.localScale = new Vector3(trans.localScale.x, trans.localScale.y, val); 1772 | } 1773 | else if (tweenAction == TweenAction.ROTATE_X) 1774 | { 1775 | trans.eulerAngles = new Vector3(val, trans.eulerAngles.y, trans.eulerAngles.z); 1776 | } 1777 | else if (tweenAction == TweenAction.ROTATE_Y) 1778 | { 1779 | trans.eulerAngles = new Vector3(trans.eulerAngles.x, val, trans.eulerAngles.z); 1780 | } 1781 | else if (tweenAction == TweenAction.ROTATE_Z) 1782 | { 1783 | trans.eulerAngles = new Vector3(trans.eulerAngles.x, trans.eulerAngles.y, val); 1784 | } 1785 | else if (tweenAction == TweenAction.ROTATE_AROUND) 1786 | { 1787 | float move = val - tween.lastVal; 1788 | // Debug.Log("move:"+move+" val:"+val + " timeTotal:"+timeTotal + " from:"+tween.from+ " diff:"+tween.diff); 1789 | /*if(isTweenFinished){ 1790 | trans.eulerAngles = tween.origRotation; 1791 | trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, tween.to.x); 1792 | }else{*/ 1793 | /*trans.rotation = tween.origRotation; 1794 | trans.RotateAround((Vector3)trans.TransformPoint( tween.point ), tween.axis, val); 1795 | tween.lastVal = val;*/ 1796 | 1797 | trans.RotateAround((Vector3)trans.TransformPoint(tween.point), tween.axis, move); 1798 | tween.lastVal = val; 1799 | 1800 | //trans.rotation = * Quaternion.AngleAxis(val, tween.axis); 1801 | //} 1802 | } 1803 | else if (tweenAction == TweenAction.ALPHA) 1804 | { 1805 | #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 1806 | 1807 | foreach(Material mat in trans.gameObject.renderer.materials){ 1808 | mat.color = new Color( mat.color.r, mat.color.g, mat.color.b, val); 1809 | } 1810 | 1811 | #else 1812 | 1813 | SpriteRenderer ren = trans.gameObject.GetComponent(); 1814 | if (ren != null) 1815 | { 1816 | ren.color = new Color(ren.color.r, ren.color.g, ren.color.b, val); 1817 | } 1818 | else 1819 | { 1820 | foreach (Material mat in trans.gameObject.renderer.materials) 1821 | { 1822 | mat.color = new Color(mat.color.r, mat.color.g, mat.color.b, val); 1823 | } 1824 | } 1825 | 1826 | #endif 1827 | } 1828 | else if (tweenAction == TweenAction.ALPHA_VERTEX) 1829 | { 1830 | Mesh mesh = trans.GetComponent().mesh; 1831 | Vector3[] vertices = mesh.vertices; 1832 | Color32[] colors = new Color32[vertices.Length]; 1833 | Color32 c = mesh.colors32[0]; 1834 | c = new Color(c.r, c.g, c.b, val); 1835 | for (int k = 0; k < vertices.Length; k++) 1836 | { 1837 | colors[k] = c; 1838 | } 1839 | mesh.colors32 = colors; 1840 | } 1841 | } 1842 | else if (tweenAction >= TweenAction.MOVE) 1843 | { 1844 | // 1845 | 1846 | if (tween.animationCurve != null) 1847 | { 1848 | newVect = tweenOnCurveVector(tween, ratioPassed); 1849 | } 1850 | else 1851 | { 1852 | if (tween.tweenType == LeanTweenType.linear) 1853 | { 1854 | newVect = new Vector3(tween.from.x + tween.diff.x * ratioPassed, tween.from.y + tween.diff.y * ratioPassed, tween.from.z + tween.diff.z * ratioPassed); 1855 | } 1856 | else if (tween.tweenType >= LeanTweenType.linear) 1857 | { 1858 | switch (tween.tweenType) 1859 | { 1860 | case LeanTweenType.easeOutQuad: 1861 | newVect = new Vector3(easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break; 1862 | case LeanTweenType.easeInQuad: 1863 | newVect = new Vector3(easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break; 1864 | case LeanTweenType.easeInOutQuad: 1865 | newVect = new Vector3(easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break; 1866 | case LeanTweenType.easeInCubic: 1867 | newVect = new Vector3(easeInCubic(tween.from.x, tween.to.x, ratioPassed), easeInCubic(tween.from.y, tween.to.y, ratioPassed), easeInCubic(tween.from.z, tween.to.z, ratioPassed)); break; 1868 | case LeanTweenType.easeOutCubic: 1869 | newVect = new Vector3(easeOutCubic(tween.from.x, tween.to.x, ratioPassed), easeOutCubic(tween.from.y, tween.to.y, ratioPassed), easeOutCubic(tween.from.z, tween.to.z, ratioPassed)); break; 1870 | case LeanTweenType.easeInOutCubic: 1871 | newVect = new Vector3(easeInOutCubic(tween.from.x, tween.to.x, ratioPassed), easeInOutCubic(tween.from.y, tween.to.y, ratioPassed), easeInOutCubic(tween.from.z, tween.to.z, ratioPassed)); break; 1872 | case LeanTweenType.easeInQuart: 1873 | newVect = new Vector3(easeInQuart(tween.from.x, tween.to.x, ratioPassed), easeInQuart(tween.from.y, tween.to.y, ratioPassed), easeInQuart(tween.from.z, tween.to.z, ratioPassed)); break; 1874 | case LeanTweenType.easeOutQuart: 1875 | newVect = new Vector3(easeOutQuart(tween.from.x, tween.to.x, ratioPassed), easeOutQuart(tween.from.y, tween.to.y, ratioPassed), easeOutQuart(tween.from.z, tween.to.z, ratioPassed)); break; 1876 | case LeanTweenType.easeInOutQuart: 1877 | newVect = new Vector3(easeInOutQuart(tween.from.x, tween.to.x, ratioPassed), easeInOutQuart(tween.from.y, tween.to.y, ratioPassed), easeInOutQuart(tween.from.z, tween.to.z, ratioPassed)); break; 1878 | case LeanTweenType.easeInQuint: 1879 | newVect = new Vector3(easeInQuint(tween.from.x, tween.to.x, ratioPassed), easeInQuint(tween.from.y, tween.to.y, ratioPassed), easeInQuint(tween.from.z, tween.to.z, ratioPassed)); break; 1880 | case LeanTweenType.easeOutQuint: 1881 | newVect = new Vector3(easeOutQuint(tween.from.x, tween.to.x, ratioPassed), easeOutQuint(tween.from.y, tween.to.y, ratioPassed), easeOutQuint(tween.from.z, tween.to.z, ratioPassed)); break; 1882 | case LeanTweenType.easeInOutQuint: 1883 | newVect = new Vector3(easeInOutQuint(tween.from.x, tween.to.x, ratioPassed), easeInOutQuint(tween.from.y, tween.to.y, ratioPassed), easeInOutQuint(tween.from.z, tween.to.z, ratioPassed)); break; 1884 | case LeanTweenType.easeInSine: 1885 | newVect = new Vector3(easeInSine(tween.from.x, tween.to.x, ratioPassed), easeInSine(tween.from.y, tween.to.y, ratioPassed), easeInSine(tween.from.z, tween.to.z, ratioPassed)); break; 1886 | case LeanTweenType.easeOutSine: 1887 | newVect = new Vector3(easeOutSine(tween.from.x, tween.to.x, ratioPassed), easeOutSine(tween.from.y, tween.to.y, ratioPassed), easeOutSine(tween.from.z, tween.to.z, ratioPassed)); break; 1888 | case LeanTweenType.easeInOutSine: 1889 | newVect = new Vector3(easeInOutSine(tween.from.x, tween.to.x, ratioPassed), easeInOutSine(tween.from.y, tween.to.y, ratioPassed), easeInOutSine(tween.from.z, tween.to.z, ratioPassed)); break; 1890 | case LeanTweenType.easeInExpo: 1891 | newVect = new Vector3(easeInExpo(tween.from.x, tween.to.x, ratioPassed), easeInExpo(tween.from.y, tween.to.y, ratioPassed), easeInExpo(tween.from.z, tween.to.z, ratioPassed)); break; 1892 | case LeanTweenType.easeOutExpo: 1893 | newVect = new Vector3(easeOutExpo(tween.from.x, tween.to.x, ratioPassed), easeOutExpo(tween.from.y, tween.to.y, ratioPassed), easeOutExpo(tween.from.z, tween.to.z, ratioPassed)); break; 1894 | case LeanTweenType.easeInOutExpo: 1895 | newVect = new Vector3(easeInOutExpo(tween.from.x, tween.to.x, ratioPassed), easeInOutExpo(tween.from.y, tween.to.y, ratioPassed), easeInOutExpo(tween.from.z, tween.to.z, ratioPassed)); break; 1896 | case LeanTweenType.easeInCirc: 1897 | newVect = new Vector3(easeInCirc(tween.from.x, tween.to.x, ratioPassed), easeInCirc(tween.from.y, tween.to.y, ratioPassed), easeInCirc(tween.from.z, tween.to.z, ratioPassed)); break; 1898 | case LeanTweenType.easeOutCirc: 1899 | newVect = new Vector3(easeOutCirc(tween.from.x, tween.to.x, ratioPassed), easeOutCirc(tween.from.y, tween.to.y, ratioPassed), easeOutCirc(tween.from.z, tween.to.z, ratioPassed)); break; 1900 | case LeanTweenType.easeInOutCirc: 1901 | newVect = new Vector3(easeInOutCirc(tween.from.x, tween.to.x, ratioPassed), easeInOutCirc(tween.from.y, tween.to.y, ratioPassed), easeInOutCirc(tween.from.z, tween.to.z, ratioPassed)); break; 1902 | case LeanTweenType.easeInBounce: 1903 | newVect = new Vector3(easeInBounce(tween.from.x, tween.to.x, ratioPassed), easeInBounce(tween.from.y, tween.to.y, ratioPassed), easeInBounce(tween.from.z, tween.to.z, ratioPassed)); break; 1904 | case LeanTweenType.easeOutBounce: 1905 | newVect = new Vector3(easeOutBounce(tween.from.x, tween.to.x, ratioPassed), easeOutBounce(tween.from.y, tween.to.y, ratioPassed), easeOutBounce(tween.from.z, tween.to.z, ratioPassed)); break; 1906 | case LeanTweenType.easeInOutBounce: 1907 | newVect = new Vector3(easeInOutBounce(tween.from.x, tween.to.x, ratioPassed), easeInOutBounce(tween.from.y, tween.to.y, ratioPassed), easeInOutBounce(tween.from.z, tween.to.z, ratioPassed)); break; 1908 | case LeanTweenType.easeInBack: 1909 | newVect = new Vector3(easeInBack(tween.from.x, tween.to.x, ratioPassed), easeInBack(tween.from.y, tween.to.y, ratioPassed), easeInBack(tween.from.z, tween.to.z, ratioPassed)); break; 1910 | case LeanTweenType.easeOutBack: 1911 | newVect = new Vector3(easeOutBack(tween.from.x, tween.to.x, ratioPassed), easeOutBack(tween.from.y, tween.to.y, ratioPassed), easeOutBack(tween.from.z, tween.to.z, ratioPassed)); break; 1912 | case LeanTweenType.easeInOutBack: 1913 | newVect = new Vector3(easeInOutBack(tween.from.x, tween.to.x, ratioPassed), easeInOutBack(tween.from.y, tween.to.y, ratioPassed), easeInOutBack(tween.from.z, tween.to.z, ratioPassed)); break; 1914 | case LeanTweenType.easeInElastic: 1915 | newVect = new Vector3(easeInElastic(tween.from.x, tween.to.x, ratioPassed), easeInElastic(tween.from.y, tween.to.y, ratioPassed), easeInElastic(tween.from.z, tween.to.z, ratioPassed)); break; 1916 | case LeanTweenType.easeOutElastic: 1917 | newVect = new Vector3(easeOutElastic(tween.from.x, tween.to.x, ratioPassed), easeOutElastic(tween.from.y, tween.to.y, ratioPassed), easeOutElastic(tween.from.z, tween.to.z, ratioPassed)); break; 1918 | case LeanTweenType.easeInOutElastic: 1919 | newVect = new Vector3(easeInOutElastic(tween.from.x, tween.to.x, ratioPassed), easeInOutElastic(tween.from.y, tween.to.y, ratioPassed), easeInOutElastic(tween.from.z, tween.to.z, ratioPassed)); break; 1920 | case LeanTweenType.punch: 1921 | case LeanTweenType.easeShake: 1922 | if (tween.tweenType == LeanTweenType.punch) 1923 | { 1924 | tween.animationCurve = LeanTween.punch; 1925 | } 1926 | else if (tween.tweenType == LeanTweenType.easeShake) 1927 | { 1928 | tween.animationCurve = LeanTween.shake; 1929 | } 1930 | tween.to = tween.from + tween.to; 1931 | tween.diff = tween.to - tween.from; 1932 | if (tweenAction == TweenAction.ROTATE || tweenAction == TweenAction.ROTATE_LOCAL) 1933 | { 1934 | tween.to = new Vector3(closestRot(tween.from.x, tween.to.x), closestRot(tween.from.y, tween.to.y), closestRot(tween.from.z, tween.to.z)); 1935 | } 1936 | newVect = tweenOnCurveVector(tween, ratioPassed); break; 1937 | case LeanTweenType.easeSpring: 1938 | newVect = new Vector3(spring(tween.from.x, tween.to.x, ratioPassed), spring(tween.from.y, tween.to.y, ratioPassed), spring(tween.from.z, tween.to.z, ratioPassed)); break; 1939 | } 1940 | } 1941 | else 1942 | { 1943 | newVect = new Vector3(tween.from.x + tween.diff.x * ratioPassed, tween.from.y + tween.diff.y * ratioPassed, tween.from.z + tween.diff.z * ratioPassed); 1944 | } 1945 | } 1946 | 1947 | if (tweenAction == TweenAction.MOVE) 1948 | { 1949 | trans.position = newVect; 1950 | } 1951 | else if (tweenAction == TweenAction.MOVE_LOCAL) 1952 | { 1953 | trans.localPosition = newVect; 1954 | } 1955 | else if (tweenAction == TweenAction.ROTATE) 1956 | { 1957 | /*if(tween.hasPhysics){ 1958 | trans.gameObject.rigidbody.MoveRotation(Quaternion.Euler( newVect )); 1959 | }else{*/ 1960 | trans.eulerAngles = newVect; 1961 | // } 1962 | } 1963 | else if (tweenAction == TweenAction.ROTATE_LOCAL) 1964 | { 1965 | trans.localEulerAngles = newVect; 1966 | } 1967 | else if (tweenAction == TweenAction.SCALE) 1968 | { 1969 | trans.localScale = newVect; 1970 | } 1971 | else if (tweenAction == TweenAction.GUI_MOVE) 1972 | { 1973 | tween.ltRect.rect = new Rect(newVect.x, newVect.y, tween.ltRect.rect.width, tween.ltRect.rect.height); 1974 | } 1975 | else if (tweenAction == TweenAction.GUI_MOVE_MARGIN) 1976 | { 1977 | tween.ltRect.margin = new Vector2(newVect.x, newVect.y); 1978 | } 1979 | else if (tweenAction == TweenAction.GUI_SCALE) 1980 | { 1981 | tween.ltRect.rect = new Rect(tween.ltRect.rect.x, tween.ltRect.rect.y, newVect.x, newVect.y); 1982 | } 1983 | else if (tweenAction == TweenAction.GUI_ALPHA) 1984 | { 1985 | tween.ltRect.alpha = newVect.x; 1986 | } 1987 | else if (tweenAction == TweenAction.GUI_ROTATE) 1988 | { 1989 | tween.ltRect.rotation = newVect.x; 1990 | } 1991 | } 1992 | //Debug.Log("tween.delay:"+tween.delay + " tween.passed:"+tween.passed + " tweenAction:"+tweenAction + " to:"+newVect+" axis:"+tween.axis); 1993 | 1994 | if (tween.onUpdateFloat != null) 1995 | { 1996 | tween.onUpdateFloat(val); 1997 | } 1998 | else if (tween.onUpdateFloatObject != null) 1999 | { 2000 | tween.onUpdateFloatObject(val, tween.onUpdateParam); 2001 | } 2002 | else if (tween.onUpdateVector3Object != null) 2003 | { 2004 | tween.onUpdateVector3Object(newVect, tween.onUpdateParam); 2005 | } 2006 | else if (tween.onUpdateVector3 != null) 2007 | { 2008 | tween.onUpdateVector3(newVect); 2009 | } 2010 | #if !UNITY_METRO 2011 | else if (tween.optional != null) 2012 | { // LeanTween 1.x legacy stuff 2013 | var onUpdate = tween.optional["onUpdate"]; 2014 | if (onUpdate != null) 2015 | { 2016 | Hashtable updateParam = (Hashtable)tween.optional["onUpdateParam"]; 2017 | if ((TweenAction)tweenAction == TweenAction.VALUE3) 2018 | { 2019 | if (onUpdate.GetType() == typeof(string)) 2020 | { 2021 | string onUpdateS = onUpdate as string; 2022 | customTarget = tween.optional["onUpdateTarget"] != null ? tween.optional["onUpdateTarget"] as GameObject : trans.gameObject; 2023 | customTarget.BroadcastMessage(onUpdateS, newVect); 2024 | } 2025 | else if (onUpdate.GetType() == typeof(System.Action)) 2026 | { 2027 | System.Action onUpdateA = (System.Action)onUpdate; 2028 | onUpdateA(newVect, updateParam); 2029 | } 2030 | else 2031 | { 2032 | System.Action onUpdateA = (System.Action)onUpdate; 2033 | onUpdateA(newVect); 2034 | } 2035 | } 2036 | else 2037 | { 2038 | if (onUpdate.GetType() == typeof(string)) 2039 | { 2040 | string onUpdateS = onUpdate as string; 2041 | if (tween.optional["onUpdateTarget"] != null) 2042 | { 2043 | customTarget = tween.optional["onUpdateTarget"] as GameObject; 2044 | customTarget.BroadcastMessage(onUpdateS, val); 2045 | } 2046 | else 2047 | { 2048 | trans.gameObject.BroadcastMessage(onUpdateS, val); 2049 | } 2050 | } 2051 | else if (onUpdate.GetType() == typeof(System.Action)) 2052 | { 2053 | System.Action onUpdateA = (System.Action)onUpdate; 2054 | onUpdateA(val, updateParam); 2055 | } 2056 | else if (onUpdate.GetType() == typeof(System.Action)) 2057 | { 2058 | System.Action onUpdateA = (System.Action)onUpdate; 2059 | onUpdateA(newVect); 2060 | } 2061 | else 2062 | { 2063 | System.Action onUpdateA = (System.Action)onUpdate; 2064 | onUpdateA(val); 2065 | } 2066 | } 2067 | } 2068 | } 2069 | #endif 2070 | } 2071 | 2072 | if (isTweenFinished) 2073 | { 2074 | // Debug.Log("finished tween:"+i+" tween:"+tween); 2075 | if (tweenAction == TweenAction.GUI_ROTATE) 2076 | tween.ltRect.rotateFinished = true; 2077 | 2078 | if (tween.loopType == LeanTweenType.once || tween.loopCount == 1) 2079 | { 2080 | if (tween.onComplete != null) 2081 | { 2082 | removeTween(i); 2083 | tween.onComplete(); 2084 | } 2085 | else if (tween.onCompleteObject != null) 2086 | { 2087 | removeTween(i); 2088 | tween.onCompleteObject(tween.onCompleteParam); 2089 | } 2090 | #if !UNITY_METRO 2091 | else if (tween.optional != null) 2092 | { 2093 | System.Action callback = null; 2094 | System.Action callbackWithParam = null; 2095 | string callbackS = string.Empty; 2096 | object callbackParam = null; 2097 | if (tween.optional != null && tween.trans) 2098 | { 2099 | if (tween.optional["onComplete"] != null) 2100 | { 2101 | callbackParam = tween.optional["onCompleteParam"]; 2102 | if (tween.optional["onComplete"].GetType() == typeof(string)) 2103 | { 2104 | callbackS = tween.optional["onComplete"] as string; 2105 | } 2106 | else 2107 | { 2108 | if (callbackParam != null) 2109 | { 2110 | callbackWithParam = (System.Action)tween.optional["onComplete"]; 2111 | } 2112 | else 2113 | { 2114 | callback = (System.Action)tween.optional["onComplete"]; 2115 | if (callback == null) 2116 | Debug.LogWarning("callback was not converted"); 2117 | } 2118 | } 2119 | } 2120 | } 2121 | removeTween(i); 2122 | if (callbackWithParam != null) 2123 | { 2124 | callbackWithParam(callbackParam); 2125 | } 2126 | else if (callback != null) 2127 | { 2128 | callback(); 2129 | } 2130 | else if (callbackS != string.Empty) 2131 | { 2132 | if (tween.optional["onCompleteTarget"] != null) 2133 | { 2134 | customTarget = tween.optional["onCompleteTarget"] as GameObject; 2135 | if (callbackParam != null) customTarget.BroadcastMessage(callbackS, callbackParam); 2136 | else customTarget.BroadcastMessage(callbackS); 2137 | } 2138 | else 2139 | { 2140 | if (callbackParam != null) trans.gameObject.BroadcastMessage(callbackS, callbackParam); 2141 | else trans.gameObject.BroadcastMessage(callbackS); 2142 | } 2143 | } 2144 | } 2145 | #endif 2146 | else 2147 | { 2148 | removeTween(i); 2149 | } 2150 | } 2151 | else 2152 | { 2153 | if (tween.loopCount < 0 && tween.type == TweenAction.CALLBACK) 2154 | { 2155 | if (tween.onComplete != null) 2156 | { 2157 | tween.onComplete(); 2158 | } 2159 | else if (tween.onCompleteObject != null) 2160 | { 2161 | tween.onCompleteObject(tween.onCompleteParam); 2162 | } 2163 | } 2164 | if (tween.loopCount >= 1) 2165 | { 2166 | tween.loopCount--; 2167 | } 2168 | if (tween.loopType == LeanTweenType.clamp) 2169 | { 2170 | tween.passed = Mathf.Epsilon; 2171 | // tween.delay = 0.0; 2172 | } 2173 | else if (tween.loopType == LeanTweenType.pingPong) 2174 | { 2175 | tween.direction = 0.0f - (tween.direction); 2176 | } 2177 | } 2178 | } 2179 | else if (tween.delay <= 0) 2180 | { 2181 | tween.passed += dt * tween.direction; 2182 | } 2183 | else 2184 | { 2185 | tween.delay -= dt; 2186 | // Debug.Log("dt:"+dt+" tween:"+i+" tween:"+tween); 2187 | if (tween.delay < 0) 2188 | { 2189 | tween.passed = 0.0f;//-tween.delay 2190 | tween.delay = 0.0f; 2191 | } 2192 | } 2193 | } 2194 | } 2195 | 2196 | frameRendered = Time.frameCount; 2197 | } 2198 | } 2199 | 2200 | // This method is only used internally! Do not call this from your scripts. To cancel a tween use LeanTween.cancel 2201 | public static void removeTween(int i) 2202 | { 2203 | if (tweens[i].toggle) 2204 | { 2205 | tweens[i].toggle = false; 2206 | if (tweens[i].destroyOnComplete) 2207 | { 2208 | //Debug.Log("destroying tween.type:"+tween.type); 2209 | if (tweens[i].ltRect != null) 2210 | { 2211 | // Debug.Log("destroy i:"+i+" id:"+tweens[i].ltRect.id); 2212 | LTGUI.destroy(tweens[i].ltRect.id); 2213 | } 2214 | else 2215 | { // check if equal to tweenEmpty 2216 | } 2217 | } 2218 | //tweens[i].optional = null; 2219 | startSearch = i; 2220 | //Debug.Log("start search reset:"+startSearch + " i:"+i+" tweenMaxSearch:"+tweenMaxSearch); 2221 | if (i + 1 >= tweenMaxSearch) 2222 | { 2223 | //Debug.Log("reset to zero"); 2224 | startSearch = 0; 2225 | tweenMaxSearch--; 2226 | } 2227 | } 2228 | } 2229 | 2230 | public static Vector3[] add(Vector3[] a, Vector3 b) 2231 | { 2232 | Vector3[] c = new Vector3[a.Length]; 2233 | for (i = 0; i < a.Length; i++) 2234 | { 2235 | c[i] = a[i] + b; 2236 | } 2237 | 2238 | return c; 2239 | } 2240 | 2241 | public static float closestRot(float from, float to) 2242 | { 2243 | float minusWhole = 0 - (360 - to); 2244 | float plusWhole = 360 + to; 2245 | float toDiffAbs = Mathf.Abs(to - from); 2246 | float minusDiff = Mathf.Abs(minusWhole - from); 2247 | float plusDiff = Mathf.Abs(plusWhole - from); 2248 | if (toDiffAbs < minusDiff && toDiffAbs < plusDiff) 2249 | { 2250 | return to; 2251 | } 2252 | else 2253 | { 2254 | if (minusDiff < plusDiff) 2255 | { 2256 | return minusWhole; 2257 | } 2258 | else 2259 | { 2260 | return plusWhole; 2261 | } 2262 | } 2263 | } 2264 | 2265 | /** 2266 | * Cancel all tweens that are currently targeting the gameObject 2267 | * 2268 | * @method LeanTween.cancel 2269 | * @param {GameObject} gameObject:GameObject gameObject whose tweens you wish to cancel 2270 | * @example LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f);
2271 | * LeanTween.cancel( gameObject ); 2272 | */ 2273 | public static void cancel(GameObject gameObject) 2274 | { 2275 | init(); 2276 | Transform trans = gameObject.transform; 2277 | for (int i = 0; i < tweenMaxSearch; i++) 2278 | { 2279 | if (tweens[i].trans == trans) 2280 | removeTween(i); 2281 | } 2282 | } 2283 | 2284 | /** 2285 | * Cancel a specific tween with the provided id 2286 | * 2287 | * @method LeanTween.cancel 2288 | * @param {GameObject} gameObject:GameObject gameObject whose tweens you want to cancel 2289 | * @param {float} id:float unique id that represents that tween 2290 | */ 2291 | public static void cancel(GameObject gameObject, int uniqueId) 2292 | { 2293 | if (uniqueId >= 0) 2294 | { 2295 | init(); 2296 | int backId = uniqueId & 0xFFFF; 2297 | int backCounter = uniqueId >> 16; 2298 | // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); 2299 | if (tweens[backId].trans == null || (tweens[backId].trans.gameObject == gameObject && tweens[backId].counter == backCounter)) 2300 | removeTween((int)backId); 2301 | } 2302 | } 2303 | 2304 | /** 2305 | * Cancel a specific tween with the provided id 2306 | * 2307 | * @method LeanTween.cancel 2308 | * @param {LTRect} ltRect:LTRect LTRect object whose tweens you want to cancel 2309 | * @param {float} id:float unique id that represents that tween 2310 | */ 2311 | public static void cancel(LTRect ltRect, int uniqueId) 2312 | { 2313 | if (uniqueId >= 0) 2314 | { 2315 | init(); 2316 | int backId = uniqueId & 0xFFFF; 2317 | int backCounter = uniqueId >> 16; 2318 | // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); 2319 | if (tweens[backId].ltRect == ltRect && tweens[backId].counter == backCounter) 2320 | removeTween((int)backId); 2321 | } 2322 | } 2323 | 2324 | private static void cancel(int uniqueId) 2325 | { 2326 | if (uniqueId >= 0) 2327 | { 2328 | init(); 2329 | int backId = uniqueId & 0xFFFF; 2330 | int backCounter = uniqueId >> 16; 2331 | // Debug.Log("uniqueId:"+uniqueId+ " id:"+backId +" action:"+(TweenAction)backType + " tweens[id].type:"+tweens[backId].type); 2332 | if (tweens[backId].hasInitiliazed && tweens[backId].counter == backCounter) 2333 | removeTween((int)backId); 2334 | } 2335 | } 2336 | 2337 | // Deprecated 2338 | public static LTDescr description(int uniqueId) 2339 | { 2340 | int backId = uniqueId & 0xFFFF; 2341 | int backCounter = uniqueId >> 16; 2342 | 2343 | if (tweens[backId] != null && tweens[backId].uniqueId == uniqueId && tweens[backId].counter == backCounter) 2344 | return tweens[backId]; 2345 | for (int i = 0; i < tweenMaxSearch; i++) 2346 | { 2347 | if (tweens[i].uniqueId == uniqueId && tweens[i].counter == backCounter) 2348 | return tweens[i]; 2349 | } 2350 | return null; 2351 | } 2352 | 2353 | // Deprecated use pause( id ) 2354 | public static void pause(GameObject gameObject, int uniqueId) 2355 | { 2356 | pause(uniqueId); 2357 | } 2358 | 2359 | public static void pause(int uniqueId) 2360 | { 2361 | int backId = uniqueId & 0xFFFF; 2362 | int backCounter = uniqueId >> 16; 2363 | if (tweens[backId].counter == backCounter) 2364 | { 2365 | tweens[backId].pause(); 2366 | } 2367 | } 2368 | 2369 | /** 2370 | * Pause all tweens for a GameObject 2371 | * 2372 | * @method LeanTween.pause 2373 | * @param {GameObject} gameObject:GameObject GameObject whose tweens you want to pause 2374 | */ 2375 | public static void pause(GameObject gameObject) 2376 | { 2377 | Transform trans = gameObject.transform; 2378 | for (int i = 0; i < tweenMaxSearch; i++) 2379 | { 2380 | if (tweens[i].trans == trans) 2381 | { 2382 | tweens[i].pause(); 2383 | } 2384 | } 2385 | } 2386 | 2387 | // Deprecated 2388 | public static void resume(GameObject gameObject, int uniqueId) 2389 | { 2390 | resume(uniqueId); 2391 | } 2392 | 2393 | /** 2394 | * Resume a specific tween 2395 | * 2396 | * @method LeanTween.resume 2397 | * @param {int} id:int Id of the tween you want to resume ex: int id = LeanTween.MoveX(gameObject, 5, 1.0).id; 2398 | */ 2399 | public static void resume(int uniqueId) 2400 | { 2401 | int backId = uniqueId & 0xFFFF; 2402 | int backCounter = uniqueId >> 16; 2403 | if (tweens[backId].counter == backCounter) 2404 | { 2405 | tweens[backId].resume(); 2406 | } 2407 | } 2408 | 2409 | /** 2410 | * Resume all the tweens on a GameObject 2411 | * 2412 | * @method LeanTween.resume 2413 | * @param {GameObject} gameObject:GameObject GameObject whose tweens you want to resume 2414 | */ 2415 | public static void resume(GameObject gameObject) 2416 | { 2417 | Transform trans = gameObject.transform; 2418 | for (int i = 0; i < tweenMaxSearch; i++) 2419 | { 2420 | if (tweens[i].trans == trans) 2421 | tweens[i].resume(); 2422 | } 2423 | } 2424 | 2425 | /** 2426 | * Test whether or not a tween is active on a GameObject 2427 | * 2428 | * @method LeanTween.isTweening 2429 | * @param {GameObject} gameObject:GameObject GameObject that you want to test if it is tweening 2430 | */ 2431 | public static bool isTweening(GameObject gameObject) 2432 | { 2433 | Transform trans = gameObject.transform; 2434 | for (int i = 0; i < tweenMaxSearch; i++) 2435 | { 2436 | if (tweens[i].toggle && tweens[i].trans == trans) 2437 | return true; 2438 | } 2439 | return false; 2440 | } 2441 | 2442 | /** 2443 | * Test whether or not a tween is active or not 2444 | * 2445 | * @method LeanTween.isTweening 2446 | * @param {GameObject} id:int id of the tween that you want to test if it is tweening 2447 | *   Example:
2448 | *   int id = LeanTween.moveX(gameObject, 1f, 3f).id;
2449 | *   if(LeanTween.isTweening( id ))
2450 | *      Debug.Log("I am tweening!");
2451 | */ 2452 | public static bool isTweening(int uniqueId) 2453 | { 2454 | int backId = uniqueId & 0xFFFF; 2455 | int backCounter = uniqueId >> 16; 2456 | if (tweens[backId].counter == backCounter && tweens[backId].toggle) 2457 | { 2458 | return true; 2459 | } 2460 | return false; 2461 | } 2462 | 2463 | /** 2464 | * Test whether or not a tween is active on a LTRect 2465 | * 2466 | * @method LeanTween.isTweening 2467 | * @param {LTRect} ltRect:LTRect LTRect that you want to test if it is tweening 2468 | */ 2469 | public static bool isTweening(LTRect ltRect) 2470 | { 2471 | for (int i = 0; i < tweenMaxSearch; i++) 2472 | { 2473 | if (tweens[i].toggle && tweens[i].ltRect == ltRect) 2474 | return true; 2475 | } 2476 | return false; 2477 | } 2478 | 2479 | public static void drawBezierPath(Vector3 a, Vector3 b, Vector3 c, Vector3 d) 2480 | { 2481 | Vector3 last = a; 2482 | Vector3 p; 2483 | Vector3 aa = (-a + 3 * (b - c) + d); 2484 | Vector3 bb = 3 * (a + c) - 6 * b; 2485 | Vector3 cc = 3 * (b - a); 2486 | float t; 2487 | for (float k = 1.0f; k <= 30.0f; k++) 2488 | { 2489 | t = k / 30.0f; 2490 | p = ((aa * t + (bb)) * t + cc) * t + a; 2491 | Gizmos.DrawLine(last, p); 2492 | last = p; 2493 | } 2494 | } 2495 | 2496 | public static object logError(string error) 2497 | { 2498 | if (throwErrors) Debug.LogError(error); else Debug.Log(error); 2499 | return null; 2500 | } 2501 | 2502 | // LeanTween 2.0 Methods 2503 | 2504 | public static LTDescr options(LTDescr seed) 2505 | { 2506 | Debug.LogError("error this function is no longer used"); return null; 2507 | } 2508 | public static LTDescr options() 2509 | { 2510 | init(); 2511 | 2512 | for (j = 0, i = startSearch; j < maxTweens; i++) 2513 | { 2514 | if (i >= maxTweens - 1) 2515 | i = 0; 2516 | if (tweens[i].toggle == false) 2517 | { 2518 | if (i + 1 > tweenMaxSearch) 2519 | tweenMaxSearch = i + 1; 2520 | startSearch = i + 1; 2521 | break; 2522 | } 2523 | 2524 | j++; 2525 | if (j >= maxTweens) 2526 | 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; 2527 | } 2528 | tween = tweens[i]; 2529 | tween.reset(); 2530 | tween.setId((uint)i); 2531 | 2532 | return tween; 2533 | } 2534 | 2535 | public static GameObject tweenEmpty 2536 | { 2537 | get 2538 | { 2539 | init(maxTweens); 2540 | return _tweenEmpty; 2541 | } 2542 | } 2543 | 2544 | public static int startSearch = 0; 2545 | public static LTDescr descr; 2546 | 2547 | private static LTDescr pushNewTween(GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, LTDescr tween) 2548 | { 2549 | init(maxTweens); 2550 | if (gameObject == null) 2551 | return null; 2552 | tween.trans = gameObject.transform; 2553 | tween.to = to; 2554 | tween.time = time; 2555 | tween.type = tweenAction; 2556 | tween.hasPhysics = gameObject.rigidbody != null; 2557 | 2558 | return tween; 2559 | } 2560 | 2561 | /** 2562 | * 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. 2563 | * 2564 | * @method LeanTween.alpha 2565 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to fade 2566 | * @param {float} to:float the final alpha value (0-1) 2567 | * @param {float} time:float The time with which to fade the object 2568 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2569 | * @example 2570 | * LeanTween.alpha(gameObject, 1f, 1f) .setDelay(1f); 2571 | */ 2572 | public static LTDescr alpha(GameObject gameObject, float to, float time) 2573 | { 2574 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ALPHA, options()); 2575 | } 2576 | 2577 | /** 2578 | * Fade a GUI Object 2579 | * 2580 | * @method LeanTween.alpha 2581 | * @param {LTRect} ltRect:LTRect LTRect that you wish to fade 2582 | * @param {float} to:float the final alpha value (0-1) 2583 | * @param {float} time:float The time with which to fade the object 2584 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2585 | * @example 2586 | * LeanTween.alpha(ltRect, 1f, 1f) .setEase(LeanTweenType.easeInCirc); 2587 | */ 2588 | public static LTDescr alpha(LTRect ltRect, float to, float time) 2589 | { 2590 | ltRect.alphaEnabled = true; 2591 | return pushNewTween(tweenEmpty, new Vector3(to, 0f, 0f), time, TweenAction.GUI_ALPHA, options().setRect(ltRect)); 2592 | } 2593 | 2594 | /** 2595 | * This works by tweening the vertex colors directly.
2596 |
2597 | Vertex-based coloring is useful because you avoid making a copy of your 2598 | object's material for each instance that needs a different color.
2599 |
2600 | A shader that supports vertex colors is required for it to work 2601 | (for example the shaders in Mobile/Particles/) 2602 | * 2603 | * @method LeanTween.alphaVertex 2604 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to alpha 2605 | * @param {float} to:float The alpha value you wish to tween to 2606 | * @param {float} time:float The time with which to delay before calling the function 2607 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2608 | */ 2609 | public static LTDescr alphaVertex(GameObject gameObject, float to, float time) 2610 | { 2611 | return pushNewTween(gameObject, new Vector3(to, 0f, 0f), time, TweenAction.ALPHA_VERTEX, options()); 2612 | } 2613 | 2614 | public static LTDescr delayedCall(float delayTime, Action callback) 2615 | { 2616 | return pushNewTween(tweenEmpty, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback)); 2617 | } 2618 | 2619 | public static LTDescr delayedCall(float delayTime, Action callback) 2620 | { 2621 | return pushNewTween(tweenEmpty, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback)); 2622 | } 2623 | 2624 | public static LTDescr delayedCall(GameObject gameObject, float delayTime, Action callback) 2625 | { 2626 | return pushNewTween(gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback)); 2627 | } 2628 | 2629 | public static LTDescr delayedCall(GameObject gameObject, float delayTime, Action callback) 2630 | { 2631 | return pushNewTween(gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete(callback)); 2632 | } 2633 | 2634 | public static LTDescr destroyAfter(LTRect rect, float delayTime) 2635 | { 2636 | return pushNewTween(tweenEmpty, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setRect(rect).setDestroyOnComplete(true)); 2637 | } 2638 | 2639 | /*public static LTDescr delayedCall(GameObject gameObject, float delayTime, string callback){ 2640 | return pushNewTween( gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, options().setOnComplete( callback ) ); 2641 | }*/ 2642 | 2643 | /** 2644 | * Move a GameObject to a certain location 2645 | * 2646 | * @method LeanTween.move 2647 | * @param {GameObject} GameObject gameObject Gameobject that you wish to move 2648 | * @param {Vector3} vec:Vector3 to The final positin with which to move to 2649 | * @param {float} time:float time The time to complete the tween in 2650 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2651 | * @example LeanTween.move(gameObject, new Vector3(0f,-3f,5f), 2.0f) .setEase( LeanTween.easeOutQuad ); 2652 | */ 2653 | public static LTDescr move(GameObject gameObject, Vector3 to, float time) 2654 | { 2655 | return pushNewTween(gameObject, to, time, TweenAction.MOVE, options()); 2656 | } 2657 | public static LTDescr move(GameObject gameObject, Vector2 to, float time) 2658 | { 2659 | return pushNewTween(gameObject, new Vector3(to.x, to.y, gameObject.transform.position.z), time, TweenAction.MOVE, options()); 2660 | } 2661 | 2662 | /** 2663 | * Move a GameObject along a set of bezier curves 2664 | * 2665 | * @method LeanTween.move 2666 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to move 2667 | * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,... 2668 | * @param {float} time:float The time to complete the tween in 2669 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2670 | * @example 2671 | * Javascript:
2672 | * LeanTween.move(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0) .setEase(LeanTween.easeOutQuad).setOrientToPath(true);

2673 | * C#:
2674 | * LeanTween.move(gameObject, new Vector3{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}, 1.5f) .setEase(LeanTween.easeOutQuad).setOrientToPath(true);;
2675 | */ 2676 | public static LTDescr move(GameObject gameObject, Vector3[] to, float time) 2677 | { 2678 | descr = options(); 2679 | if (descr.path == null) 2680 | descr.path = new LTBezierPath(to); 2681 | else 2682 | descr.path.setPoints(to); 2683 | 2684 | return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED, descr); 2685 | } 2686 | 2687 | /** 2688 | * Move a GUI Element to a certain location 2689 | * 2690 | * @method LeanTween.move (GUI) 2691 | * @param {LTRect} ltRect:LTRect ltRect LTRect object that you wish to move 2692 | * @param {Vector2} vec:Vector2 to The final position with which to move to (pixel coordinates) 2693 | * @param {float} time:float time The time to complete the tween in 2694 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2695 | */ 2696 | public static LTDescr move(LTRect ltRect, Vector2 to, float time) 2697 | { 2698 | return pushNewTween(tweenEmpty, to, time, TweenAction.GUI_MOVE, options().setRect(ltRect)); 2699 | } 2700 | 2701 | public static LTDescr moveMargin(LTRect ltRect, Vector2 to, float time) 2702 | { 2703 | return pushNewTween(tweenEmpty, to, time, TweenAction.GUI_MOVE_MARGIN, options().setRect(ltRect)); 2704 | } 2705 | 2706 | /** 2707 | * Move a GameObject along the x-axis 2708 | * 2709 | * @method LeanTween.moveX 2710 | * @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to move 2711 | * @param {float} to:float to The final position with which to move to 2712 | * @param {float} time:float time The time to complete the move in 2713 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2714 | */ 2715 | public static LTDescr moveX(GameObject gameObject, float to, float time) 2716 | { 2717 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_X, options()); 2718 | } 2719 | 2720 | /** 2721 | * Move a GameObject along the y-axis 2722 | * 2723 | * @method LeanTween.moveY 2724 | * @param {GameObject} GameObject gameObject Gameobject that you wish to move 2725 | * @param {float} float to The final position with which to move to 2726 | * @param {float} float time The time to complete the move in 2727 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2728 | */ 2729 | public static LTDescr moveY(GameObject gameObject, float to, float time) 2730 | { 2731 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_Y, options()); 2732 | } 2733 | 2734 | /** 2735 | * Move a GameObject along the z-axis 2736 | * 2737 | * @method LeanTween.moveZ 2738 | * @param {GameObject} GameObject gameObject Gameobject that you wish to move 2739 | * @param {float} float to The final position with which to move to 2740 | * @param {float} float time The time to complete the move in 2741 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2742 | */ 2743 | public static LTDescr moveZ(GameObject gameObject, float to, float time) 2744 | { 2745 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_Z, options()); 2746 | } 2747 | 2748 | /** 2749 | * Move a GameObject to a certain location relative to the parent transform. 2750 | * 2751 | * @method LeanTween.moveLocal 2752 | * @param {GameObject} GameObject gameObject Gameobject that you wish to rotate 2753 | * @param {Vector3} Vector3 to The final positin with which to move to 2754 | * @param {float} float time The time to complete the tween in 2755 | * @param {Hashtable} Hashtable optional Hashtable where you can pass optional items. 2756 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2757 | */ 2758 | public static LTDescr moveLocal(GameObject gameObject, Vector3 to, float time) 2759 | { 2760 | return pushNewTween(gameObject, to, time, TweenAction.MOVE_LOCAL, options()); 2761 | } 2762 | 2763 | /** 2764 | * Move a GameObject along a set of bezier curves 2765 | * 2766 | * @method LeanTween.move 2767 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to move 2768 | * @param {Vector3[]} path:Vector3[] A set of points that define the curve(s) ex: Point1,Handle1,Handle2,Point2,... 2769 | * @param {float} time:float The time to complete the tween in 2770 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2771 | * @example 2772 | * Javascript:
2773 | * LeanTween.move(gameObject, [Vector3(0,0,0),Vector3(1,0,0),Vector3(1,0,0),Vector3(1,0,1)], 2.0).setEase(LeanTween.easeOutQuad).setOrientToPath(true);

2774 | * C#:
2775 | * LeanTween.move(gameObject, new Vector3{Vector3(0f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,0f),Vector3(1f,0f,1f)}).setEase(LeanTween.easeOutQuad).setOrientToPath(true);
2776 | */ 2777 | public static LTDescr moveLocal(GameObject gameObject, Vector3[] to, float time) 2778 | { 2779 | descr = options(); 2780 | if (descr.path == null) 2781 | descr.path = new LTBezierPath(to); 2782 | else 2783 | descr.path.setPoints(to); 2784 | 2785 | return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED_LOCAL, descr); 2786 | } 2787 | 2788 | public static LTDescr moveLocalX(GameObject gameObject, float to, float time) 2789 | { 2790 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_LOCAL_X, options()); 2791 | } 2792 | 2793 | public static LTDescr moveLocalY(GameObject gameObject, float to, float time) 2794 | { 2795 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_LOCAL_Y, options()); 2796 | } 2797 | 2798 | public static LTDescr moveLocalZ(GameObject gameObject, float to, float time) 2799 | { 2800 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_LOCAL_Z, options()); 2801 | } 2802 | 2803 | /** 2804 | * Rotate a GameObject, to values are in passed in degrees 2805 | * 2806 | * @method LeanTween.rotate 2807 | * @param {GameObject} GameObject gameObject Gameobject that you wish to rotate 2808 | * @param {Vector3} Vector3 to The final rotation with which to rotate to 2809 | * @param {float} float time The time to complete the tween in 2810 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2811 | * @example LeanTween.rotate(cube, new Vector3(180f,30f,0f), 1.5f); 2812 | */ 2813 | 2814 | public static LTDescr rotate(GameObject gameObject, Vector3 to, float time) 2815 | { 2816 | return pushNewTween(gameObject, to, time, TweenAction.ROTATE, options()); 2817 | } 2818 | 2819 | /** 2820 | * Rotate a GUI element (using an LTRect object), to a value that is in degrees 2821 | * 2822 | * @method LeanTween.rotate 2823 | * @param {LTRect} ltRect:LTRect LTRect that you wish to rotate 2824 | * @param {float} to:float The final rotation with which to rotate to 2825 | * @param {float} time:float The time to complete the tween in 2826 | * @param {Array} optional:Array Object Array where you can pass optional items. 2827 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2828 | * @example 2829 | * if(GUI.Button(buttonRect.rect, "Rotate"))
2830 | * LeanTween.rotate( buttonRect4, 150.0f, 1.0f).setEase(LeanTween.easeOutElastic);
2831 | * GUI.matrix = Matrix4x4.identity;
2832 | */ 2833 | public static LTDescr rotate(LTRect ltRect, float to, float time) 2834 | { 2835 | return pushNewTween(tweenEmpty, new Vector3(to, 0f, 0f), time, TweenAction.GUI_ROTATE, options().setRect(ltRect)); 2836 | } 2837 | 2838 | /** 2839 | * Rotate a GameObject in the objects local space (on the transforms localEulerAngles object) 2840 | * 2841 | * @method LeanTween.rotateLocal 2842 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate 2843 | * @param {Vector3} to:Vector3 The final rotation with which to rotate to 2844 | * @param {float} time:float The time to complete the rotation in 2845 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2846 | */ 2847 | public static LTDescr rotateLocal(GameObject gameObject, Vector3 to, float time) 2848 | { 2849 | return pushNewTween(gameObject, to, time, TweenAction.ROTATE_LOCAL, options()); 2850 | } 2851 | 2852 | /** 2853 | * Rotate a GameObject only on the X axis 2854 | * 2855 | * @method LeanTween.rotateX 2856 | * @param {GameObject} GameObject Gameobject that you wish to rotate 2857 | * @param {float} to:float The final x-axis rotation with which to rotate 2858 | * @param {float} time:float The time to complete the rotation in 2859 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2860 | */ 2861 | public static LTDescr rotateX(GameObject gameObject, float to, float time) 2862 | { 2863 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ROTATE_X, options()); 2864 | } 2865 | 2866 | /** 2867 | * Rotate a GameObject only on the Y axis 2868 | * 2869 | * @method LeanTween.rotateY 2870 | * @param {GameObject} GameObject Gameobject that you wish to rotate 2871 | * @param {float} to:float The final y-axis rotation with which to rotate 2872 | * @param {float} time:float The time to complete the rotation in 2873 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2874 | */ 2875 | public static LTDescr rotateY(GameObject gameObject, float to, float time) 2876 | { 2877 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ROTATE_Y, options()); 2878 | } 2879 | 2880 | /** 2881 | * Rotate a GameObject only on the Z axis 2882 | * 2883 | * @method LeanTween.rotateZ 2884 | * @param {GameObject} GameObject Gameobject that you wish to rotate 2885 | * @param {float} to:float The final z-axis rotation with which to rotate 2886 | * @param {float} time:float The time to complete the rotation in 2887 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2888 | */ 2889 | public static LTDescr rotateZ(GameObject gameObject, float to, float time) 2890 | { 2891 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ROTATE_Z, options()); 2892 | } 2893 | 2894 | /** 2895 | * Rotate a GameObject around a certain Axis (the best method to use when you want to rotate beyond 180 degrees) 2896 | * 2897 | * @method LeanTween.rotateAround 2898 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to rotate 2899 | * @param {Vector3} vec:Vector3 axis in which to rotate around ex: Vector3.up 2900 | * @param {float} degrees:float the degrees in which to rotate 2901 | * @param {float} time:float time The time to complete the rotation in 2902 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2903 | * @example 2904 | * Example:
2905 | * LeanTween.rotateAround ( gameObject, Vector3.left, 90f, 1f ); 2906 | */ 2907 | public static LTDescr rotateAround(GameObject gameObject, Vector3 axis, float add, float time) 2908 | { 2909 | return pushNewTween(gameObject, new Vector3(add, 0f, 0f), time, TweenAction.ROTATE_AROUND, options().setAxis(axis)); 2910 | } 2911 | 2912 | /** 2913 | * Scale a GameObject to a certain size 2914 | * 2915 | * @method LeanTween.scale 2916 | * @param {GameObject} gameObject:GameObject gameObject Gameobject that you wish to scale 2917 | * @param {Vector3} vec:Vector3 to The size with which to tween to 2918 | * @param {float} time:float time The time to complete the tween in 2919 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2920 | */ 2921 | public static LTDescr scale(GameObject gameObject, Vector3 to, float time) 2922 | { 2923 | return pushNewTween(gameObject, to, time, TweenAction.SCALE, options()); 2924 | } 2925 | 2926 | /** 2927 | * Scale a GUI Element to a certain width and height 2928 | * 2929 | * @method LeanTween.scale (GUI) 2930 | * @param {LTRect} LTRect ltRect LTRect object that you wish to move 2931 | * @param {Vector2} Vector2 to The final width and height to scale to (pixel based) 2932 | * @param {float} float time The time to complete the tween in 2933 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2934 | * @example 2935 | * Example Javascript:
2936 | * var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
2937 | * LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 ).setEase(LeanTweenType.easeOutBounce);
2938 | * function OnGUI(){
2939 | *   if(GUI.Button(bRect.rect, "Scale")){ }
2940 | * }
2941 | *
2942 | * Example C#:
2943 | * LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
2944 | * LeanTween.scale( bRect, new Vector2(150f,75f), 0.25f ).setEase(LeanTweenType.easeOutBounce);
2945 | * void OnGUI(){
2946 | *   if(GUI.Button(bRect.rect, "Scale")){ }
2947 | * }
2948 | */ 2949 | public static LTDescr scale(LTRect ltRect, Vector2 to, float time) 2950 | { 2951 | return pushNewTween(tweenEmpty, to, time, TweenAction.GUI_SCALE, options().setRect(ltRect)); 2952 | } 2953 | 2954 | /** 2955 | * Scale a GameObject to a certain size along the x-axis only 2956 | * 2957 | * @method LeanTween.scaleX 2958 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale 2959 | * @param {float} scaleTo:float the size with which to scale to 2960 | * @param {float} time:float the time to complete the tween in 2961 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2962 | */ 2963 | public static LTDescr scaleX(GameObject gameObject, float to, float time) 2964 | { 2965 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.SCALE_X, options()); 2966 | } 2967 | 2968 | /** 2969 | * Scale a GameObject to a certain size along the y-axis only 2970 | * 2971 | * @method LeanTween.scaleY 2972 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale 2973 | * @param {float} scaleTo:float the size with which to scale to 2974 | * @param {float} time:float the time to complete the tween in 2975 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2976 | */ 2977 | public static LTDescr scaleY(GameObject gameObject, float to, float time) 2978 | { 2979 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.SCALE_Y, options()); 2980 | } 2981 | 2982 | /** 2983 | * Scale a GameObject to a certain size along the z-axis only 2984 | * 2985 | * @method LeanTween.scaleZ 2986 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to scale 2987 | * @param {float} scaleTo:float the size with which to scale to 2988 | * @param {float} time:float the time to complete the tween in 2989 | * @return {LTDescr} LTDescr an object that distinguishes the tween 2990 | */ 2991 | public static LTDescr scaleZ(GameObject gameObject, float to, float time) 2992 | { 2993 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.SCALE_Z, options()); 2994 | } 2995 | 2996 | /** 2997 | * Tween any particular value, it does not need to be tied to any particular type or GameObject 2998 | * 2999 | * @method LeanTween.value (float) 3000 | * @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 3001 | * @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 ){ } 3002 | * @param {float} float from The original value to start the tween from 3003 | * @param {float} float to The value to end the tween on 3004 | * @param {float} float time The time to complete the tween in 3005 | * @return {LTDescr} LTDescr an object that distinguishes the tween 3006 | */ 3007 | public static LTDescr value(GameObject gameObject, Action callOnUpdate, float from, float to, float time) 3008 | { 3009 | 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)); 3010 | } 3011 | 3012 | /** 3013 | * Tween any particular value (Vector3), this could be used to tween an arbitrary value like a material color 3014 | * 3015 | * @method LeanTween.value (Vector3) 3016 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to 3017 | * @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 ){ } 3018 | * @param {float} from:Vector3 The original value to start the tween from 3019 | * @param {Vector3} to:Vector3 The final Vector3 with which to tween to 3020 | * @param {float} time:float The time to complete the tween in 3021 | * @return {LTDescr} LTDescr an object that distinguishes the tween 3022 | */ 3023 | public static LTDescr value(GameObject gameObject, Action callOnUpdate, Vector3 from, Vector3 to, float time) 3024 | { 3025 | return pushNewTween(gameObject, to, time, TweenAction.VALUE3, options().setTo(to).setFrom(from).setOnUpdateVector3(callOnUpdate)); 3026 | } 3027 | 3028 | /** 3029 | * Tween any particular value (float) 3030 | * 3031 | * @method LeanTween.value (float,object) 3032 | * @param {GameObject} gameObject:GameObject Gameobject that you wish to attach the tween to 3033 | * @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 ){ } 3034 | * @param {float} from:Vector3 The original value to start the tween from 3035 | * @param {Vector3} to:Vector3 The final Vector3 with which to tween to 3036 | * @param {float} time:float The time to complete the tween in 3037 | * @return {LTDescr} LTDescr an object that distinguishes the tween 3038 | */ 3039 | public static LTDescr value(GameObject gameObject, Action callOnUpdate, float from, float to, float time) 3040 | { 3041 | 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)); 3042 | } 3043 | 3044 | #if !UNITY_METRO 3045 | // LeanTween 1.x Methods 3046 | 3047 | public static Hashtable h(object[] arr) 3048 | { 3049 | if (arr.Length % 2 == 1) 3050 | { 3051 | logError("LeanTween - You have attempted to create a Hashtable with an odd number of values."); 3052 | return null; 3053 | } 3054 | Hashtable hash = new Hashtable(); 3055 | for (i = 0; i < arr.Length; i += 2) 3056 | { 3057 | hash.Add(arr[i] as string, arr[i + 1]); 3058 | } 3059 | 3060 | return hash; 3061 | } 3062 | 3063 | private static int idFromUnique(int uniqueId) 3064 | { 3065 | return uniqueId & 0xFFFFFF; 3066 | } 3067 | 3068 | private static int pushNewTween(GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, Hashtable optional) 3069 | { 3070 | init(maxTweens); 3071 | if (gameObject == null) 3072 | return -1; 3073 | 3074 | j = 0; 3075 | for (i = startSearch; j < maxTweens; i++) 3076 | { 3077 | if (i >= maxTweens - 1) 3078 | i = 0; 3079 | if (tweens[i].toggle == false) 3080 | { 3081 | if (i + 1 > tweenMaxSearch) 3082 | tweenMaxSearch = i + 1; 3083 | startSearch = i + 1; 3084 | break; 3085 | } 3086 | 3087 | j++; 3088 | if (j >= maxTweens) 3089 | { 3090 | 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) + " );"); 3091 | return -1; 3092 | } 3093 | } 3094 | tween = tweens[i]; 3095 | tween.toggle = true; 3096 | tween.reset(); 3097 | tween.trans = gameObject.transform; 3098 | tween.to = to; 3099 | tween.time = time; 3100 | tween.type = tweenAction; 3101 | tween.optional = optional; 3102 | tween.setId((uint)i); 3103 | tween.hasPhysics = gameObject.rigidbody != null; 3104 | 3105 | if (optional != null) 3106 | { 3107 | var ease = optional["ease"]; 3108 | //LeanTweenType ease; 3109 | var optionsNotUsed = 0; 3110 | if (ease != null) 3111 | { 3112 | tween.tweenType = LeanTweenType.linear; 3113 | if (ease.GetType() == typeof(LeanTweenType)) 3114 | { 3115 | tween.tweenType = (LeanTweenType)ease;// Enum.Parse(typeof(LeanTweenType), optional["ease"].ToString()); 3116 | } 3117 | else if (ease.GetType() == typeof(AnimationCurve)) 3118 | { 3119 | tween.animationCurve = optional["ease"] as AnimationCurve; 3120 | } 3121 | else 3122 | { 3123 | string func = optional["ease"].ToString(); 3124 | if (func.Equals("easeOutQuad")) 3125 | { 3126 | tween.tweenType = LeanTweenType.easeOutQuad; 3127 | } 3128 | else if (func.Equals("easeInQuad")) 3129 | { 3130 | tween.tweenType = LeanTweenType.easeInQuad; 3131 | } 3132 | else if (func.Equals("easeInOutQuad")) 3133 | { 3134 | tween.tweenType = LeanTweenType.easeInOutQuad; 3135 | } 3136 | } 3137 | optionsNotUsed++; 3138 | } 3139 | if (optional["rect"] != null) 3140 | { 3141 | tween.ltRect = (LTRect)optional["rect"]; 3142 | optionsNotUsed++; 3143 | } 3144 | if (optional["path"] != null) 3145 | { 3146 | tween.path = (LTBezierPath)optional["path"]; 3147 | optionsNotUsed++; 3148 | } 3149 | if (optional["delay"] != null) 3150 | { 3151 | tween.delay = (float)optional["delay"]; 3152 | optionsNotUsed++; 3153 | } 3154 | if (optional["useEstimatedTime"] != null) 3155 | { 3156 | tween.useEstimatedTime = (bool)optional["useEstimatedTime"]; 3157 | optionsNotUsed++; 3158 | } 3159 | if (optional["useFrames"] != null) 3160 | { 3161 | tween.useFrames = (bool)optional["useFrames"]; 3162 | optionsNotUsed++; 3163 | } 3164 | if (optional["loopType"] != null) 3165 | { 3166 | tween.loopType = (LeanTweenType)optional["loopType"]; 3167 | optionsNotUsed++; 3168 | } 3169 | if (optional["repeat"] != null) 3170 | { 3171 | tween.loopCount = (int)optional["repeat"]; 3172 | if (tween.loopType == LeanTweenType.once) 3173 | tween.loopType = LeanTweenType.clamp; 3174 | optionsNotUsed++; 3175 | } 3176 | if (optional["point"] != null) 3177 | { 3178 | tween.point = (Vector3)optional["point"]; 3179 | optionsNotUsed++; 3180 | } 3181 | if (optional["axis"] != null) 3182 | { 3183 | tween.axis = (Vector3)optional["axis"]; 3184 | optionsNotUsed++; 3185 | } 3186 | if (optional.Count <= optionsNotUsed) 3187 | tween.optional = null; // nothing else is used with the extra piece, so set to null 3188 | } 3189 | else 3190 | { 3191 | tween.optional = null; 3192 | } 3193 | //Debug.Log("pushing new tween["+i+"]:"+tweens[i]); 3194 | 3195 | return tweens[i].uniqueId; 3196 | } 3197 | 3198 | public static int value(string callOnUpdate, float from, float to, float time, Hashtable optional) 3199 | { 3200 | return value(tweenEmpty, callOnUpdate, from, to, time, optional); 3201 | } 3202 | 3203 | public static int value(GameObject gameObject, string callOnUpdate, float from, float to, float time) 3204 | { 3205 | return value(gameObject, callOnUpdate, from, to, time, new Hashtable()); 3206 | } 3207 | public static int value(GameObject gameObject, string callOnUpdate, float from, float to, float time, object[] optional) 3208 | { 3209 | return value(gameObject, callOnUpdate, from, to, time, h(optional)); 3210 | } 3211 | 3212 | public static int value(GameObject gameObject, Action callOnUpdate, float from, float to, float time, object[] optional) 3213 | { 3214 | return value(gameObject, callOnUpdate, from, to, time, h(optional)); 3215 | } 3216 | public static int value(GameObject gameObject, Action callOnUpdate, float from, float to, float time, object[] optional) 3217 | { 3218 | return value(gameObject, callOnUpdate, from, to, time, h(optional)); 3219 | } 3220 | 3221 | public static int value(GameObject gameObject, string callOnUpdate, float from, float to, float time, Hashtable optional) 3222 | { 3223 | if (optional == null || optional.Count == 0) 3224 | optional = new Hashtable(); 3225 | 3226 | optional["onUpdate"] = callOnUpdate; 3227 | int id = idFromUnique(pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.CALLBACK, optional)); 3228 | tweens[id].from = new Vector3(from, 0, 0); 3229 | return id; 3230 | } 3231 | 3232 | public static int value(GameObject gameObject, Action callOnUpdate, float from, float to, float time, Hashtable optional) 3233 | { 3234 | if (optional == null || optional.Count == 0) 3235 | optional = new Hashtable(); 3236 | 3237 | optional["onUpdate"] = callOnUpdate; 3238 | int id = idFromUnique(pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.CALLBACK, optional)); 3239 | tweens[id].from = new Vector3(from, 0, 0); 3240 | return id; 3241 | } 3242 | 3243 | public static int value(GameObject gameObject, Action callOnUpdate, float from, float to, float time, Hashtable optional) 3244 | { 3245 | if (optional == null || optional.Count == 0) 3246 | optional = new Hashtable(); 3247 | 3248 | optional["onUpdate"] = callOnUpdate; 3249 | int id = idFromUnique(pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.CALLBACK, optional)); 3250 | tweens[id].from = new Vector3(from, 0, 0); 3251 | return id; 3252 | } 3253 | 3254 | public static int value(GameObject gameObject, String callOnUpdate, Vector3 from, Vector3 to, float time, Hashtable optional) 3255 | { 3256 | if (optional == null || optional.Count == 0) 3257 | optional = new Hashtable(); 3258 | 3259 | optional["onUpdate"] = callOnUpdate; 3260 | int id = idFromUnique(pushNewTween(gameObject, to, time, TweenAction.VALUE3, optional)); 3261 | tweens[id].from = from; 3262 | return id; 3263 | } 3264 | public static int value(GameObject gameObject, String callOnUpdate, Vector3 from, Vector3 to, float time, object[] optional) 3265 | { 3266 | return value(gameObject, callOnUpdate, from, to, time, h(optional)); 3267 | } 3268 | 3269 | public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, Hashtable optional) 3270 | { 3271 | if (optional == null || optional.Count == 0) 3272 | optional = new Hashtable(); 3273 | 3274 | optional["onUpdate"] = callOnUpdate; 3275 | int id = idFromUnique(pushNewTween(gameObject, to, time, TweenAction.VALUE3, optional)); 3276 | tweens[id].from = from; 3277 | return id; 3278 | } 3279 | public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, Hashtable optional) 3280 | { 3281 | if (optional == null || optional.Count == 0) 3282 | optional = new Hashtable(); 3283 | 3284 | optional["onUpdate"] = callOnUpdate; 3285 | int id = idFromUnique(pushNewTween(gameObject, to, time, TweenAction.VALUE3, optional)); 3286 | tweens[id].from = from; 3287 | return id; 3288 | } 3289 | public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, object[] optional) 3290 | { 3291 | return value(gameObject, callOnUpdate, from, to, time, h(optional)); 3292 | } 3293 | public static int value(GameObject gameObject, System.Action callOnUpdate, Vector3 from, Vector3 to, float time, object[] optional) 3294 | { 3295 | return value(gameObject, callOnUpdate, from, to, time, h(optional)); 3296 | } 3297 | 3298 | public static int rotate(GameObject gameObject, Vector3 to, float time, Hashtable optional) 3299 | { 3300 | return pushNewTween(gameObject, to, time, TweenAction.ROTATE, optional); 3301 | } 3302 | public static int rotate(GameObject gameObject, Vector3 to, float time, object[] optional) 3303 | { 3304 | return rotate(gameObject, to, time, h(optional)); 3305 | } 3306 | 3307 | public static int rotate(LTRect ltRect, float to, float time, Hashtable optional) 3308 | { 3309 | init(); 3310 | if (optional == null || optional.Count == 0) 3311 | optional = new Hashtable(); 3312 | 3313 | optional["rect"] = ltRect; 3314 | return pushNewTween(tweenEmpty, new Vector3(to, 0f, 0f), time, TweenAction.GUI_ROTATE, optional); 3315 | } 3316 | 3317 | public static int rotate(LTRect ltRect, float to, float time, object[] optional) 3318 | { 3319 | return rotate(ltRect, to, time, h(optional)); 3320 | } 3321 | 3322 | public static int rotateX(GameObject gameObject, float to, float time, Hashtable optional) 3323 | { 3324 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ROTATE_X, optional); 3325 | } 3326 | 3327 | public static int rotateX(GameObject gameObject, float to, float time, object[] optional) 3328 | { 3329 | return rotateX(gameObject, to, time, h(optional)); 3330 | } 3331 | 3332 | public static int rotateY(GameObject gameObject, float to, float time, Hashtable optional) 3333 | { 3334 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ROTATE_Y, optional); 3335 | } 3336 | public static int rotateY(GameObject gameObject, float to, float time, object[] optional) 3337 | { 3338 | return rotateY(gameObject, to, time, h(optional)); 3339 | } 3340 | 3341 | public static int rotateZ(GameObject gameObject, float to, float time, Hashtable optional) 3342 | { 3343 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ROTATE_Z, optional); 3344 | } 3345 | 3346 | public static int rotateZ(GameObject gameObject, float to, float time, object[] optional) 3347 | { 3348 | return rotateZ(gameObject, to, time, h(optional)); 3349 | } 3350 | 3351 | public static int rotateLocal(GameObject gameObject, Vector3 to, float time, Hashtable optional) 3352 | { 3353 | return pushNewTween(gameObject, to, time, TweenAction.ROTATE_LOCAL, optional); 3354 | } 3355 | public static int rotateLocal(GameObject gameObject, Vector3 to, float time, object[] optional) 3356 | { 3357 | return rotateLocal(gameObject, to, time, h(optional)); 3358 | } 3359 | 3360 | /*public static int rotateAround(GameObject gameObject, Vector3 point, Vector3 axis, float add, float time, Hashtable optional){ 3361 | if(optional==null || optional.Count==0) 3362 | optional = new Hashtable(); 3363 | 3364 | optional["axis"] = axis; 3365 | if(optional["point"]!=null) 3366 | optional["point"] = Vector3.zero; 3367 | return pushNewTween( gameObject, new Vector3(add,0f,0f), time, TweenAction.ROTATE_AROUND, optional ); 3368 | }*/ 3369 | 3370 | public static int rotateAround(GameObject gameObject, Vector3 axis, float add, float time, Hashtable optional) 3371 | { 3372 | if (optional == null || optional.Count == 0) 3373 | optional = new Hashtable(); 3374 | 3375 | optional["axis"] = axis; 3376 | if (optional["point"] == null) 3377 | optional["point"] = Vector3.zero; 3378 | 3379 | return pushNewTween(gameObject, new Vector3(add, 0f, 0f), time, TweenAction.ROTATE_AROUND, optional); 3380 | } 3381 | 3382 | public static int rotateAround(GameObject gameObject, Vector3 axis, float add, float time, object[] optional) 3383 | { 3384 | return rotateAround(gameObject, axis, add, time, h(optional)); 3385 | } 3386 | 3387 | public static int moveX(GameObject gameObject, float to, float time, Hashtable optional) 3388 | { 3389 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_X, optional); 3390 | } 3391 | public static int moveX(GameObject gameObject, float to, float time, object[] optional) 3392 | { 3393 | return moveX(gameObject, to, time, h(optional)); 3394 | } 3395 | 3396 | public static int moveY(GameObject gameObject, float to, float time, Hashtable optional) 3397 | { 3398 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_Y, optional); 3399 | } 3400 | public static int moveY(GameObject gameObject, float to, float time, object[] optional) 3401 | { 3402 | return moveY(gameObject, to, time, h(optional)); 3403 | } 3404 | 3405 | public static int moveZ(GameObject gameObject, float to, float time, Hashtable optional) 3406 | { 3407 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_Z, optional); 3408 | } 3409 | public static int moveZ(GameObject gameObject, float to, float time, object[] optional) 3410 | { 3411 | return moveZ(gameObject, to, time, h(optional)); 3412 | } 3413 | 3414 | public static int move(GameObject gameObject, Vector3 to, float time, Hashtable optional) 3415 | { 3416 | return pushNewTween(gameObject, to, time, TweenAction.MOVE, optional); 3417 | } 3418 | 3419 | public static int move(GameObject gameObject, Vector3 to, float time, object[] optional) 3420 | { 3421 | return move(gameObject, to, time, LeanTween.h(optional)); 3422 | } 3423 | 3424 | public static int move(GameObject gameObject, Vector3[] to, float time, Hashtable optional) 3425 | { 3426 | if (to.Length < 4) 3427 | { 3428 | string errorMsg = "LeanTween - When passing values for a vector path, you must pass four or more values!"; 3429 | if (throwErrors) Debug.LogError(errorMsg); else Debug.Log(errorMsg); 3430 | return -1; 3431 | } 3432 | if (to.Length % 4 != 0) 3433 | { 3434 | string errorMsg2 = "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..."; 3435 | if (throwErrors) Debug.LogError(errorMsg2); else Debug.Log(errorMsg2); 3436 | return -1; 3437 | } 3438 | 3439 | init(); 3440 | if (optional == null || optional.Count == 0) 3441 | optional = new Hashtable(); 3442 | 3443 | LTBezierPath ltPath = new LTBezierPath(to); 3444 | if (optional["orientToPath"] != null) 3445 | ltPath.orientToPath = true; 3446 | optional["path"] = ltPath; 3447 | 3448 | return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED, optional); 3449 | } 3450 | public static int move(GameObject gameObject, Vector3[] to, float time, object[] optional) 3451 | { 3452 | return move(gameObject, to, time, LeanTween.h(optional)); 3453 | } 3454 | 3455 | public static int move(LTRect ltRect, Vector2 to, float time, Hashtable optional) 3456 | { 3457 | init(); 3458 | if (optional == null || optional.Count == 0) 3459 | optional = new Hashtable(); 3460 | 3461 | optional["rect"] = ltRect; 3462 | return pushNewTween(tweenEmpty, to, time, TweenAction.GUI_MOVE, optional); 3463 | } 3464 | public static int move(LTRect ltRect, Vector3 to, float time, object[] optional) 3465 | { 3466 | return move(ltRect, to, time, LeanTween.h(optional)); 3467 | } 3468 | 3469 | public static int moveLocal(GameObject gameObject, Vector3 to, float time, Hashtable optional) 3470 | { 3471 | return pushNewTween(gameObject, to, time, TweenAction.MOVE_LOCAL, optional); 3472 | } 3473 | public static int moveLocal(GameObject gameObject, Vector3 to, float time, object[] optional) 3474 | { 3475 | return moveLocal(gameObject, to, time, LeanTween.h(optional)); 3476 | } 3477 | 3478 | public static int moveLocal(GameObject gameObject, Vector3[] to, float time, Hashtable optional) 3479 | { 3480 | if (to.Length < 4) 3481 | { 3482 | string errorMsg = "LeanTween - When passing values for a vector path, you must pass four or more values!"; 3483 | if (throwErrors) Debug.LogError(errorMsg); else Debug.Log(errorMsg); 3484 | return -1; 3485 | } 3486 | if (to.Length % 4 != 0) 3487 | { 3488 | string errorMsg2 = "LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2..."; 3489 | if (throwErrors) Debug.LogError(errorMsg2); else Debug.Log(errorMsg2); 3490 | return -1; 3491 | } 3492 | 3493 | init(); 3494 | if (optional == null) 3495 | optional = new Hashtable(); 3496 | 3497 | LTBezierPath ltPath = new LTBezierPath(to); 3498 | if (optional["orientToPath"] != null) 3499 | ltPath.orientToPath = true; 3500 | optional["path"] = ltPath; 3501 | 3502 | return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_CURVED_LOCAL, optional); 3503 | } 3504 | public static int moveLocal(GameObject gameObject, Vector3[] to, float time, object[] optional) 3505 | { 3506 | return moveLocal(gameObject, to, time, LeanTween.h(optional)); 3507 | } 3508 | 3509 | public static int moveLocalX(GameObject gameObject, float to, float time, Hashtable optional) 3510 | { 3511 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_LOCAL_X, optional); 3512 | } 3513 | public static int moveLocalX(GameObject gameObject, float to, float time, object[] optional) 3514 | { 3515 | return moveLocalX(gameObject, to, time, h(optional)); 3516 | } 3517 | 3518 | public static int moveLocalY(GameObject gameObject, float to, float time, Hashtable optional) 3519 | { 3520 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_LOCAL_Y, optional); 3521 | } 3522 | public static int moveLocalY(GameObject gameObject, float to, float time, object[] optional) 3523 | { 3524 | return moveLocalY(gameObject, to, time, h(optional)); 3525 | } 3526 | 3527 | public static int moveLocalZ(GameObject gameObject, float to, float time, Hashtable optional) 3528 | { 3529 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.MOVE_LOCAL_Z, optional); 3530 | } 3531 | public static int moveLocalZ(GameObject gameObject, float to, float time, object[] optional) 3532 | { 3533 | return moveLocalZ(gameObject, to, time, h(optional)); 3534 | } 3535 | 3536 | public static int scale(GameObject gameObject, Vector3 to, float time, Hashtable optional) 3537 | { 3538 | return pushNewTween(gameObject, to, time, TweenAction.SCALE, optional); 3539 | } 3540 | public static int scale(GameObject gameObject, Vector3 to, float time, object[] optional) 3541 | { 3542 | return scale(gameObject, to, time, h(optional)); 3543 | } 3544 | 3545 | public static int scale(LTRect ltRect, Vector2 to, float time, Hashtable optional) 3546 | { 3547 | init(); 3548 | if (optional == null || optional.Count == 0) 3549 | optional = new Hashtable(); 3550 | 3551 | optional["rect"] = ltRect; 3552 | return pushNewTween(tweenEmpty, to, time, TweenAction.GUI_SCALE, optional); 3553 | } 3554 | public static int scale(LTRect ltRect, Vector2 to, float time, object[] optional) 3555 | { 3556 | return scale(ltRect, to, time, h(optional)); 3557 | } 3558 | 3559 | public static int alpha(LTRect ltRect, float to, float time, Hashtable optional) 3560 | { 3561 | init(); 3562 | if (optional == null || optional.Count == 0) 3563 | optional = new Hashtable(); 3564 | 3565 | ltRect.alphaEnabled = true; 3566 | optional["rect"] = ltRect; 3567 | return pushNewTween(tweenEmpty, new Vector3(to, 0f, 0f), time, TweenAction.GUI_ALPHA, optional); 3568 | } 3569 | public static int alpha(LTRect ltRect, float to, float time, object[] optional) 3570 | { 3571 | return alpha(ltRect, to, time, h(optional)); 3572 | } 3573 | 3574 | public static int scaleX(GameObject gameObject, float to, float time, Hashtable optional) 3575 | { 3576 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.SCALE_X, optional); 3577 | } 3578 | public static int scaleX(GameObject gameObject, float to, float time, object[] optional) 3579 | { 3580 | return scaleX(gameObject, to, time, h(optional)); 3581 | } 3582 | 3583 | public static int scaleY(GameObject gameObject, float to, float time, Hashtable optional) 3584 | { 3585 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.SCALE_Y, optional); 3586 | } 3587 | public static int scaleY(GameObject gameObject, float to, float time, object[] optional) 3588 | { 3589 | return scaleY(gameObject, to, time, h(optional)); 3590 | } 3591 | 3592 | public static int scaleZ(GameObject gameObject, float to, float time, Hashtable optional) 3593 | { 3594 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.SCALE_Z, optional); 3595 | } 3596 | public static int scaleZ(GameObject gameObject, float to, float time, object[] optional) 3597 | { 3598 | return scaleZ(gameObject, to, time, h(optional)); 3599 | } 3600 | 3601 | public static int delayedCall(float delayTime, string callback, Hashtable optional) 3602 | { 3603 | init(); 3604 | return delayedCall(tweenEmpty, delayTime, callback, optional); 3605 | } 3606 | public static int delayedCall(float delayTime, Action callback, object[] optional) 3607 | { 3608 | init(); 3609 | return delayedCall(tweenEmpty, delayTime, callback, h(optional)); 3610 | } 3611 | 3612 | public static int delayedCall(GameObject gameObject, float delayTime, string callback, object[] optional) 3613 | { 3614 | return delayedCall(gameObject, delayTime, callback, h(optional)); 3615 | } 3616 | 3617 | public static int delayedCall(GameObject gameObject, float delayTime, Action callback, object[] optional) 3618 | { 3619 | return delayedCall(gameObject, delayTime, callback, h(optional)); 3620 | } 3621 | 3622 | public static int delayedCall(GameObject gameObject, float delayTime, string callback, Hashtable optional) 3623 | { 3624 | if (optional == null || optional.Count == 0) 3625 | optional = new Hashtable(); 3626 | optional["onComplete"] = callback; 3627 | 3628 | return pushNewTween(gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional); 3629 | } 3630 | 3631 | public static int delayedCall(GameObject gameObject, float delayTime, Action callback, Hashtable optional) 3632 | { 3633 | if (optional == null) 3634 | optional = new Hashtable(); 3635 | optional["onComplete"] = callback; 3636 | 3637 | return pushNewTween(gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional); 3638 | } 3639 | 3640 | public static int delayedCall(GameObject gameObject, float delayTime, Action callback, Hashtable optional) 3641 | { 3642 | if (optional == null) 3643 | optional = new Hashtable(); 3644 | optional["onComplete"] = callback; 3645 | 3646 | return pushNewTween(gameObject, Vector3.zero, delayTime, TweenAction.CALLBACK, optional); 3647 | } 3648 | 3649 | public static int alpha(GameObject gameObject, float to, float time, Hashtable optional) 3650 | { 3651 | return pushNewTween(gameObject, new Vector3(to, 0, 0), time, TweenAction.ALPHA, optional); 3652 | } 3653 | public static int alpha(GameObject gameObject, float to, float time, object[] optional) 3654 | { 3655 | return alpha(gameObject, to, time, h(optional)); 3656 | } 3657 | #endif 3658 | 3659 | // Tweening Functions - Thanks to Robert Penner and GFX47 3660 | 3661 | private static float tweenOnCurve(LTDescr tweenDescr, float ratioPassed) 3662 | { 3663 | // Debug.Log("single ratio:"+ratioPassed+" tweenDescr.animationCurve.Evaluate(ratioPassed):"+tweenDescr.animationCurve.Evaluate(ratioPassed)); 3664 | return tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed); 3665 | } 3666 | 3667 | private static Vector3 tweenOnCurveVector(LTDescr tweenDescr, float ratioPassed) 3668 | { 3669 | return new Vector3(tweenDescr.from.x + (tweenDescr.diff.x) * tweenDescr.animationCurve.Evaluate(ratioPassed), 3670 | tweenDescr.from.y + (tweenDescr.diff.y) * tweenDescr.animationCurve.Evaluate(ratioPassed), 3671 | tweenDescr.from.z + (tweenDescr.diff.z) * tweenDescr.animationCurve.Evaluate(ratioPassed)); 3672 | } 3673 | 3674 | private static float easeOutQuadOpt(float start, float diff, float ratioPassed) 3675 | { 3676 | return -diff * ratioPassed * (ratioPassed - 2) + start; 3677 | } 3678 | 3679 | private static float easeInQuadOpt(float start, float diff, float ratioPassed) 3680 | { 3681 | return diff * ratioPassed * ratioPassed + start; 3682 | } 3683 | 3684 | private static float easeInOutQuadOpt(float start, float diff, float ratioPassed) 3685 | { 3686 | ratioPassed /= .5f; 3687 | if (ratioPassed < 1) return diff / 2 * ratioPassed * ratioPassed + start; 3688 | ratioPassed--; 3689 | return -diff / 2 * (ratioPassed * (ratioPassed - 2) - 1) + start; 3690 | } 3691 | 3692 | private static float linear(float start, float end, float val) 3693 | { 3694 | return Mathf.Lerp(start, end, val); 3695 | } 3696 | 3697 | private static float clerp(float start, float end, float val) 3698 | { 3699 | float min = 0.0f; 3700 | float max = 360.0f; 3701 | float half = Mathf.Abs((max - min) / 2.0f); 3702 | float retval = 0.0f; 3703 | float diff = 0.0f; 3704 | if ((end - start) < -half) 3705 | { 3706 | diff = ((max - start) + end) * val; 3707 | retval = start + diff; 3708 | } 3709 | else if ((end - start) > half) 3710 | { 3711 | diff = -((max - end) + start) * val; 3712 | retval = start + diff; 3713 | } 3714 | else retval = start + (end - start) * val; 3715 | return retval; 3716 | } 3717 | 3718 | private static float spring(float start, float end, float val) 3719 | { 3720 | val = Mathf.Clamp01(val); 3721 | 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))); 3722 | return start + (end - start) * val; 3723 | } 3724 | 3725 | private static float easeInQuad(float start, float end, float val) 3726 | { 3727 | end -= start; 3728 | return end * val * val + start; 3729 | } 3730 | 3731 | private static float easeOutQuad(float start, float end, float val) 3732 | { 3733 | end -= start; 3734 | return -end * val * (val - 2) + start; 3735 | } 3736 | 3737 | private static float easeInOutQuad(float start, float end, float val) 3738 | { 3739 | val /= .5f; 3740 | end -= start; 3741 | if (val < 1) return end / 2 * val * val + start; 3742 | val--; 3743 | return -end / 2 * (val * (val - 2) - 1) + start; 3744 | } 3745 | 3746 | private static float easeInCubic(float start, float end, float val) 3747 | { 3748 | end -= start; 3749 | return end * val * val * val + start; 3750 | } 3751 | 3752 | private static float easeOutCubic(float start, float end, float val) 3753 | { 3754 | val--; 3755 | end -= start; 3756 | return end * (val * val * val + 1) + start; 3757 | } 3758 | 3759 | private static float easeInOutCubic(float start, float end, float val) 3760 | { 3761 | val /= .5f; 3762 | end -= start; 3763 | if (val < 1) return end / 2 * val * val * val + start; 3764 | val -= 2; 3765 | return end / 2 * (val * val * val + 2) + start; 3766 | } 3767 | 3768 | private static float easeInQuart(float start, float end, float val) 3769 | { 3770 | end -= start; 3771 | return end * val * val * val * val + start; 3772 | } 3773 | 3774 | private static float easeOutQuart(float start, float end, float val) 3775 | { 3776 | val--; 3777 | end -= start; 3778 | return -end * (val * val * val * val - 1) + start; 3779 | } 3780 | 3781 | private static float easeInOutQuart(float start, float end, float val) 3782 | { 3783 | val /= .5f; 3784 | end -= start; 3785 | if (val < 1) return end / 2 * val * val * val * val + start; 3786 | val -= 2; 3787 | return -end / 2 * (val * val * val * val - 2) + start; 3788 | } 3789 | 3790 | private static float easeInQuint(float start, float end, float val) 3791 | { 3792 | end -= start; 3793 | return end * val * val * val * val * val + start; 3794 | } 3795 | 3796 | private static float easeOutQuint(float start, float end, float val) 3797 | { 3798 | val--; 3799 | end -= start; 3800 | return end * (val * val * val * val * val + 1) + start; 3801 | } 3802 | 3803 | private static float easeInOutQuint(float start, float end, float val) 3804 | { 3805 | val /= .5f; 3806 | end -= start; 3807 | if (val < 1) return end / 2 * val * val * val * val * val + start; 3808 | val -= 2; 3809 | return end / 2 * (val * val * val * val * val + 2) + start; 3810 | } 3811 | 3812 | private static float easeInSine(float start, float end, float val) 3813 | { 3814 | end -= start; 3815 | return -end * Mathf.Cos(val / 1 * (Mathf.PI / 2)) + end + start; 3816 | } 3817 | 3818 | private static float easeOutSine(float start, float end, float val) 3819 | { 3820 | end -= start; 3821 | return end * Mathf.Sin(val / 1 * (Mathf.PI / 2)) + start; 3822 | } 3823 | 3824 | private static float easeInOutSine(float start, float end, float val) 3825 | { 3826 | end -= start; 3827 | return -end / 2 * (Mathf.Cos(Mathf.PI * val / 1) - 1) + start; 3828 | } 3829 | 3830 | private static float easeInExpo(float start, float end, float val) 3831 | { 3832 | end -= start; 3833 | return end * Mathf.Pow(2, 10 * (val / 1 - 1)) + start; 3834 | } 3835 | 3836 | private static float easeOutExpo(float start, float end, float val) 3837 | { 3838 | end -= start; 3839 | return end * (-Mathf.Pow(2, -10 * val / 1) + 1) + start; 3840 | } 3841 | 3842 | private static float easeInOutExpo(float start, float end, float val) 3843 | { 3844 | val /= .5f; 3845 | end -= start; 3846 | if (val < 1) return end / 2 * Mathf.Pow(2, 10 * (val - 1)) + start; 3847 | val--; 3848 | return end / 2 * (-Mathf.Pow(2, -10 * val) + 2) + start; 3849 | } 3850 | 3851 | private static float easeInCirc(float start, float end, float val) 3852 | { 3853 | end -= start; 3854 | return -end * (Mathf.Sqrt(1 - val * val) - 1) + start; 3855 | } 3856 | 3857 | private static float easeOutCirc(float start, float end, float val) 3858 | { 3859 | val--; 3860 | end -= start; 3861 | return end * Mathf.Sqrt(1 - val * val) + start; 3862 | } 3863 | 3864 | private static float easeInOutCirc(float start, float end, float val) 3865 | { 3866 | val /= .5f; 3867 | end -= start; 3868 | if (val < 1) return -end / 2 * (Mathf.Sqrt(1 - val * val) - 1) + start; 3869 | val -= 2; 3870 | return end / 2 * (Mathf.Sqrt(1 - val * val) + 1) + start; 3871 | } 3872 | 3873 | /* GFX47 MOD START */ 3874 | private static float easeInBounce(float start, float end, float val) 3875 | { 3876 | end -= start; 3877 | float d = 1f; 3878 | return end - easeOutBounce(0, end, d - val) + start; 3879 | } 3880 | /* GFX47 MOD END */ 3881 | 3882 | /* GFX47 MOD START */ 3883 | //public static function bounce(float start, float end, float val){ 3884 | private static float easeOutBounce(float start, float end, float val) 3885 | { 3886 | val /= 1f; 3887 | end -= start; 3888 | if (val < (1 / 2.75f)) 3889 | { 3890 | return end * (7.5625f * val * val) + start; 3891 | } 3892 | else if (val < (2 / 2.75f)) 3893 | { 3894 | val -= (1.5f / 2.75f); 3895 | return end * (7.5625f * (val) * val + .75f) + start; 3896 | } 3897 | else if (val < (2.5 / 2.75)) 3898 | { 3899 | val -= (2.25f / 2.75f); 3900 | return end * (7.5625f * (val) * val + .9375f) + start; 3901 | } 3902 | else 3903 | { 3904 | val -= (2.625f / 2.75f); 3905 | return end * (7.5625f * (val) * val + .984375f) + start; 3906 | } 3907 | } 3908 | /* GFX47 MOD END */ 3909 | 3910 | /* GFX47 MOD START */ 3911 | private static float easeInOutBounce(float start, float end, float val) 3912 | { 3913 | end -= start; 3914 | float d = 1f; 3915 | if (val < d / 2) return easeInBounce(0, end, val * 2) * 0.5f + start; 3916 | else return easeOutBounce(0, end, val * 2 - d) * 0.5f + end * 0.5f + start; 3917 | } 3918 | /* GFX47 MOD END */ 3919 | 3920 | private static float easeInBack(float start, float end, float val) 3921 | { 3922 | end -= start; 3923 | val /= 1; 3924 | float s = 1.70158f; 3925 | return end * (val) * val * ((s + 1) * val - s) + start; 3926 | } 3927 | 3928 | private static float easeOutBack(float start, float end, float val) 3929 | { 3930 | float s = 1.70158f; 3931 | end -= start; 3932 | val = (val / 1) - 1; 3933 | return end * ((val) * val * ((s + 1) * val + s) + 1) + start; 3934 | } 3935 | 3936 | private static float easeInOutBack(float start, float end, float val) 3937 | { 3938 | float s = 1.70158f; 3939 | end -= start; 3940 | val /= .5f; 3941 | if ((val) < 1) 3942 | { 3943 | s *= (1.525f); 3944 | return end / 2 * (val * val * (((s) + 1) * val - s)) + start; 3945 | } 3946 | val -= 2; 3947 | s *= (1.525f); 3948 | return end / 2 * ((val) * val * (((s) + 1) * val + s) + 2) + start; 3949 | } 3950 | 3951 | /* GFX47 MOD START */ 3952 | private static float easeInElastic(float start, float end, float val) 3953 | { 3954 | end -= start; 3955 | 3956 | float d = 1f; 3957 | float p = d * .3f; 3958 | float s = 0; 3959 | float a = 0; 3960 | 3961 | if (val == 0) return start; 3962 | val = val / d; 3963 | if (val == 1) return start + end; 3964 | 3965 | if (a == 0f || a < Mathf.Abs(end)) 3966 | { 3967 | a = end; 3968 | s = p / 4; 3969 | } 3970 | else 3971 | { 3972 | s = p / (2 * Mathf.PI) * Mathf.Asin(end / a); 3973 | } 3974 | val = val - 1; 3975 | return -(a * Mathf.Pow(2, 10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p)) + start; 3976 | } 3977 | /* GFX47 MOD END */ 3978 | 3979 | /* GFX47 MOD START */ 3980 | //public static function elastic(float start, float end, float val){ 3981 | private static float easeOutElastic(float start, float end, float val) 3982 | { 3983 | /* GFX47 MOD END */ 3984 | //Thank you to rafael.marteleto for fixing this as a port over from Pedro's UnityTween 3985 | end -= start; 3986 | 3987 | float d = 1f; 3988 | float p = d * .3f; 3989 | float s = 0; 3990 | float a = 0; 3991 | 3992 | if (val == 0) return start; 3993 | 3994 | val = val / d; 3995 | if (val == 1) return start + end; 3996 | 3997 | if (a == 0f || a < Mathf.Abs(end)) 3998 | { 3999 | a = end; 4000 | s = p / 4; 4001 | } 4002 | else 4003 | { 4004 | s = p / (2 * Mathf.PI) * Mathf.Asin(end / a); 4005 | } 4006 | 4007 | return (a * Mathf.Pow(2, -10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p) + end + start); 4008 | } 4009 | 4010 | /* GFX47 MOD START */ 4011 | private static float easeInOutElastic(float start, float end, float val) 4012 | { 4013 | end -= start; 4014 | 4015 | float d = 1f; 4016 | float p = d * .3f; 4017 | float s = 0; 4018 | float a = 0; 4019 | 4020 | if (val == 0) return start; 4021 | 4022 | val = val / (d / 2); 4023 | if (val == 2) return start + end; 4024 | 4025 | if (a == 0f || a < Mathf.Abs(end)) 4026 | { 4027 | a = end; 4028 | s = p / 4; 4029 | } 4030 | else 4031 | { 4032 | s = p / (2 * Mathf.PI) * Mathf.Asin(end / a); 4033 | } 4034 | 4035 | if (val < 1) 4036 | { 4037 | val = val - 1; 4038 | return -0.5f * (a * Mathf.Pow(2, 10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p)) + start; 4039 | } 4040 | val = val - 1; 4041 | return a * Mathf.Pow(2, -10 * val) * Mathf.Sin((val * d - s) * (2 * Mathf.PI) / p) * 0.5f + end + start; 4042 | } 4043 | 4044 | // LeanTween Listening/Dispatch 4045 | 4046 | private static System.Action[] eventListeners; 4047 | private static GameObject[] goListeners; 4048 | private static int eventsMaxSearch = 0; 4049 | public static int EVENTS_MAX = 10; 4050 | public static int LISTENERS_MAX = 10; 4051 | 4052 | public static void addListener(int eventId, System.Action callback) 4053 | { 4054 | addListener(tweenEmpty, eventId, callback); 4055 | } 4056 | 4057 | /** 4058 | * Add a listener method to be called when the appropriate LeanTween.dispatchEvent is called 4059 | * @method LeanTween.addListener 4060 | * @param {GameObject} caller:GameObject the gameObject the listener is attached to 4061 | * @param {int} eventId:int a unique int that describes the event (best to use an enum) 4062 | * @param {System.Action} callback:System.Action the method to call when the event has been dispatched 4063 | * @example 4064 | * LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp);
4065 | *
4066 | * void jumpUp( LTEvent e ){ Debug.Log("jump!"); }
4067 | */ 4068 | public static void addListener(GameObject caller, int eventId, System.Action callback) 4069 | { 4070 | if (eventListeners == null) 4071 | { 4072 | eventListeners = new System.Action[EVENTS_MAX * LISTENERS_MAX]; 4073 | goListeners = new GameObject[EVENTS_MAX * LISTENERS_MAX]; 4074 | } 4075 | // Debug.Log("searching for an empty space for:"+caller + " eventid:"+event); 4076 | for (i = 0; i < LISTENERS_MAX; i++) 4077 | { 4078 | int point = eventId * LISTENERS_MAX + i; 4079 | if (goListeners[point] == null || eventListeners[point] == null) 4080 | { 4081 | eventListeners[point] = callback; 4082 | goListeners[point] = caller; 4083 | if (i >= eventsMaxSearch) 4084 | eventsMaxSearch = i + 1; 4085 | // Debug.Log("adding event for:"+caller.name); 4086 | 4087 | return; 4088 | } 4089 | if (goListeners[point] == caller && System.Object.ReferenceEquals(eventListeners[point], callback)) 4090 | { 4091 | // Debug.Log("This event is already being listened for."); 4092 | return; 4093 | } 4094 | } 4095 | Debug.LogError("You ran out of areas to add listeners, consider increasing LISTENERS_MAX, ex: LeanTween.LISTENERS_MAX = " + (LISTENERS_MAX * 2)); 4096 | } 4097 | 4098 | public static bool removeListener(int eventId, System.Action callback) 4099 | { 4100 | return removeListener(tweenEmpty, eventId, callback); 4101 | } 4102 | 4103 | /** 4104 | * Remove an event listener you have added 4105 | * @method LeanTween.removeListener 4106 | * @param {GameObject} caller:GameObject the gameObject the listener is attached to 4107 | * @param {int} eventId:int a unique int that describes the event (best to use an enum) 4108 | * @param {System.Action} callback:System.Action the method that was specified to call when the event has been dispatched 4109 | * @example 4110 | * LeanTween.removeListener(gameObject, (int)MyEvents.JUMP, jumpUp);
4111 | *
4112 | * void jumpUp( LTEvent e ){ }
4113 | */ 4114 | public static bool removeListener(GameObject caller, int eventId, System.Action callback) 4115 | { 4116 | for (i = 0; i < eventsMaxSearch; i++) 4117 | { 4118 | int point = eventId * LISTENERS_MAX + i; 4119 | if (goListeners[point] == caller && System.Object.ReferenceEquals(eventListeners[point], callback)) 4120 | { 4121 | eventListeners[point] = null; 4122 | goListeners[point] = null; 4123 | return true; 4124 | } 4125 | } 4126 | return false; 4127 | } 4128 | 4129 | /** 4130 | * Tell the added listeners that you are dispatching the event 4131 | * @method LeanTween.dispatchEvent 4132 | * @param {int} eventId:int a unique int that describes the event (best to use an enum) 4133 | * @example 4134 | * LeanTween.dispatchEvent( (int)MyEvents.JUMP );
4135 | */ 4136 | public static void dispatchEvent(int eventId) 4137 | { 4138 | dispatchEvent(eventId, null); 4139 | } 4140 | 4141 | /** 4142 | * Tell the added listeners that you are dispatching the event 4143 | * @method LeanTween.dispatchEvent 4144 | * @param {int} eventId:int a unique int that describes the event (best to use an enum) 4145 | * @param {object} data:object Pass data to the listener, access it from the listener with *.data on the LTEvent object 4146 | * @example 4147 | * LeanTween.dispatchEvent( (int)MyEvents.JUMP, transform );
4148 | *
4149 | * void jumpUp( LTEvent e ){
4150 | *   Transform tran = (Transform)e.data;
4151 | * }
4152 | */ 4153 | public static void dispatchEvent(int eventId, object data) 4154 | { 4155 | for (int k = 0; k < eventsMaxSearch; k++) 4156 | { 4157 | int point = eventId * LISTENERS_MAX + k; 4158 | if (eventListeners[point] != null) 4159 | { 4160 | if (goListeners[point]) 4161 | { 4162 | eventListeners[point](new LTEvent(eventId, data)); 4163 | } 4164 | else 4165 | { 4166 | eventListeners[point] = null; 4167 | } 4168 | } 4169 | } 4170 | } 4171 | } 4172 | 4173 | /** 4174 | * Object that describes the event to an event listener 4175 | * @class LTEvent 4176 | * @constructor 4177 | * @param {object} data:object Data that has been passed from the dispatchEvent method 4178 | */ 4179 | public class LTEvent 4180 | { 4181 | public int id; 4182 | public object data; 4183 | 4184 | public LTEvent(int id, object data) 4185 | { 4186 | this.id = id; 4187 | this.data = data; 4188 | } 4189 | } 4190 | 4191 | public class LTGUI 4192 | { 4193 | public static int RECT_LEVELS = 5; 4194 | public static int RECTS_PER_LEVEL = 10; 4195 | public static int BUTTONS_MAX = 24; 4196 | 4197 | private static LTRect[] levels; 4198 | private static int[] levelDepths; 4199 | private static Rect[] buttons; 4200 | private static int[] buttonLevels; 4201 | private static int[] buttonLastFrame; 4202 | private static LTRect r; 4203 | private static Color color = Color.white; 4204 | private static bool isGUIEnabled = false; 4205 | private static int global_counter = 0; 4206 | 4207 | public enum Element_Type 4208 | { 4209 | Texture, 4210 | Label 4211 | } 4212 | 4213 | public static void init() 4214 | { 4215 | if (levels == null) 4216 | { 4217 | levels = new LTRect[RECT_LEVELS * RECTS_PER_LEVEL]; 4218 | levelDepths = new int[RECT_LEVELS]; 4219 | } 4220 | } 4221 | 4222 | public static void initRectCheck() 4223 | { 4224 | if (buttons == null) 4225 | { 4226 | buttons = new Rect[BUTTONS_MAX]; 4227 | buttonLevels = new int[BUTTONS_MAX]; 4228 | buttonLastFrame = new int[BUTTONS_MAX]; 4229 | for (int i = 0; i < buttonLevels.Length; i++) 4230 | { 4231 | buttonLevels[i] = -1; 4232 | } 4233 | } 4234 | } 4235 | 4236 | public static void reset() 4237 | { 4238 | if (isGUIEnabled) 4239 | { 4240 | isGUIEnabled = false; 4241 | for (int i = 0; i < levels.Length; i++) 4242 | { 4243 | levels[i] = null; 4244 | } 4245 | 4246 | for (int i = 0; i < levelDepths.Length; i++) 4247 | { 4248 | levelDepths[i] = 0; 4249 | } 4250 | } 4251 | } 4252 | 4253 | public static void update(int updateLevel) 4254 | { 4255 | if (isGUIEnabled) 4256 | { 4257 | init(); 4258 | if (levelDepths[updateLevel] > 0) 4259 | { 4260 | color = GUI.color; 4261 | int baseI = updateLevel * RECTS_PER_LEVEL; 4262 | int maxLoop = baseI + levelDepths[updateLevel];// RECTS_PER_LEVEL;//; 4263 | 4264 | for (int i = baseI; i < maxLoop; i++) 4265 | { 4266 | r = levels[i]; 4267 | //Debug.Log("r:"+r+" i:"+i); 4268 | if (r != null /*&& checkOnScreen(r.rect)*/) 4269 | { 4270 | //Debug.Log("label:"+r.labelStr+" textColor:"+r.style.normal.textColor); 4271 | if (r.useColor) 4272 | GUI.color = r.color; 4273 | if (r.type == Element_Type.Label) 4274 | { 4275 | if (r.style != null) 4276 | GUI.skin.label = r.style; 4277 | if (r.useSimpleScale) 4278 | { 4279 | GUI.Label(new Rect((r.rect.x + r.margin.x + r.relativeRect.x) * r.relativeRect.width, (r.rect.y + r.margin.y + r.relativeRect.y) * r.relativeRect.height, r.rect.width * r.relativeRect.width, r.rect.height * r.relativeRect.height), r.labelStr); 4280 | } 4281 | else 4282 | { 4283 | GUI.Label(new Rect(r.rect.x + r.margin.x, r.rect.y + r.margin.y, r.rect.width, r.rect.height), r.labelStr); 4284 | } 4285 | } 4286 | else if (r.type == Element_Type.Texture && r.texture != null) 4287 | { 4288 | Vector2 size = r.useSimpleScale ? new Vector2(0f, r.rect.height * r.relativeRect.height) : new Vector2(r.rect.width, r.rect.height); 4289 | if (r.sizeByHeight) 4290 | { 4291 | size.x = (float)r.texture.width / (float)r.texture.height * size.y; 4292 | } 4293 | if (r.useSimpleScale) 4294 | { 4295 | GUI.DrawTexture(new Rect((r.rect.x + r.margin.x + r.relativeRect.x) * r.relativeRect.width, (r.rect.y + r.margin.y + r.relativeRect.y) * r.relativeRect.height, size.x, size.y), r.texture); 4296 | } 4297 | else 4298 | { 4299 | GUI.DrawTexture(new Rect(r.rect.x + r.margin.x, r.rect.y + r.margin.y, size.x, size.y), r.texture); 4300 | } 4301 | } 4302 | } 4303 | } 4304 | GUI.color = color; 4305 | } 4306 | } 4307 | } 4308 | 4309 | public static bool checkOnScreen(Rect rect) 4310 | { 4311 | bool offLeft = rect.x + rect.width < 0f; 4312 | bool offRight = rect.x > Screen.width; 4313 | bool offBottom = rect.y > Screen.height; 4314 | bool offTop = rect.y + rect.height < 0f; 4315 | 4316 | return !(offLeft || offRight || offBottom || offTop); 4317 | } 4318 | 4319 | public static void destroy(int id) 4320 | { 4321 | int backId = id & 0xFFFF; 4322 | int backCounter = id >> 16; 4323 | if (id >= 0 && levels[backId] != null && levels[backId].hasInitiliazed && levels[backId].counter == backCounter) 4324 | levels[backId] = null; 4325 | } 4326 | 4327 | public static LTRect label(Rect rect, string label, int depth) 4328 | { 4329 | return LTGUI.label(new LTRect(rect), label, depth); 4330 | } 4331 | 4332 | public static LTRect label(LTRect rect, string label, int depth) 4333 | { 4334 | rect.type = Element_Type.Label; 4335 | rect.labelStr = label; 4336 | return element(rect, depth); 4337 | } 4338 | 4339 | public static LTRect texture(Rect rect, Texture texture, int depth) 4340 | { 4341 | return LTGUI.texture(new LTRect(rect), texture, depth); 4342 | } 4343 | 4344 | public static LTRect texture(LTRect rect, Texture texture, int depth) 4345 | { 4346 | rect.type = Element_Type.Texture; 4347 | rect.texture = texture; 4348 | return element(rect, depth); 4349 | } 4350 | 4351 | public static LTRect element(LTRect rect, int depth) 4352 | { 4353 | isGUIEnabled = true; 4354 | init(); 4355 | int maxLoop = depth * RECTS_PER_LEVEL + RECTS_PER_LEVEL; 4356 | int k = 0; 4357 | if (rect != null) 4358 | { 4359 | destroy(rect.id); 4360 | } 4361 | if (rect.type == LTGUI.Element_Type.Label && rect.style != null) 4362 | { 4363 | if (rect.style.normal.textColor.a <= 0f) 4364 | { 4365 | Debug.LogWarning("Your GUI normal color has an alpha of zero, and will not be rendered."); 4366 | } 4367 | } 4368 | for (int i = depth * RECTS_PER_LEVEL; i < maxLoop; i++) 4369 | { 4370 | r = levels[i]; 4371 | if (r == null) 4372 | { 4373 | r = rect; 4374 | r.rotateEnabled = true; 4375 | r.alphaEnabled = true; 4376 | r.setId(i, global_counter); 4377 | levels[i] = r; 4378 | // Debug.Log("k:"+k+ " maxDepth:"+levelDepths[depth]); 4379 | if (k >= levelDepths[depth]) 4380 | { 4381 | levelDepths[depth] = k + 1; 4382 | } 4383 | global_counter++; 4384 | return r; 4385 | } 4386 | k++; 4387 | } 4388 | 4389 | Debug.LogError("You ran out of GUI Element spaces"); 4390 | 4391 | return null; 4392 | } 4393 | 4394 | public static bool hasNoOverlap(Rect rect, int depth) 4395 | { 4396 | initRectCheck(); 4397 | bool hasNoOverlap = true; 4398 | bool wasAddedToList = false; 4399 | for (int i = 0; i < buttonLevels.Length; i++) 4400 | { 4401 | // Debug.Log("buttonLastFrame["+i+"]:"+buttonLastFrame[i]); 4402 | //Debug.Log("buttonLevels["+i+"]:"+buttonLevels[i]); 4403 | if (buttonLevels[i] >= 0) 4404 | { 4405 | //Debug.Log("buttonLastFrame["+i+"]:"+buttonLastFrame[i]+" Time.frameCount:"+Time.frameCount); 4406 | if (buttonLastFrame[i] + 1 < Time.frameCount) 4407 | { // It has to have been visible within the current, or 4408 | buttonLevels[i] = -1; 4409 | // Debug.Log("resetting i:"+i); 4410 | } 4411 | else 4412 | { 4413 | //if(buttonLevels[i]>=0) 4414 | // Debug.Log("buttonLevels["+i+"]:"+buttonLevels[i]); 4415 | if (buttonLevels[i] > depth) 4416 | { 4417 | /*if(firstTouch().x > 0){ 4418 | Debug.Log("buttons["+i+"]:"+buttons[i] + " firstTouch:"); 4419 | Debug.Log(firstTouch()); 4420 | Debug.Log(buttonLevels[i]); 4421 | }*/ 4422 | if (pressedWithinRect(buttons[i])) 4423 | { 4424 | hasNoOverlap = false; // there is an overlapping button that is higher 4425 | } 4426 | } 4427 | } 4428 | } 4429 | 4430 | if (wasAddedToList == false && buttonLevels[i] < 0) 4431 | { 4432 | wasAddedToList = true; 4433 | buttonLevels[i] = depth; 4434 | buttons[i] = rect; 4435 | buttonLastFrame[i] = Time.frameCount; 4436 | } 4437 | } 4438 | 4439 | return hasNoOverlap; 4440 | } 4441 | 4442 | public static bool pressedWithinRect(Rect rect) 4443 | { 4444 | Vector2 vec2 = firstTouch(); 4445 | if (vec2.x < 0f) 4446 | return false; 4447 | float vecY = Screen.height - vec2.y; 4448 | return (vec2.x > rect.x && vec2.x < rect.x + rect.width && vecY > rect.y && vecY < rect.y + rect.height); 4449 | } 4450 | 4451 | public static bool checkWithinRect(Vector2 vec2, Rect rect) 4452 | { 4453 | vec2.y = Screen.height - vec2.y; 4454 | return (vec2.x > rect.x && vec2.x < rect.x + rect.width && vec2.y > rect.y && vec2.y < rect.y + rect.height); 4455 | } 4456 | 4457 | public static Vector2 firstTouch() 4458 | { 4459 | if (Input.touchCount > 0) 4460 | { 4461 | return Input.touches[0].position; 4462 | } 4463 | else if (Input.GetMouseButton(0)) 4464 | { 4465 | return Input.mousePosition; 4466 | } 4467 | 4468 | return new Vector2(Mathf.NegativeInfinity, Mathf.NegativeInfinity); 4469 | } 4470 | } 4471 | -------------------------------------------------------------------------------- /Assets/LeanTween/LeanTween.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: adf04ad9870a53f4da324d5da5302991 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/TouchScript.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9265a2bc5e2be1e4ebdf19cb593ecb85 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/TouchScript/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f436f518569eeab46ac01cdaaac3b02f 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/TouchScript/Editor/TouchScript.Editor.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/Assets/TouchScript/Editor/TouchScript.Editor.dll -------------------------------------------------------------------------------- /Assets/TouchScript/Editor/TouchScript.Editor.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa83d1ea05edf8748af6cae5aed422e4 3 | MonoAssemblyImporter: 4 | serializedVersion: 1 5 | iconMap: {} 6 | executionOrder: {} 7 | userData: 8 | -------------------------------------------------------------------------------- /Assets/TouchScript/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c0399605434412489023ed07eb471c6 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/TouchScript/Plugins/TouchScript.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/Assets/TouchScript/Plugins/TouchScript.dll -------------------------------------------------------------------------------- /Assets/TouchScript/Plugins/TouchScript.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20c2a163775f09b4cafa29b19d0c9204 3 | MonoAssemblyImporter: 4 | serializedVersion: 1 5 | iconMap: {} 6 | executionOrder: 7 | TouchScript.GestureManager: -900 8 | TouchScript.InputSources.MobileInput: -1110 9 | TouchScript.InputSources.MouseInput: -1100 10 | TouchScript.InputSources.TuioInput: -1002 11 | TouchScript.InputSources.WMTouchInput: -1001 12 | TouchScript.InputSources.Win7TouchInput: -1002 13 | TouchScript.TouchManager: -1000 14 | userData: 15 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakkarage/Unity3D-CoverFlow/d1a46176ad7df8d353a00ae350f3d58c789eb764/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Unity3D-CoverFlow 2 | ================= 3 | 4 | A simple CoverFlow example using LeanTween & TouchScript 5 | --------------------------------------------------------------------------------