| @@ -0,0 +1,60 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralAdvancedTechniques : MonoBehaviour { | ||
|
|
||
| public GameObject avatarRecursive; | ||
| public GameObject avatar2dRecursive; | ||
| public RectTransform wingPersonPanel; | ||
| public RectTransform textField; | ||
|
|
||
| public GameObject avatarMove; | ||
| public Transform[] movePts; | ||
| public GameObject[] avatarSpeed; | ||
| public GameObject[] avatarSpeed2; | ||
|
|
||
| private Vector3[] circleSm = new Vector3[]{ new Vector3(16f,0f,0f), new Vector3(14.56907f,8.009418f,0f), new Vector3(15.96541f,4.638379f,0f), new Vector3(11.31371f,11.31371f,0f), new Vector3(11.31371f,11.31371f,0f), new Vector3(4.638379f,15.96541f,0f), new Vector3(8.009416f,14.56908f,0f), new Vector3(-6.993822E-07f,16f,0f), new Vector3(-6.993822E-07f,16f,0f), new Vector3(-8.009419f,14.56907f,0f), new Vector3(-4.63838f,15.9654f,0f), new Vector3(-11.31371f,11.31371f,0f), new Vector3(-11.31371f,11.31371f,0f), new Vector3(-15.9654f,4.63838f,0f), new Vector3(-14.56908f,8.009415f,0f), new Vector3(-16f,-1.398764E-06f,0f), new Vector3(-16f,-1.398764E-06f,0f), new Vector3(-14.56907f,-8.009418f,0f), new Vector3(-15.9654f,-4.638382f,0f), new Vector3(-11.31371f,-11.31371f,0f), new Vector3(-11.31371f,-11.31371f,0f), new Vector3(-4.638381f,-15.9654f,0f), new Vector3(-8.009413f,-14.56908f,0f), new Vector3(1.907981E-07f,-16f,0f), new Vector3(1.907981E-07f,-16f,0f), new Vector3(8.00942f,-14.56907f,0f), new Vector3(4.638381f,-15.9654f,0f), new Vector3(11.31371f,-11.3137f,0f), new Vector3(11.31371f,-11.3137f,0f), new Vector3(15.96541f,-4.638378f,0f), new Vector3(14.56907f,-8.009418f,0f), new Vector3(16f,2.797529E-06f,0f) }; | ||
| private Vector3[] circleLrg = new Vector3[]{ new Vector3(25f,0f,0f), new Vector3(22.76418f,12.51472f,0f), new Vector3(24.94595f,7.247467f,0f), new Vector3(17.67767f,17.67767f,0f), new Vector3(17.67767f,17.67767f,0f), new Vector3(7.247467f,24.94595f,0f), new Vector3(12.51471f,22.76418f,0f), new Vector3(-1.092785E-06f,25f,0f), new Vector3(-1.092785E-06f,25f,0f), new Vector3(-12.51472f,22.76418f,0f), new Vector3(-7.247468f,24.94594f,0f), new Vector3(-17.67767f,17.67767f,0f), new Vector3(-17.67767f,17.67767f,0f), new Vector3(-24.94594f,7.247468f,0f), new Vector3(-22.76418f,12.51471f,0f), new Vector3(-25f,-2.185569E-06f,0f), new Vector3(-25f,-2.185569E-06f,0f), new Vector3(-22.76418f,-12.51472f,0f), new Vector3(-24.94594f,-7.247472f,0f), new Vector3(-17.67767f,-17.67767f,0f), new Vector3(-17.67767f,-17.67767f,0f), new Vector3(-7.247469f,-24.94594f,0f), new Vector3(-12.51471f,-22.76418f,0f), new Vector3(2.98122E-07f,-25f,0f), new Vector3(2.98122E-07f,-25f,0f), new Vector3(12.51472f,-22.76418f,0f), new Vector3(7.24747f,-24.94594f,0f), new Vector3(17.67768f,-17.67766f,0f), new Vector3(17.67768f,-17.67766f,0f), new Vector3(24.94595f,-7.247465f,0f), new Vector3(22.76418f,-12.51472f,0f), new Vector3(25f,4.371139E-06f,0f) }; | ||
|
|
||
| // Use this for initialization | ||
| void Start () { | ||
| // Recursion - Set a objects value and have it recursively effect it's children | ||
| LeanTween.alpha( avatarRecursive, 0f, 1f).setRecursive(true).setLoopPingPong(); | ||
| LeanTween.alpha( avatar2dRecursive, 0f, 1f).setRecursive(true).setLoopPingPong(); | ||
| LeanTween.alpha( wingPersonPanel, 0f, 1f).setRecursive(true).setLoopPingPong(); | ||
|
|
||
| // Destroy on Complete - | ||
|
|
||
| // Chaining tweens together | ||
|
|
||
| // setOnCompleteOnRepeat | ||
|
|
||
|
|
||
| // Move to path of transforms that are moving themselves | ||
| LeanTween.value( avatarMove, 0f, (float)movePts.Length-1, 5f).setOnUpdate((float val)=>{ | ||
| int first = (int)Mathf.Floor(val); | ||
| int next = first < movePts.Length-1 ? first + 1 : first; | ||
| float diff = val - (float)first; | ||
| // Debug.Log("val:"+val+" first:"+first+" next:"+next); | ||
| Vector3 diffPos = (movePts[next].position-movePts[first].position); | ||
| avatarMove.transform.position = movePts[first].position + diffPos*diff; | ||
| }).setEase(LeanTweenType.easeInOutExpo).setLoopPingPong(); | ||
|
|
||
| // move the pts | ||
| for(int i = 0; i < movePts.Length; i++) | ||
| LeanTween.moveY( movePts[i].gameObject, movePts[i].position.y + 1.5f, 1f).setDelay(((float)i)*0.2f).setLoopPingPong(); | ||
|
|
||
|
|
||
| // move objects at a constant speed | ||
| for(int i = 0; i < avatarSpeed.Length; i++) | ||
| LeanTween.moveLocalZ( avatarSpeed[i], (i+1)*5f, 1f).setSpeed(6f).setEase(LeanTweenType.easeInOutExpo).setLoopPingPong(); // any time you set the speed it overrides the time value | ||
|
|
||
| // move around a circle at a constant speed | ||
| for(int i = 0; i < avatarSpeed2.Length; i++){ | ||
| LeanTween.moveLocal( avatarSpeed2[i], i == 0 ? circleSm : circleLrg, 1f).setSpeed(20f).setRepeat(-1); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,82 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralBasicCS : MonoBehaviour { | ||
|
|
||
| public GameObject prefabAvatar; | ||
|
|
||
| void Start () { | ||
| // Setup | ||
| GameObject avatarRotate = GameObject.Find("AvatarRotate"); | ||
| GameObject avatarScale = GameObject.Find("AvatarScale"); | ||
| GameObject avatarMove = GameObject.Find("AvatarMove"); | ||
|
|
||
| // Rotate Example | ||
| LeanTween.rotateAround( avatarRotate, Vector3.forward, 360f, 5f); | ||
|
|
||
| // Scale Example | ||
| LeanTween.scale( avatarScale, new Vector3(1.7f, 1.7f, 1.7f), 5f).setEase(LeanTweenType.easeOutBounce); | ||
| LeanTween.moveX( avatarScale, avatarScale.transform.position.x + 5f, 5f).setEase(LeanTweenType.easeOutBounce); // Simultaneously target many different tweens on the same object | ||
|
|
||
| // Move Example | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-9f, 0f, 1f), 2f).setEase(LeanTweenType.easeInQuad); | ||
|
|
||
| // Delay | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-6f, 0f, 1f), 2f).setDelay(3f); | ||
|
|
||
| // Chain properties (delay, easing with a set repeating of type ping pong) | ||
| LeanTween.scale( avatarScale, new Vector3(0.2f, 0.2f, 0.2f), 1f).setDelay(7f).setEase(LeanTweenType.easeInOutCirc).setLoopPingPong( 3 ); | ||
|
|
||
| // Call methods after a certain time period | ||
| LeanTween.delayedCall(gameObject, 0.2f, advancedExamples); | ||
| } | ||
|
|
||
| // Advanced Examples | ||
| // It might be best to master the basics first, but this is included to tease the many possibilies LeanTween provides. | ||
|
|
||
| void advancedExamples(){ | ||
| LeanTween.delayedCall(gameObject, 14f, ()=>{ | ||
| for(int i=0; i < 10; i++){ | ||
| // Instantiate Container | ||
| GameObject rotator = new GameObject("rotator"+i); | ||
| rotator.transform.position = new Vector3(10.2f,2.85f,0f); | ||
|
|
||
| // Instantiate Avatar | ||
| GameObject dude = (GameObject)GameObject.Instantiate(prefabAvatar, Vector3.zero, prefabAvatar.transform.rotation ); | ||
| dude.transform.parent = rotator.transform; | ||
| dude.transform.localPosition = new Vector3(0f,1.5f,2.5f*i); | ||
|
|
||
| // Scale, pop-in | ||
| dude.transform.localScale = new Vector3(0f,0f,0f); | ||
| LeanTween.scale(dude, new Vector3(0.65f,0.65f,0.65f), 1f).setDelay(i*0.2f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| // Color like the rainbow | ||
| float period = LeanTween.tau/10*i; | ||
| float red = Mathf.Sin(period + LeanTween.tau*0f/3f) * 0.5f + 0.5f; | ||
| float green = Mathf.Sin(period + LeanTween.tau*1f/3f) * 0.5f + 0.5f; | ||
| float blue = Mathf.Sin(period + LeanTween.tau*2f/3f) * 0.5f + 0.5f; | ||
| Color rainbowColor = new Color(red, green, blue); | ||
| LeanTween.color(dude, rainbowColor, 0.3f).setDelay(1.2f + i*0.4f); | ||
|
|
||
| // Push into the wheel | ||
| LeanTween.moveZ(dude, 0f, 0.3f).setDelay(1.2f + i*0.4f).setEase(LeanTweenType.easeSpring).setOnComplete( | ||
| ()=>{ | ||
| LeanTween.rotateAround(rotator, Vector3.forward, -1080f, 12f); | ||
| } | ||
| ); | ||
|
|
||
| // Jump Up and back down | ||
| LeanTween.moveLocalY(dude,4f,1.2f).setDelay(5f + i*0.2f).setLoopPingPong(1).setEase(LeanTweenType.easeInOutQuad); | ||
|
|
||
| // Alpha Out, and destroy | ||
| LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete( | ||
| ()=>{ | ||
| Destroy( rotator ); // destroying parent as well | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| }).setOnCompleteOnStart(true).setRepeat(-1); // Have the OnComplete play in the beginning and have the whole group repeat endlessly | ||
| } | ||
| } |
| @@ -0,0 +1,78 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| public var prefabAvatar:GameObject; | ||
|
|
||
| function Start () { | ||
| // Setup | ||
| var avatarRotate:GameObject = GameObject.Find("AvatarRotate"); | ||
| var avatarScale:GameObject = GameObject.Find("AvatarScale"); | ||
| var avatarMove:GameObject = GameObject.Find("AvatarMove"); | ||
|
|
||
| // Rotate Example | ||
| LeanTween.rotateAround( avatarRotate, Vector3.forward, 360f, 5f); | ||
|
|
||
| // Scale Example | ||
| LeanTween.scale( avatarScale, new Vector3(1.7f, 1.7f, 1.7f), 5f).setEase(LeanTweenType.easeOutBounce); | ||
| LeanTween.moveX( avatarScale, avatarScale.transform.position.x + 5f, 5f).setEase(LeanTweenType.easeOutBounce); // Simultaneously target many different tweens on the same object | ||
|
|
||
| // Move Example | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-9f, 0f, 1f), 2f).setEase(LeanTweenType.easeInQuad); | ||
|
|
||
| // Delay | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-6f, 0f, 1f), 2f).setDelay(3f); | ||
|
|
||
| // Chain properties (delay, easing with a set repeating of type ping pong) | ||
| LeanTween.scale( avatarScale, new Vector3(0.2f, 0.2f, 0.2f), 1f).setDelay(7f).setEase(LeanTweenType.easeInOutCirc).setRepeat(5).setLoopPingPong(); | ||
|
|
||
| // Call methods after a certain time period | ||
| LeanTween.delayedCall(gameObject, 0.2f, advancedExamples); | ||
| } | ||
|
|
||
| // Advanced Examples | ||
| // It might be best to master the basics first, but this is included to tease the many possibilies LeanTween provides. | ||
|
|
||
| function advancedExamples(){ | ||
| LeanTween.delayedCall(gameObject, 14f, function(){ | ||
| for(var i:int=0; i < 10; i++){ | ||
| // Instantiate Container | ||
| var rotator:GameObject = new GameObject("rotator"+i); | ||
| rotator.transform.position = new Vector3(10.2f,2.85f,0f); | ||
|
|
||
| // Instantiate Avatar | ||
| var dude:GameObject = GameObject.Instantiate(prefabAvatar, Vector3.zero, prefabAvatar.transform.rotation ) as GameObject; | ||
| dude.transform.parent = rotator.transform; | ||
| dude.transform.localPosition = new Vector3(0f,1.5f,2.5f*i); | ||
|
|
||
| // Scale, pop-in | ||
| dude.transform.localScale = new Vector3(0f,0f,0f); | ||
| LeanTween.scale(dude, new Vector3(0.65f,0.65f,0.65f), 1f).setDelay(i*0.2f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| // Color like the rainbow | ||
| var period:float = LeanTween.tau/10*i; | ||
| var red:float = Mathf.Sin(period + LeanTween.tau*0f/3f) * 0.5f + 0.5f; | ||
| var green:float = Mathf.Sin(period + LeanTween.tau*1f/3f) * 0.5f + 0.5f; | ||
| var blue:float = Mathf.Sin(period + LeanTween.tau*2f/3f) * 0.5f + 0.5f; | ||
| var rainbowColor:Color = new Color(red, green, blue); | ||
| LeanTween.color(dude, rainbowColor, 0.3f).setDelay(1.2f + i*0.4f); | ||
|
|
||
| // Push into the wheel | ||
| LeanTween.moveZ(dude, 0f, 0.3f).setDelay(1.2f + i*0.4f).setEase(LeanTweenType.easeSpring).setOnComplete( | ||
| function( rot:GameObject ){ | ||
| LeanTween.rotateAround(rot, Vector3.forward, -1080f, 12f); | ||
| } | ||
| ).setOnCompleteParam( rotator ); | ||
|
|
||
| // Jump Up and back down | ||
| LeanTween.moveLocalY(dude,4f,1.2f).setDelay(5f + i*0.2f).setLoopPingPong().setRepeat(2).setEase(LeanTweenType.easeInOutQuad); | ||
|
|
||
| // Alpha Out, and destroy | ||
| LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete( | ||
| function(rot:GameObject){ | ||
| Destroy( rot ); // destroying parent as well | ||
| } | ||
| ).setOnCompleteParam( rotator ); | ||
| } | ||
|
|
||
| }).setOnCompleteOnStart(true).setRepeat(-1); // Have the OnComplete play in the beginning and have the whole group repeat endlessly | ||
| } |
| @@ -0,0 +1,102 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralBasics2dCS : MonoBehaviour { | ||
|
|
||
| public Texture2D dudeTexture; | ||
| public GameObject prefabParticles; | ||
|
|
||
| #if !(UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2) | ||
|
|
||
| void Start () { | ||
| // Setup | ||
| GameObject avatarRotate = createSpriteDude( "avatarRotate", new Vector3(-2.51208f,10.7119f,-14.37754f)); | ||
| GameObject avatarScale = createSpriteDude( "avatarScale", new Vector3(2.51208f,10.2119f,-14.37754f)); | ||
| GameObject avatarMove = createSpriteDude( "avatarMove", new Vector3(-3.1208f,7.100643f,-14.37754f)); | ||
|
|
||
| // Rotate Example | ||
| LeanTween.rotateAround( avatarRotate, Vector3.forward, -360f, 5f); | ||
|
|
||
| // Scale Example | ||
| LeanTween.scale( avatarScale, new Vector3(1.7f, 1.7f, 1.7f), 5f).setEase(LeanTweenType.easeOutBounce); | ||
| LeanTween.moveX( avatarScale, avatarScale.transform.position.x + 1f, 5f).setEase(LeanTweenType.easeOutBounce); // Simultaneously target many different tweens on the same object | ||
|
|
||
| // Move Example | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(1.7f, 0f, 0f), 2f).setEase(LeanTweenType.easeInQuad); | ||
|
|
||
| // Delay | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(2f, -1f, 0f), 2f).setDelay(3f); | ||
|
|
||
| // Chain properties (delay, easing with a set repeating of type ping pong) | ||
| LeanTween.scale( avatarScale, new Vector3(0.2f, 0.2f, 0.2f), 1f).setDelay(7f).setEase(LeanTweenType.easeInOutCirc).setLoopPingPong(3); | ||
|
|
||
| // Call methods after a certain time period | ||
| LeanTween.delayedCall(gameObject, 0.2f, advancedExamples); | ||
| } | ||
|
|
||
| GameObject createSpriteDude( string name, Vector3 pos, bool hasParticles = true ){ | ||
| GameObject go = new GameObject(name); | ||
| SpriteRenderer ren = go.AddComponent<SpriteRenderer>(); | ||
| go.GetComponent<SpriteRenderer>().color = new Color(0f,181f/255f,1f); | ||
| ren.sprite = Sprite.Create( dudeTexture, new Rect(0.0f,0.0f,256.0f,256.0f), new Vector2(0.5f,0f), 256f); | ||
| go.transform.position = pos; | ||
|
|
||
| if(hasParticles){ | ||
| GameObject particles = (GameObject)GameObject.Instantiate(prefabParticles, Vector3.zero, prefabParticles.transform.rotation ); | ||
| particles.transform.parent = go.transform; | ||
| particles.transform.localPosition = prefabParticles.transform.position; | ||
| } | ||
| return go; | ||
| } | ||
|
|
||
| // Advanced Examples | ||
| // It might be best to master the basics first, but this is included to tease the many possibilies LeanTween provides. | ||
|
|
||
| void advancedExamples(){ | ||
| LeanTween.delayedCall(gameObject, 14f, ()=>{ | ||
| for(int i=0; i < 10; i++){ | ||
| // Instantiate Container | ||
| GameObject rotator = new GameObject("rotator"+i); | ||
| rotator.transform.position = new Vector3(2.71208f,7.100643f,-12.37754f); | ||
|
|
||
| // Instantiate Avatar | ||
| GameObject dude = createSpriteDude( "dude"+i, new Vector3(-2.51208f,7.100643f,-14.37754f), false);//(GameObject)GameObject.Instantiate(prefabAvatar, Vector3.zero, prefabAvatar.transform.rotation ); | ||
| dude.transform.parent = rotator.transform; | ||
| dude.transform.localPosition = new Vector3(0f,0.5f,0.5f*i); | ||
|
|
||
| // Scale, pop-in | ||
| dude.transform.localScale = new Vector3(0f,0f,0f); | ||
| LeanTween.scale(dude, new Vector3(0.65f,0.65f,0.65f), 1f).setDelay(i*0.2f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| // Color like the rainbow | ||
| float period = LeanTween.tau/10*i; | ||
| float red = Mathf.Sin(period + LeanTween.tau*0f/3f) * 0.5f + 0.5f; | ||
| float green = Mathf.Sin(period + LeanTween.tau*1f/3f) * 0.5f + 0.5f; | ||
| float blue = Mathf.Sin(period + LeanTween.tau*2f/3f) * 0.5f + 0.5f; | ||
| Color rainbowColor = new Color(red, green, blue); | ||
| LeanTween.color(dude, rainbowColor, 0.3f).setDelay(1.2f + i*0.4f); | ||
|
|
||
| // Push into the wheel | ||
| LeanTween.moveLocalZ(dude, -2f, 0.3f).setDelay(1.2f + i*0.4f).setEase(LeanTweenType.easeSpring).setOnComplete( | ||
| ()=>{ | ||
| LeanTween.rotateAround(rotator, Vector3.forward, -1080f, 12f); | ||
| } | ||
| ); | ||
|
|
||
| // Jump Up and back down | ||
| LeanTween.moveLocalY(dude,1.17f,1.2f).setDelay(5f + i*0.2f).setLoopPingPong(1).setEase(LeanTweenType.easeInOutQuad); | ||
|
|
||
| // Alpha Out, and destroy | ||
| LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete( | ||
| ()=>{ | ||
| Destroy( rotator ); // destroying parent as well | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| }).setOnCompleteOnStart(true).setRepeat(-1); // Have the OnComplete play in the beginning and have the whole group repeat endlessly | ||
| } | ||
|
|
||
| #endif | ||
| } |
| @@ -0,0 +1,98 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| public var dudeTexture:Texture2D; | ||
| public var prefabParticles:GameObject; | ||
|
|
||
| #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 | ||
|
|
||
| function Start () { | ||
| // Setup | ||
| var avatarRotate:GameObject = createSpriteDude( "avatarRotate", new Vector3(-2.51208f,10.7119f,-14.37754f), true); | ||
| var avatarScale:GameObject = createSpriteDude( "avatarScale", new Vector3(2.51208f,10.2119f,-14.37754f), true); | ||
| var avatarMove:GameObject = createSpriteDude( "avatarMove", new Vector3(-3.1208f,7.100643f,-14.37754f), true); | ||
|
|
||
| // Rotate Example | ||
| LeanTween.rotateAround( avatarRotate, Vector3.forward, -360f, 5f); | ||
|
|
||
| // Scale Example | ||
| LeanTween.scale( avatarScale, new Vector3(1.7f, 1.7f, 1.7f), 5f).setEase(LeanTweenType.easeOutBounce); | ||
| LeanTween.moveX( avatarScale, avatarScale.transform.position.x + 1f, 5f).setEase(LeanTweenType.easeOutBounce); // Simultaneously target many different tweens on the same object | ||
|
|
||
| // Move Example | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(1.7f, 0f, 0f), 2f).setEase(LeanTweenType.easeInQuad); | ||
|
|
||
| // Delay | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(2f, -1f, 0f), 2f).setDelay(3f); | ||
|
|
||
| // Chain properties (delay, easing with a set repeating of type ping pong) | ||
| LeanTween.scale( avatarScale, new Vector3(0.2f, 0.2f, 0.2f), 1f).setDelay(7f).setEase(LeanTweenType.easeInOutCirc).setRepeat(5).setLoopPingPong(); | ||
|
|
||
| // Call methods after a certain time period | ||
| LeanTween.delayedCall(gameObject, 0.2f, advancedExamples); | ||
| } | ||
|
|
||
| function createSpriteDude( name:String, pos:Vector3, hasParticles:boolean ):GameObject{ | ||
| var go:GameObject = new GameObject(name); | ||
| var ren:SpriteRenderer = go.AddComponent(SpriteRenderer); | ||
| go.GetComponent.<Renderer>().material.color = new Color(0f,181f/255f,1f); | ||
| ren.sprite = Sprite.Create( dudeTexture, new Rect(0.0f,0.0f,256.0f,256.0f), new Vector2(0.5f,0f), 256f); | ||
| go.transform.position = pos; | ||
|
|
||
| if(hasParticles){ | ||
| var particles:GameObject = GameObject.Instantiate(prefabParticles, Vector3.zero, prefabParticles.transform.rotation ) as GameObject; | ||
| particles.transform.parent = go.transform; | ||
| particles.transform.localPosition = prefabParticles.transform.position; | ||
| } | ||
| return go; | ||
| } | ||
|
|
||
| // Advanced Examples | ||
| // It might be best to master the basics first, but this is included to tease the many possibilies LeanTween provides. | ||
|
|
||
| function advancedExamples(){ | ||
| LeanTween.delayedCall(gameObject, 14f, function(){ | ||
| for(var i:int=0; i < 10; i++){ | ||
| // Instantiate Container | ||
| var rotator:GameObject = new GameObject("rotator"+i); | ||
| rotator.transform.position = new Vector3(2.71208f,7.100643f,-12.37754f); | ||
|
|
||
| // Instantiate Avatar | ||
| var dude:GameObject = createSpriteDude( "dude"+i, new Vector3(-2.51208f,7.100643f,-14.37754f), false);//(GameObject)GameObject.Instantiate(prefabAvatar, Vector3.zero, prefabAvatar.transform.rotation ); | ||
| dude.transform.parent = rotator.transform; | ||
| dude.transform.localPosition = new Vector3(0f,0.5f,0.5f*i); | ||
|
|
||
| // Scale, pop-in | ||
| dude.transform.localScale = new Vector3(0f,0f,0f); | ||
| LeanTween.scale(dude, new Vector3(0.65f,0.65f,0.65f), 1f).setDelay(i*0.2f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| // Color like the rainbow | ||
| var period:float = LeanTween.tau/10*i; | ||
| var red:float = Mathf.Sin(period + LeanTween.tau*0f/3f) * 0.5f + 0.5f; | ||
| var green:float = Mathf.Sin(period + LeanTween.tau*1f/3f) * 0.5f + 0.5f; | ||
| var blue:float = Mathf.Sin(period + LeanTween.tau*2f/3f) * 0.5f + 0.5f; | ||
| var rainbowColor:Color = new Color(red, green, blue); | ||
| LeanTween.color(dude, rainbowColor, 0.3f).setDelay(1.2f + i*0.4f); | ||
|
|
||
| // Push into the wheel | ||
| LeanTween.moveLocalZ(dude, -2f, 0.3f).setDelay(1.2f + i*0.4f).setEase(LeanTweenType.easeSpring).setOnComplete( | ||
| function( rot:GameObject ){ | ||
| LeanTween.rotateAround(rot, Vector3.forward, -1080f, 12f); | ||
| } | ||
| ).setOnCompleteParam( rotator ); | ||
|
|
||
| // Jump Up and back down | ||
| LeanTween.moveLocalY(dude,1.17f,1.2f).setDelay(5f + i*0.2f).setLoopPingPong(1).setEase(LeanTweenType.easeInOutQuad); | ||
|
|
||
| // Alpha Out, and destroy | ||
| LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete( | ||
| function(rot:GameObject){ | ||
| Destroy( rot ); // destroying parent as well | ||
| } | ||
| ).setOnCompleteParam( rotator );; | ||
| } | ||
|
|
||
| }).setOnCompleteOnStart(true).setRepeat(-1); // Have the OnComplete play in the beginning and have the whole group repeat endlessly | ||
| } | ||
|
|
||
| #endif |
| @@ -0,0 +1,78 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| public var prefabAvatar:GameObject; | ||
|
|
||
| function Start () { | ||
| // Setup | ||
| var avatarRotate:GameObject = GameObject.Find("AvatarRotate"); | ||
| var avatarScale:GameObject = GameObject.Find("AvatarScale"); | ||
| var avatarMove:GameObject = GameObject.Find("AvatarMove"); | ||
|
|
||
| // Rotate Example | ||
| LeanTween.rotateAround( avatarRotate, Vector3.forward, 360f, 5f); | ||
|
|
||
| // Scale Example | ||
| LeanTween.scale( avatarScale, new Vector3(1.7f, 1.7f, 1.7f), 5f).setEase(LeanTweenType.easeOutBounce); | ||
| LeanTween.moveX( avatarScale, avatarScale.transform.position.x + 5f, 5f).setEase(LeanTweenType.easeOutBounce); // Simultaneously target many different tweens on the same object | ||
|
|
||
| // Move Example | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-9f, 0f, 1f), 2f).setEase(LeanTweenType.easeInQuad); | ||
|
|
||
| // Delay | ||
| LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-6f, 0f, 1f), 2f).setDelay(3f); | ||
|
|
||
| // Chain properties (delay, easing with a set repeating of type ping pong) | ||
| LeanTween.scale( avatarScale, new Vector3(0.2f, 0.2f, 0.2f), 1f).setDelay(7f).setEase(LeanTweenType.easeInOutCirc).setRepeat(5).setLoopPingPong(); | ||
|
|
||
| // Call methods after a certain time period | ||
| LeanTween.delayedCall(gameObject, 0.2f, advancedExamples); | ||
| } | ||
|
|
||
| // Advanced Examples | ||
| // It might be best to master the basics first, but this is included to tease the many possibilies LeanTween provides. | ||
|
|
||
| function advancedExamples(){ | ||
| LeanTween.delayedCall(gameObject, 14f, function(){ | ||
| for(var i:int=0; i < 10; i++){ | ||
| // Instantiate Container | ||
| var rotator:GameObject = new GameObject("rotator"+i); | ||
| rotator.transform.position = new Vector3(10.2f,2.85f,0f); | ||
|
|
||
| // Instantiate Avatar | ||
| var dude:GameObject = GameObject.Instantiate(prefabAvatar, Vector3.zero, prefabAvatar.transform.rotation ) as GameObject; | ||
| dude.transform.parent = rotator.transform; | ||
| dude.transform.localPosition = new Vector3(0f,1.5f,2.5f*i); | ||
|
|
||
| // Scale, pop-in | ||
| dude.transform.localScale = new Vector3(0f,0f,0f); | ||
| LeanTween.scale(dude, new Vector3(0.65f,0.65f,0.65f), 1f).setDelay(i*0.2f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| // Color like the rainbow | ||
| var period:float = LeanTween.tau/10*i; | ||
| var red:float = Mathf.Sin(period + LeanTween.tau*0f/3f) * 0.5f + 0.5f; | ||
| var green:float = Mathf.Sin(period + LeanTween.tau*1f/3f) * 0.5f + 0.5f; | ||
| var blue:float = Mathf.Sin(period + LeanTween.tau*2f/3f) * 0.5f + 0.5f; | ||
| var rainbowColor:Color = new Color(red, green, blue); | ||
| LeanTween.color(dude, rainbowColor, 0.3f).setDelay(1.2f + i*0.4f); | ||
|
|
||
| // Push into the wheel | ||
| LeanTween.moveZ(dude, 0f, 0.3f).setDelay(1.2f + i*0.4f).setEase(LeanTweenType.easeSpring).setOnComplete( | ||
| function( rot:GameObject ){ | ||
| LeanTween.rotateAround(rot, Vector3.forward, -1080f, 12f); | ||
| } | ||
| ).setOnCompleteParam( rotator ); | ||
|
|
||
| // Jump Up and back down | ||
| LeanTween.moveLocalY(dude,4f,1.2f).setDelay(5f + i*0.2f).setLoopPingPong().setRepeat(2).setEase(LeanTweenType.easeInOutQuad); | ||
|
|
||
| // Alpha Out, and destroy | ||
| LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete( | ||
| function(rot:GameObject){ | ||
| Destroy( rot ); // destroying parent as well | ||
| } | ||
| ).setOnCompleteParam( rotator ); | ||
| } | ||
|
|
||
| }).setOnCompleteOnStart(true).setRepeat(-1); // Have the OnComplete play in the beginning and have the whole group repeat endlessly | ||
| } |
| @@ -0,0 +1,82 @@ | ||
| #if !UNITY_FLASH | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralCameraShake : MonoBehaviour { | ||
|
|
||
| private GameObject avatarBig; | ||
| private float jumpIter = 9.5f; | ||
| private AudioClip boomAudioClip; | ||
|
|
||
| // Use this for initialization | ||
| void Start () { | ||
| avatarBig = GameObject.Find("AvatarBig"); | ||
|
|
||
| AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(8.130963E-06f, 0.06526042f, 0f, -1f), new Keyframe(0.0007692695f, 2.449077f, 9.078861f, 9.078861f), new Keyframe(0.01541314f, 0.9343268f, -40f, -40f), new Keyframe(0.05169491f, 0.03835937f, -0.08621139f, -0.08621139f)); | ||
| AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003005181f, 0f, 0f), new Keyframe(0.01507768f, 0.002227979f, 0f, 0f)); | ||
| boomAudioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.1f,0f,0f)} )); | ||
|
|
||
|
|
||
| bigGuyJump(); | ||
| } | ||
|
|
||
| void bigGuyJump(){ | ||
| float height = Mathf.PerlinNoise(jumpIter, 0f)*10f; | ||
| height = height*height * 0.3f; | ||
| // Debug.Log("height:"+height+" jumpIter:"+jumpIter); | ||
|
|
||
| LeanTween.moveY(avatarBig, height, 1f).setEase(LeanTweenType.easeInOutQuad).setOnComplete( ()=>{ | ||
| LeanTween.moveY(avatarBig, 0f, 0.27f).setEase(LeanTweenType.easeInQuad).setOnComplete( ()=>{ | ||
| LeanTween.cancel(gameObject); | ||
|
|
||
| /************** | ||
| * Camera Shake | ||
| **************/ | ||
|
|
||
| float shakeAmt = height*0.2f; // the degrees to shake the camera | ||
| float shakePeriodTime = 0.42f; // The period of each shake | ||
| float dropOffTime = 1.6f; // How long it takes the shaking to settle down to nothing | ||
| LTDescr shakeTween = LeanTween.rotateAroundLocal( gameObject, Vector3.right, shakeAmt, shakePeriodTime) | ||
| .setEase( LeanTweenType.easeShake ) // this is a special ease that is good for shaking | ||
| .setLoopClamp() | ||
| .setRepeat(-1); | ||
|
|
||
| // Slow the camera shake down to zero | ||
| LeanTween.value(gameObject, shakeAmt, 0f, dropOffTime).setOnUpdate( | ||
| (float val)=>{ | ||
| shakeTween.setTo(Vector3.right*val); | ||
| } | ||
| ).setEase(LeanTweenType.easeOutQuad); | ||
|
|
||
|
|
||
| /******************** | ||
| * Shake scene objects | ||
| ********************/ | ||
|
|
||
| // Make the boxes jump from the big stomping | ||
| GameObject[] boxes = GameObject.FindGameObjectsWithTag("Respawn"); // I just arbitrarily tagged the boxes with this since it was available in the scene | ||
| foreach (GameObject box in boxes) { | ||
| box.GetComponent<Rigidbody>().AddForce(Vector3.up * 100 * height); | ||
| } | ||
|
|
||
| // Make the lamps spin from the big stomping | ||
| GameObject[] lamps = GameObject.FindGameObjectsWithTag("GameController"); // I just arbitrarily tagged the lamps with this since it was available in the scene | ||
| foreach (GameObject lamp in lamps) { | ||
| float z = lamp.transform.eulerAngles.z; | ||
| z = z > 0.0f && z < 180f ? 1 : -1; // push the lamps in whatever direction they are currently swinging | ||
| lamp.GetComponent<Rigidbody>().AddForce(new Vector3(z, 0f, 0f ) * 15 * height); | ||
| } | ||
|
|
||
| // Play BOOM! | ||
| LeanAudio.play(boomAudioClip, transform.position, height*0.2f); // Like this sound? : http://leanaudioplay.dentedpixel.com/?d=a:fvb:8,0,0.003005181,0,0,0.01507768,0.002227979,0,0,8~8,8.130963E-06,0.06526042,0,-1,0.0007692695,2.449077,9.078861,9.078861,0.01541314,0.9343268,-40,-40,0.05169491,0.03835937,-0.08621139,-0.08621139,8~0.1,0,0,~44100 | ||
|
|
||
| // Have the jump happen again 2 seconds from now | ||
| LeanTween.delayedCall(2f, bigGuyJump); | ||
| }); | ||
| }); | ||
| jumpIter += 5.2f; | ||
| } | ||
|
|
||
| } | ||
| #endif |
| @@ -0,0 +1,72 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System.Reflection; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralEasingTypes : MonoBehaviour { | ||
|
|
||
| public float lineDrawScale = 10f; | ||
| public AnimationCurve animationCurve; | ||
|
|
||
| private string[] easeTypes = new string[]{ | ||
| "EaseLinear","EaseAnimationCurve","EaseSpring", | ||
| "EaseInQuad","EaseOutQuad","EaseInOutQuad", | ||
| "EaseInCubic","EaseOutCubic","EaseInOutCubic", | ||
| "EaseInQuart","EaseOutQuart","EaseInOutQuart", | ||
| "EaseInQuint","EaseOutQuint","EaseInOutQuint", | ||
| "EaseInSine","EaseOutSine","EaseInOutSine", | ||
| "EaseInExpo","EaseOutExpo","EaseInOutExpo", | ||
| "EaseInCirc","EaseOutCirc","EaseInOutCirc", | ||
| "EaseInBounce","EaseOutBounce","EaseInOutBounce", | ||
| "EaseInBack","EaseOutBack","EaseInOutBack", | ||
| "EaseInElastic","EaseOutElastic","EaseInOutElastic", | ||
| "EasePunch","EaseShake", | ||
| }; | ||
|
|
||
| void Start () { | ||
|
|
||
| demoEaseTypes(); | ||
| } | ||
|
|
||
| private void demoEaseTypes(){ | ||
| for(int i = 0; i < easeTypes.Length; i++){ | ||
| string easeName = easeTypes[i]; | ||
| Transform obj1 = GameObject.Find(easeName).transform.Find("Line"); | ||
| float obj1val = 0f; | ||
| LTDescr lt = LeanTween.value( obj1.gameObject, 0f, 1f, 5f).setOnUpdate( (float val)=>{ | ||
| Vector3 vec = obj1.localPosition; | ||
| vec.x = obj1val*lineDrawScale; | ||
| vec.y = val*lineDrawScale; | ||
|
|
||
| obj1.localPosition = vec; | ||
|
|
||
| obj1val += Time.deltaTime/5f; | ||
| if(obj1val>1f) | ||
| obj1val = 0f; | ||
| }); | ||
| if(easeName.IndexOf("AnimationCurve")>=0){ | ||
| lt.setEase(animationCurve); | ||
| }else{ | ||
| MethodInfo theMethod = lt.GetType().GetMethod("set"+easeName); | ||
| theMethod.Invoke(lt, null); | ||
| } | ||
|
|
||
| if (easeName.IndexOf("EasePunch") >= 0) { | ||
| lt.setScale(1f); | ||
| } else if (easeName.IndexOf("EaseOutBounce") >= 0) { | ||
| lt.setOvershoot(2f); | ||
| } | ||
| } | ||
|
|
||
| LeanTween.delayedCall(gameObject, 10f, resetLines); | ||
| LeanTween.delayedCall(gameObject, 10.1f, demoEaseTypes); | ||
| } | ||
|
|
||
| private void resetLines(){ | ||
| for(int i = 0; i < easeTypes.Length; i++){ | ||
| Transform obj1 = GameObject.Find(easeTypes[i]).transform.Find("Line"); | ||
| obj1.localPosition = new Vector3(0f,0f,0f); | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,83 @@ | ||
| #if !UNITY_FLASH | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralEventsListenersCS : MonoBehaviour { | ||
|
|
||
| Vector3 towardsRotation; | ||
| float turnForLength = 0.5f; | ||
| float turnForIter = 0f; | ||
| Color fromColor; | ||
|
|
||
| // It's best to make this a public enum that you use throughout your project, so every class can have access to it | ||
| public enum MyEvents{ | ||
| CHANGE_COLOR, | ||
| JUMP, | ||
| LENGTH | ||
| } | ||
|
|
||
| void Awake(){ | ||
| LeanTween.LISTENERS_MAX = 100; // This is the maximum of event listeners you will have added as listeners | ||
| LeanTween.EVENTS_MAX = (int)MyEvents.LENGTH; // The maximum amount of events you will be dispatching | ||
|
|
||
| fromColor = GetComponent<Renderer>().material.color; | ||
| } | ||
|
|
||
| void Start () { | ||
| // Adding Listeners, it's best to use an enum so your listeners are more descriptive but you could use an int like 0,1,2,... | ||
| LeanTween.addListener(gameObject, (int)MyEvents.CHANGE_COLOR, changeColor); | ||
| LeanTween.addListener(gameObject, (int)MyEvents.JUMP, jumpUp); | ||
| } | ||
|
|
||
| // ****** Event Listening Methods | ||
|
|
||
| void jumpUp( LTEvent e ){ | ||
| GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * 300f); | ||
| } | ||
|
|
||
| void changeColor( LTEvent e ){ | ||
| Transform tran = (Transform)e.data; | ||
| float distance = Vector3.Distance( tran.position, transform.position); | ||
| Color to = new Color(Random.Range(0f,1f),0f,Random.Range(0f,1f)); | ||
| LeanTween.value( gameObject, fromColor, to, 0.8f ).setLoopPingPong(1).setDelay(distance*0.05f).setOnUpdate( | ||
| (Color col)=>{ | ||
| GetComponent<Renderer>().material.color = col; | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| // ****** Physics / AI Stuff | ||
|
|
||
| void OnCollisionEnter(Collision collision) { | ||
| if(collision.gameObject.layer!=2) | ||
| towardsRotation = new Vector3(0f, Random.Range(-180, 180), 0f); | ||
| } | ||
|
|
||
| void OnCollisionStay(Collision collision) { | ||
| if(collision.gameObject.layer!=2){ | ||
| turnForIter = 0f; | ||
| turnForLength = Random.Range(0.5f, 1.5f); | ||
| } | ||
| } | ||
|
|
||
| void FixedUpdate(){ | ||
| if(turnForIter < turnForLength){ | ||
| GetComponent<Rigidbody>().MoveRotation( GetComponent<Rigidbody>().rotation * Quaternion.Euler(towardsRotation * Time.deltaTime ) ); | ||
| turnForIter += Time.deltaTime; | ||
| } | ||
|
|
||
| GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * 4.5f); | ||
| } | ||
|
|
||
| // ****** Key and clicking detection | ||
|
|
||
| void OnMouseDown(){ | ||
| if(Input.GetKey( KeyCode.J )){ // Are you also pressing the "j" key while clicking | ||
| LeanTween.dispatchEvent((int)MyEvents.JUMP); | ||
| }else{ | ||
| LeanTween.dispatchEvent((int)MyEvents.CHANGE_COLOR, transform); // with every dispatched event, you can include an object (retrieve this object with the *.data var in LTEvent) | ||
| } | ||
| } | ||
| } | ||
| #endif |
| @@ -0,0 +1,77 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| private var towardsRotation:Vector3; | ||
| private var turnForLength:float = 0.5f; | ||
| private var turnForIter:float = 0f; | ||
| private var fromColor:Vector3; | ||
|
|
||
| // It's best to make this a public enum that you use throughout your project, so every class can have access to it | ||
| public enum MyEvents{ | ||
| CHANGE_COLOR, | ||
| JUMP, | ||
| LENGTH | ||
| } | ||
|
|
||
| function Awake(){ | ||
| LeanTween.LISTENERS_MAX = 100; // This is the maximum of event listeners you will have added as listeners | ||
| LeanTween.EVENTS_MAX = MyEvents.LENGTH; // The maximum amount of events you will be dispatching | ||
|
|
||
| fromColor = new Vector3(GetComponent.<Renderer>().material.color.r, GetComponent.<Renderer>().material.color.g, GetComponent.<Renderer>().material.color.b); | ||
| } | ||
|
|
||
| function Start () { | ||
| // Adding Listeners, it's best to use an enum so your listeners are more descriptive but you could use an int like 0,1,2,... | ||
| LeanTween.addListener(gameObject, MyEvents.CHANGE_COLOR, changeColor); | ||
| LeanTween.addListener(gameObject, MyEvents.JUMP, jumpUp); | ||
| } | ||
|
|
||
| // ****** Event Listening Methods | ||
|
|
||
| function jumpUp( e:LTEvent ){ | ||
| GetComponent.<Rigidbody>().AddRelativeForce(Vector3.forward * 300f); | ||
| } | ||
|
|
||
| function changeColor( e:LTEvent ){ | ||
| var tran:Transform = e.data as Transform; | ||
| var distance:float = Vector3.Distance( tran.position, transform.position); | ||
| var to:Vector3 = new Vector3(Random.Range(0f,1f),0f,Random.Range(0f,1f)); | ||
| LeanTween.value( gameObject, updateColor, fromColor, to, 0.8f ).setLoopPingPong(1).setDelay(distance*0.05f); | ||
| } | ||
|
|
||
| function updateColor( v:Vector3 ){ | ||
| GetComponent.<Renderer>().material.color = new Color( v.x, v.y, v.z ); | ||
| } | ||
|
|
||
| // ****** Physics / AI Stuff | ||
|
|
||
| function OnCollisionEnter(collision:Collision) { | ||
| if(collision.gameObject.layer!=2) | ||
| towardsRotation = new Vector3(0f, Random.Range(-180, 180), 0f); | ||
| } | ||
|
|
||
| function OnCollisionStay( collision:Collision ) { | ||
| if(collision.gameObject.layer!=2){ | ||
| turnForIter = 0f; | ||
| turnForLength = Random.Range(0.5f, 1.5f); | ||
| } | ||
| } | ||
|
|
||
| function FixedUpdate(){ | ||
| if(turnForIter < turnForLength){ | ||
| GetComponent.<Rigidbody>().MoveRotation( GetComponent.<Rigidbody>().rotation * Quaternion.Euler(towardsRotation * Time.deltaTime ) ); | ||
| turnForIter += Time.deltaTime; | ||
| } | ||
|
|
||
| GetComponent.<Rigidbody>().AddRelativeForce(Vector3.forward * 4.5f); | ||
| } | ||
|
|
||
| // ****** Key and clicking detection | ||
|
|
||
| function OnMouseDown(){ | ||
| if(Input.GetKey( KeyCode.J )){ // Are you also pressing the "j" key while clicking | ||
| LeanTween.dispatchEvent(MyEvents.JUMP); | ||
| }else{ | ||
| LeanTween.dispatchEvent(MyEvents.CHANGE_COLOR, transform); // with every dispatched event, you can include an object (retrieve this object with the *.data var in LTEvent) | ||
| } | ||
| } |
| @@ -0,0 +1,54 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class GeneralSequencer : MonoBehaviour { | ||
|
|
||
| public GameObject avatar1; | ||
|
|
||
| public GameObject star; | ||
|
|
||
| public GameObject dustCloudPrefab; | ||
|
|
||
| public float speedScale = 1f; | ||
|
|
||
| public void Start(){ | ||
|
|
||
| // Jump up | ||
| var seq = LeanTween.sequence(); | ||
|
|
||
| seq.append( LeanTween.moveY( avatar1, avatar1.transform.localPosition.y + 6f, 1f).setEaseOutQuad() ); | ||
|
|
||
| // Power up star, use insert when you want to branch off from the regular sequence (this does not push back the delay of other subsequent tweens) | ||
| seq.insert( LeanTween.alpha(star, 0f, 1f) ); | ||
| seq.insert( LeanTween.scale( star, Vector3.one * 3f, 1f) ); | ||
|
|
||
| // Rotate 360 | ||
| seq.append( LeanTween.rotateAround( avatar1, Vector3.forward, 360f, 0.6f ).setEaseInBack() ); | ||
|
|
||
| // Return to ground | ||
| seq.append( LeanTween.moveY( avatar1, avatar1.transform.localPosition.y, 1f).setEaseInQuad() ); | ||
|
|
||
| // Kick off spiraling clouds - Example of appending a callback method | ||
| seq.append(() => { | ||
| for(int i = 0; i < 50f; i++){ | ||
| GameObject cloud = Instantiate(dustCloudPrefab) as GameObject; | ||
| cloud.transform.parent = avatar1.transform; | ||
| cloud.transform.localPosition = new Vector3(Random.Range(-2f,2f),0f,0f); | ||
| cloud.transform.eulerAngles = new Vector3(0f,0f,Random.Range(0,360f)); | ||
|
|
||
| var range = new Vector3(cloud.transform.localPosition.x, Random.Range(2f,4f), Random.Range(-10f,10f)); | ||
|
|
||
| // Tweens not in a sequence, because we want them all to animate at the same time | ||
| LeanTween.moveLocal(cloud, range, 3f*speedScale).setEaseOutCirc(); | ||
| LeanTween.rotateAround(cloud, Vector3.forward, 360f*2, 3f*speedScale).setEaseOutCirc(); | ||
| LeanTween.alpha(cloud, 0f, 3f*speedScale).setEaseOutCirc().setDestroyOnComplete(true); | ||
| } | ||
| }); | ||
|
|
||
| // You can speed up or slow down the sequence of events | ||
| seq.setScale(speedScale); | ||
|
|
||
| // seq.reverse(); | ||
| } | ||
| } |
| @@ -0,0 +1,56 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralSimpleUiCS : MonoBehaviour { | ||
| #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 | ||
|
|
||
| public RectTransform button; | ||
|
|
||
| void Start () { | ||
| Debug.Log("For better examples see the 4.6_Examples folder!"); | ||
| if(button==null){ | ||
| Debug.LogError("Button not assigned! Create a new button via Hierarchy->Create->UI->Button. Then assign it to the button variable"); | ||
| return; | ||
| } | ||
|
|
||
| // Tweening various values in a block callback style | ||
| LeanTween.value(button.gameObject, button.anchoredPosition, new Vector2(200f,100f), 1f ).setOnUpdate( | ||
| (Vector2 val)=>{ | ||
| button.anchoredPosition = val; | ||
| } | ||
| ); | ||
|
|
||
| LeanTween.value(gameObject, 1f, 0.5f, 1f ).setOnUpdate( | ||
| (float volume)=>{ | ||
| Debug.Log("volume:"+volume); | ||
| } | ||
| ); | ||
|
|
||
| LeanTween.value(gameObject, gameObject.transform.position, gameObject.transform.position + new Vector3(0,1f,0), 1f ).setOnUpdate( | ||
| (Vector3 val)=>{ | ||
| gameObject.transform.position = val; | ||
| } | ||
| ); | ||
|
|
||
| LeanTween.value(gameObject, Color.red, Color.green, 1f ).setOnUpdate( | ||
| (Color val)=>{ | ||
| UnityEngine.UI.Image image = (UnityEngine.UI.Image)button.gameObject.GetComponent( typeof(UnityEngine.UI.Image) ); | ||
| image.color = val; | ||
| } | ||
| ); | ||
|
|
||
| // Tweening Using Unity's new Canvas GUI System | ||
| LeanTween.move(button, new Vector3(200f,-100f,0f), 1f).setDelay(1f); | ||
| LeanTween.rotateAround(button, Vector3.forward, 90f, 1f).setDelay(2f); | ||
| LeanTween.scale(button, button.localScale*2f, 1f).setDelay(3f); | ||
| LeanTween.rotateAround(button, Vector3.forward, -90f, 1f).setDelay(4f).setEase(LeanTweenType.easeInOutElastic); | ||
| } | ||
|
|
||
| #else | ||
| void Start(){ | ||
| Debug.LogError("Unity 4.6+ is required to use the new UI"); | ||
| } | ||
|
|
||
| #endif | ||
| } |
| @@ -0,0 +1,48 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 | ||
|
|
||
| public var button:RectTransform; | ||
|
|
||
| function Start () { | ||
| Debug.Log("For better examples see the 4.6_Examples folder!"); | ||
| if(button==null){ | ||
| Debug.LogError("Button not assigned! Create a new button via Hierarchy->Create->UI->Button. Then assign it to the button variable"); | ||
| return; | ||
| } | ||
|
|
||
| // Tweening various values in a block callback style | ||
| LeanTween.value(button.gameObject, button.anchoredPosition, new Vector2(200f,100f), 1f ).setOnUpdateVector3( | ||
| function(val:Vector3){ | ||
| button.anchoredPosition = new Vector2(val.x, val.y); | ||
| } | ||
| ); | ||
|
|
||
| LeanTween.value(gameObject, 1f, 0.5f, 1f ).setOnUpdate( | ||
| function(volume:float){ | ||
| Debug.Log("volume:"+volume); | ||
| } | ||
| ); | ||
|
|
||
| LeanTween.value(gameObject, gameObject.transform.position, gameObject.transform.position + new Vector3(0,1f,0), 1f ).setOnUpdateVector3( | ||
| function(val:Vector3){ | ||
| gameObject.transform.position = val; | ||
| } | ||
| ); | ||
|
|
||
| LeanTween.value(gameObject, Color.red, Color.green, 1f ).setOnUpdateColor( | ||
| function(val:Color){ | ||
| var image:UnityEngine.UI.Image = button.gameObject.GetComponent( UnityEngine.UI.Image ); | ||
| image.color = val; | ||
| } | ||
| ); | ||
|
|
||
| // Tweening Using Unity's new Canvas GUI System | ||
| LeanTween.move(button, new Vector3(200f,-100f,0f), 1f).setDelay(1f); | ||
| LeanTween.rotateAround(button, Vector3.forward, 90f, 1f).setDelay(2f); | ||
| LeanTween.scale(button, button.localScale*2f, 1f).setDelay(3f); | ||
| LeanTween.rotateAround(button, Vector3.forward, -90f, 1f).setDelay(4f).setEase(LeanTweenType.easeInOutElastic); | ||
| } | ||
|
|
||
| #endif |
| @@ -0,0 +1,89 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class GeneralUISpaceCS : MonoBehaviour { | ||
|
|
||
| public RectTransform mainWindow; | ||
| public RectTransform mainParagraphText; | ||
| public RectTransform mainTitleText; | ||
| public RectTransform mainButton1; | ||
| public RectTransform mainButton2; | ||
|
|
||
| public RectTransform pauseRing1; | ||
| public RectTransform pauseRing2; | ||
| public RectTransform pauseWindow; | ||
|
|
||
| public RectTransform chatWindow; | ||
| public RectTransform chatRect; | ||
| public Sprite[] chatSprites; | ||
| public RectTransform chatBar1; | ||
| public RectTransform chatBar2; | ||
| public UnityEngine.UI.Text chatText; | ||
|
|
||
| public RectTransform rawImageRect; | ||
|
|
||
| void Start () { | ||
| // Time.timeScale = 1f/4f; | ||
|
|
||
| // *********** Main Window ********** | ||
| // Scale the whole window in | ||
| mainWindow.localScale = Vector3.zero; | ||
| LeanTween.scale( mainWindow, new Vector3(1f,1f,1f), 0.6f).setEase(LeanTweenType.easeOutBack); | ||
| LeanTween.alphaCanvas( mainWindow.GetComponent<CanvasGroup>(), 0f, 1f).setDelay(2f).setLoopPingPong().setRepeat(2); | ||
|
|
||
| // Fade the main paragraph in while moving upwards | ||
| mainParagraphText.anchoredPosition3D += new Vector3(0f,-10f,0f); | ||
| LeanTween.textAlpha( mainParagraphText, 0f, 0.6f).setFrom(0f).setDelay(0f); | ||
| LeanTween.textAlpha( mainParagraphText, 1f, 0.6f).setEase(LeanTweenType.easeOutQuad).setDelay(0.6f); | ||
| LeanTween.move( mainParagraphText, mainParagraphText.anchoredPosition3D + new Vector3(0f,10f,0f), 0.6f).setEase(LeanTweenType.easeOutQuad).setDelay(0.6f); | ||
|
|
||
| // Flash text to purple and back | ||
| LeanTween.textColor( mainTitleText, new Color(133f/255f,145f/255f,223f/255f), 0.6f).setEase(LeanTweenType.easeOutQuad).setDelay(0.6f).setLoopPingPong().setRepeat(-1); | ||
|
|
||
| // Fade button in | ||
| LeanTween.textAlpha(mainButton2, 1f, 2f ).setFrom(0f).setDelay(0f).setEase(LeanTweenType.easeOutQuad); | ||
| LeanTween.alpha(mainButton2, 1f, 2f ).setFrom(0f).setDelay(0f).setEase(LeanTweenType.easeOutQuad); | ||
|
|
||
| // Pop size of button | ||
| LeanTween.size(mainButton1, mainButton1.sizeDelta * 1.1f, 0.5f).setDelay(3f).setEaseInOutCirc().setRepeat(6).setLoopPingPong(); | ||
|
|
||
|
|
||
| // *********** Pause Button ********** | ||
| // Drop pause button in | ||
| pauseWindow.anchoredPosition3D += new Vector3(0f,200f,0f); | ||
| LeanTween.moveY( pauseWindow, pauseWindow.anchoredPosition3D.y + -200f, 0.6f).setEase(LeanTweenType.easeOutSine).setDelay(0.6f); | ||
|
|
||
| // Punch Pause Symbol | ||
| RectTransform pauseText = pauseWindow.Find("PauseText").GetComponent<RectTransform>(); | ||
| LeanTween.moveZ( pauseText, pauseText.anchoredPosition3D.z - 80f, 1.5f).setEase(LeanTweenType.punch).setDelay(2.0f); | ||
|
|
||
| // Rotate rings around in opposite directions | ||
| LeanTween.rotateAroundLocal(pauseRing1, Vector3.forward, 360f, 12f).setRepeat(-1); | ||
| LeanTween.rotateAroundLocal(pauseRing2, Vector3.forward, -360f, 22f).setRepeat(-1); | ||
|
|
||
|
|
||
| // *********** Chat Window ********** | ||
| // Flip the chat window in | ||
| chatWindow.RotateAround(chatWindow.position, Vector3.up, -180f); | ||
| LeanTween.rotateAround(chatWindow, Vector3.up, 180f, 2f).setEase(LeanTweenType.easeOutElastic).setDelay(1.2f); | ||
|
|
||
| // Play a series of sprites on the window on repeat endlessly | ||
| LeanTween.play(chatRect, chatSprites).setLoopPingPong(); | ||
|
|
||
| // Animate the bar up and down while changing the color to red-ish | ||
| LeanTween.color( chatBar2, new Color(248f/255f,67f/255f,108f/255f, 0.5f), 1.2f).setEase(LeanTweenType.easeInQuad).setLoopPingPong().setDelay(1.2f); | ||
| LeanTween.scale( chatBar2, new Vector2(1f,0.7f), 1.2f).setEase(LeanTweenType.easeInQuad).setLoopPingPong(); | ||
|
|
||
| // Write in paragraph text | ||
| string origText = chatText.text; | ||
| chatText.text = ""; | ||
| LeanTween.value(gameObject, 0, (float)origText.Length, 6f).setEase(LeanTweenType.easeOutQuad).setOnUpdate( (float val)=>{ | ||
| chatText.text = origText.Substring( 0, Mathf.RoundToInt( val ) ); | ||
| }).setLoopClamp().setDelay(2.0f); | ||
|
|
||
| // Raw Image | ||
| LeanTween.alpha(rawImageRect,0f,1f).setLoopPingPong(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,44 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using DentedPixel; | ||
|
|
||
| public class LogoCinematic : MonoBehaviour { | ||
|
|
||
| public GameObject lean; | ||
|
|
||
| public GameObject tween; | ||
|
|
||
| void Awake(){ | ||
|
|
||
| } | ||
|
|
||
|
|
||
| void Start () { | ||
| //Time.timeScale = 0.2f; | ||
|
|
||
| // Slide in | ||
| tween.transform.localPosition += -Vector3.right * 15f; | ||
| LeanTween.moveLocalX(tween, tween.transform.localPosition.x+15f, 0.4f).setEase(LeanTweenType.linear).setDelay(0f).setOnComplete( playBoom ); | ||
|
|
||
| // Drop Down tween down | ||
| tween.transform.RotateAround(tween.transform.position, Vector3.forward, -30f); | ||
| LeanTween.rotateAround(tween, Vector3.forward, 30f, 0.4f).setEase(LeanTweenType.easeInQuad).setDelay(0.4f).setOnComplete( playBoom ); | ||
|
|
||
| // Drop Lean In | ||
| lean.transform.position += Vector3.up * 5.1f; | ||
| LeanTween.moveY(lean, lean.transform.position.y-5.1f, 0.6f).setEase(LeanTweenType.easeInQuad).setDelay(0.6f).setOnComplete( playBoom ); | ||
| } | ||
|
|
||
| void playBoom(){ | ||
| // Make your own Dynamic Audio at http://leanaudioplay.dentedpixel.com | ||
|
|
||
| AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1.163155f, 0f, -1f), new Keyframe(0.3098361f, 0f, 0f, 0f), new Keyframe(0.5f, 0.003524712f, 0f, 0f)); | ||
| AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0.000819672f, 0.007666667f, 0f, 0f), new Keyframe(0.01065573f, 0.002424242f, 0f, 0f), new Keyframe(0.02704918f, 0.007454545f, 0f, 0f), new Keyframe(0.03770492f, 0.002575758f, 0f, 0f), new Keyframe(0.052459f, 0.007090909f, 0f, 0f), new Keyframe(0.06885245f, 0.002939394f, 0f, 0f), new Keyframe(0.0819672f, 0.006727273f, 0f, 0f), new Keyframe(0.1040983f, 0.003181818f, 0f, 0f), new Keyframe(0.1188525f, 0.006212121f, 0f, 0f), new Keyframe(0.145082f, 0.004151515f, 0f, 0f), new Keyframe(0.1893443f, 0.005636364f, 0f, 0f)); | ||
|
|
||
| AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.1f,0f,0f)} ).setFrequency(11025)); | ||
|
|
||
| LeanAudio.play( audioClip ); //a:fvb:8,.000819672,.007666667,,,.01065573,.002424242,,,.02704918,.007454545,,,.03770492,.002575758,,,.052459,.007090909,,,.06885245,.002939394,,,.0819672,.006727273,,,.1040983,.003181818,,,.1188525,.006212121,,,.145082,.004151515,,,.1893443,.005636364,,,8~8,,1.163155,,-,.3098361,,,,.5,.003524712,,,8~.1,,,~11025~0~~ | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,48 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| namespace DentedPixel.LTExamples{ | ||
|
|
||
| public class PathBezier : MonoBehaviour { | ||
|
|
||
| public Transform[] trans; | ||
|
|
||
| LTBezierPath cr; | ||
| private GameObject avatar1; | ||
|
|
||
| void OnEnable(){ | ||
| // create the path | ||
| cr = new LTBezierPath( new Vector3[] {trans[0].position, trans[2].position, trans[1].position, trans[3].position, trans[3].position, trans[5].position, trans[4].position, trans[6].position} ); | ||
| } | ||
|
|
||
| void Start () { | ||
| avatar1 = GameObject.Find("Avatar1"); | ||
|
|
||
| // Tween automatically | ||
| LTDescr descr = LeanTween.move(avatar1, cr.pts, 6.5f).setOrientToPath(true).setRepeat(-1); | ||
| Debug.Log("length of path 1:"+cr.length); | ||
| Debug.Log("length of path 2:"+descr.optional.path.length); | ||
| } | ||
|
|
||
| private float iter; | ||
| void Update () { | ||
| // Or Update Manually | ||
| //cr.place2d( sprite1.transform, iter ); | ||
|
|
||
| iter += Time.deltaTime*0.07f; | ||
| if(iter>1.0f) | ||
| iter = 0.0f; | ||
| } | ||
|
|
||
| void OnDrawGizmos(){ | ||
| // Debug.Log("drwaing"); | ||
| if(cr!=null) | ||
| OnEnable(); | ||
| Gizmos.color = Color.red; | ||
| if(cr!=null) | ||
| cr.gizmoDraw(); // To Visualize the path, use this method | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,30 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class PathBezier2d : MonoBehaviour { | ||
|
|
||
| public Transform[] cubes; | ||
|
|
||
| public GameObject dude1; | ||
| public GameObject dude2; | ||
|
|
||
| private LTBezierPath visualizePath; | ||
|
|
||
| void Start () { | ||
| // move | ||
| Vector3[] path = new Vector3[]{cubes[0].position,cubes[1].position,cubes[2].position,cubes[3].position}; | ||
| visualizePath = new LTBezierPath(path); | ||
| LeanTween.move(dude1, path, 10f).setOrientToPath2d(true); | ||
|
|
||
| // move local | ||
| LeanTween.moveLocal(dude2, path, 10f).setOrientToPath2d(true); | ||
| } | ||
|
|
||
| void OnDrawGizmos(){ | ||
| // Debug.Log("drwaing"); | ||
| Gizmos.color = Color.red; | ||
| if(visualizePath!=null) | ||
| visualizePath.gizmoDraw(); // To Visualize the path, use this method | ||
| } | ||
| } |
| @@ -0,0 +1,32 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| public var customAnimationCurve:AnimationCurve; | ||
|
|
||
| public var pt1:Transform; | ||
| public var pt2:Transform; | ||
| public var pt3:Transform; | ||
| public var pt4:Transform; | ||
|
|
||
| private var containingSphere:Transform; | ||
| private var spline:LTSpline; | ||
| private var ltLogo:GameObject; | ||
|
|
||
| function Start () { | ||
| ltLogo = GameObject.Find("LeanTweenLogo"); | ||
| containingSphere = GameObject.Find("ContaingCube").transform; | ||
|
|
||
| var path:Vector3[] = [pt1.position,pt1.position,pt2.position,pt3.position,pt4.position,pt4.position]; | ||
| spline = new LTSpline( path ); | ||
| LeanTween.moveSplineLocal( ltLogo, path, 3.0 ).setEase(LeanTweenType.easeInQuad).setOrientToPath(true).setRepeat(-1); | ||
| } | ||
|
|
||
| function Update(){ | ||
| containingSphere.transform.eulerAngles.y += Time.deltaTime*3.0; | ||
| } | ||
|
|
||
| function OnDrawGizmos(){ | ||
| if(spline!=null) | ||
| spline.gizmoDraw(1.0f); // debug aid to be able to see the path in the scene inspector | ||
| } | ||
|
|
| @@ -0,0 +1,38 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class ExampleSpline : MonoBehaviour { | ||
|
|
||
| public Transform[] trans; | ||
|
|
||
| LTSpline spline; | ||
| private GameObject ltLogo; | ||
| private GameObject ltLogo2; | ||
|
|
||
| void Start () { | ||
| spline = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} ); | ||
| ltLogo = GameObject.Find("LeanTweenLogo1"); | ||
| ltLogo2 = GameObject.Find("LeanTweenLogo2"); | ||
|
|
||
| LeanTween.moveSpline( ltLogo2, spline.pts, 1f).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong().setOrientToPath(true); | ||
|
|
||
| LTDescr zoomInPath_LT = LeanTween.moveSpline(ltLogo2, new Vector3[]{Vector3.zero, Vector3.zero, new Vector3(1,1,1), new Vector3(2,1,1), new Vector3(2,1,1)}, 1.5f); | ||
| zoomInPath_LT.setUseEstimatedTime(true); | ||
| } | ||
|
|
||
| private float iter; | ||
| void Update () { | ||
| // Iterating over path | ||
| ltLogo.transform.position = spline.point( iter /*(Time.time*1000)%1000 * 1.0 / 1000.0 */); | ||
|
|
||
| iter += Time.deltaTime*0.1f; | ||
| if(iter>1.0f) | ||
| iter = 0.0f; | ||
| } | ||
|
|
||
| void OnDrawGizmos(){ | ||
| if(spline!=null) | ||
| spline.gizmoDraw(); // debug aid to be able to see the path in the scene inspector | ||
| } | ||
| } |
| @@ -0,0 +1,36 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class PathSpline2d : MonoBehaviour { | ||
|
|
||
| public Transform[] cubes; | ||
|
|
||
| public GameObject dude1; | ||
| public GameObject dude2; | ||
|
|
||
| private LTSpline visualizePath; | ||
|
|
||
| void Start () { | ||
| Vector3[] path = new Vector3[] { | ||
| cubes[0].position, | ||
| cubes[1].position, | ||
| cubes[2].position, | ||
| cubes[3].position, | ||
| cubes[4].position | ||
| }; | ||
|
|
||
| visualizePath = new LTSpline( path ); | ||
| // move | ||
| LeanTween.moveSpline(dude1, path, 10f).setOrientToPath2d(true).setSpeed(2f); | ||
|
|
||
| // move Local | ||
| LeanTween.moveSplineLocal(dude2, path, 10f).setOrientToPath2d(true).setSpeed(2f); | ||
| } | ||
|
|
||
| void OnDrawGizmos(){ | ||
| Gizmos.color = Color.red; | ||
| if(visualizePath!=null) | ||
| visualizePath.gizmoDraw(); | ||
| } | ||
| } |
| @@ -0,0 +1,125 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using DentedPixel; | ||
|
|
||
| public class PathSplineEndlessCS : MonoBehaviour { | ||
| public GameObject trackTrailRenderers; | ||
| public GameObject car; | ||
| public GameObject carInternal; | ||
|
|
||
| public GameObject[] cubes; | ||
| private int cubesIter; | ||
| public GameObject[] trees; | ||
| private int treesIter; | ||
|
|
||
| public float randomIterWidth = 0.1f; | ||
|
|
||
| private LTSpline track; | ||
| private List<Vector3> trackPts = new List<Vector3>(); | ||
| private int zIter = 0; | ||
| private float carIter = 0f; | ||
| private float carAdd; | ||
| private int trackMaxItems = 15; | ||
| private int trackIter = 1; | ||
| private float pushTrackAhead = 0f; | ||
| private float randomIter = 0f; | ||
|
|
||
| void Start () { | ||
|
|
||
| // Setup initial track points | ||
| for(int i = 0; i < 4; i++){ | ||
| addRandomTrackPoint(); | ||
| } | ||
| refreshSpline(); | ||
|
|
||
| // Animate in track ahead of the car | ||
| LeanTween.value(gameObject, 0, 0.3f, 2f).setOnUpdate( ( float val )=>{ | ||
| pushTrackAhead = val; | ||
| }); | ||
| } | ||
|
|
||
| void Update () { | ||
|
|
||
| float zLastDist = (trackPts[ trackPts.Count - 1].z - transform.position.z); | ||
| if(zLastDist < 200f){ // if the last node is too close we'll add in a new point and refresh the spline | ||
| addRandomTrackPoint(); | ||
| refreshSpline(); | ||
| } | ||
|
|
||
| // Update avatar's position on correct track | ||
| track.place( car.transform, carIter ); | ||
| carIter += carAdd * Time.deltaTime; | ||
|
|
||
| // we'll place the trail renders always a bit in front of the car | ||
| track.place( trackTrailRenderers.transform, carIter + pushTrackAhead ); | ||
|
|
||
|
|
||
| // Switch tracks on keyboard input | ||
| float turn = Input.GetAxis("Horizontal"); | ||
| if(Input.anyKeyDown){ | ||
| if(turn<0f && trackIter>0){ | ||
| trackIter--; | ||
| playSwish(); | ||
| }else if(turn>0f && trackIter < 2){ // We have three track "rails" so stopping it from going above 3 | ||
| trackIter++; | ||
| playSwish(); | ||
| } | ||
| // Move the internal local x of the car to simulate changing tracks | ||
| LeanTween.moveLocalX(carInternal, (trackIter-1)*6f, 0.3f).setEase(LeanTweenType.easeOutBack); | ||
| } | ||
| } | ||
|
|
||
| // Simple object queuing system | ||
| GameObject objectQueue( GameObject[] arr, ref int lastIter ){ | ||
| lastIter = lastIter>=arr.Length-1 ? 0 : lastIter+1; | ||
|
|
||
| // Reset scale and rotation for a new animation | ||
| arr[ lastIter ].transform.localScale = Vector3.one; | ||
| arr[ lastIter ].transform.rotation = Quaternion.identity; | ||
| return arr[ lastIter ]; | ||
| } | ||
|
|
||
| void addRandomTrackPoint(){ | ||
| float randX = Mathf.PerlinNoise(0f, randomIter); | ||
| randomIter += randomIterWidth; | ||
|
|
||
| Vector3 randomInFrontPosition = new Vector3( (randX-0.5f)*20f, 0f, zIter*40f); | ||
|
|
||
| // placing the box is just to visualize how the paths get created | ||
| GameObject box = objectQueue( cubes, ref cubesIter ); | ||
| box.transform.position = randomInFrontPosition; | ||
|
|
||
| // Line the roads with trees | ||
| GameObject tree = objectQueue( trees, ref treesIter ); | ||
| float treeX = zIter%2==0 ? -15f : 15f; | ||
| tree.transform.position = new Vector3( randomInFrontPosition.x + treeX, 0f, zIter*40f); | ||
|
|
||
| // Animate in new tree (just for fun) | ||
| LeanTween.rotateAround( tree, Vector3.forward, 0f, 1f).setFrom( zIter%2==0 ? 180f : -180f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| trackPts.Add( randomInFrontPosition ); // Add a future spline node | ||
| if(trackPts.Count > trackMaxItems) | ||
| trackPts.RemoveAt(0); // Remove the trailing spline node | ||
|
|
||
| zIter++; | ||
| } | ||
|
|
||
| void refreshSpline(){ | ||
| track = new LTSpline( trackPts.ToArray() ); | ||
| carIter = track.ratioAtPoint( car.transform.position ); // we created a new spline so we need to update the cars iteration point on this new spline | ||
| // Debug.Log("distance:"+track.distance+" carIter:"+carIter); | ||
| carAdd = 40f / track.distance; // we want to make sure the speed is based on the distance of the spline for a more constant speed | ||
| } | ||
|
|
||
| // Make your own LeanAudio sounds at http://leanaudioplay.dentedpixel.com | ||
| void playSwish(){ | ||
| AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 0.005464481f, 1.83897f, 0f), new Keyframe(0.1114856f, 2.281785f, 0f, 0f), new Keyframe(0.2482903f, 2.271654f, 0f, 0f), new Keyframe(0.3f, 0.01670286f, 0f, 0f)); | ||
| AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.00136725f, 0f, 0f), new Keyframe(0.1482391f, 0.005405405f, 0f, 0f), new Keyframe(0.2650336f, 0.002480127f, 0f, 0f)); | ||
|
|
||
| AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.2f,0.5f,0f)} ).setWaveNoise().setWaveNoiseScale(1000)); | ||
|
|
||
| LeanAudio.play( audioClip ); //a:fvb:8,,.00136725,,,.1482391,.005405405,,,.2650336,.002480127,,,8~8,,.005464481,1.83897,,.1114856,2.281785,,,.2482903,2.271654,,,.3,.01670286,,,8~.2,.5,,~~0~~3,1000,1 | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,93 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using DentedPixel; | ||
| // This class is to test the upper limits of a complex spline | ||
|
|
||
| public class PathSplinePerformanceCS : MonoBehaviour { | ||
|
|
||
| public GameObject trackTrailRenderers; | ||
| public GameObject car; | ||
| public GameObject carInternal; | ||
|
|
||
|
|
||
| public float circleLength = 10f; | ||
| public float randomRange = 1f; | ||
| public int trackNodes = 30; | ||
| public float carSpeed = 30f; | ||
| public float tracerSpeed = 2f; | ||
|
|
||
| private LTSpline track; | ||
| private int trackIter = 1; | ||
| private float carAdd; | ||
| private float trackPosition; // ratio 0,1 of the avatars position on the track | ||
|
|
||
| void Start () { | ||
| Application.targetFrameRate = 240; | ||
|
|
||
| // Make the track from the provided transforms | ||
| List<Vector3> randList = new List<Vector3>(); | ||
| float degree = 0f; | ||
| int nodeLength = trackNodes + 1;// We need to add some extra because the first and last nodes just act as *guides* to the first and last curvature | ||
| for(int i = 0; i < nodeLength; i++){ | ||
| float x = Mathf.Cos( degree * Mathf.Deg2Rad ) * circleLength + Random.Range(0f, randomRange); | ||
| float z = Mathf.Sin( degree * Mathf.Deg2Rad ) * circleLength + Random.Range(0f, randomRange); | ||
| randList.Add( new Vector3(x,1f,z ) ); | ||
|
|
||
| degree += 360f/(float)trackNodes; | ||
| } | ||
| randList[0] = randList[ randList.Count-1 ]; // set the zero-ith one as the last position so it will flow smoothly into the first curve | ||
| randList.Add( randList[1] ); // Add the first and second one in, so the circle connects to itself | ||
| randList.Add( randList[2] ); | ||
|
|
||
| track = new LTSpline( randList.ToArray() ); | ||
|
|
||
| carAdd = carSpeed / track.distance; | ||
|
|
||
| tracerSpeed = track.distance / (carSpeed*1.2f); | ||
|
|
||
| // Optional technique to show the trails in game | ||
| LeanTween.moveSpline( trackTrailRenderers, track, tracerSpeed ).setOrientToPath(true).setRepeat(-1); | ||
| } | ||
|
|
||
| void Update () { | ||
| // Switch tracks on keyboard input | ||
| float turn = Input.GetAxis("Horizontal"); | ||
| if(Input.anyKeyDown){ | ||
| if(turn<0f && trackIter>0){ | ||
| trackIter--; | ||
| playSwish(); | ||
| }else if(turn>0f && trackIter < 2){ // We have three track "rails" so stopping it from going above 3 | ||
| trackIter++; | ||
| playSwish(); | ||
| } | ||
| // Move the internal local x of the car to simulate changing tracks | ||
| LeanTween.moveLocalX(carInternal, (trackIter-1)*6f, 0.3f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| } | ||
|
|
||
| // Update avatar's position on correct track | ||
| track.place( car.transform, trackPosition ); | ||
|
|
||
| trackPosition += Time.deltaTime * carAdd; | ||
|
|
||
| if(trackPosition>1f) | ||
| trackPosition = 0f; // We need to keep the ratio between 0-1 so after one we will loop back to the beginning of the track | ||
| } | ||
|
|
||
| // Use this for visualizing what the track looks like in the editor (for a full suite of spline tools check out the LeanTween Editor) | ||
| void OnDrawGizmos(){ | ||
| if(track!=null) | ||
| track.drawGizmo( Color.red ); | ||
| } | ||
|
|
||
| // Make your own LeanAudio sounds at http://leanaudioplay.dentedpixel.com | ||
| void playSwish(){ | ||
| AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 0.005464481f, 1.83897f, 0f), new Keyframe(0.1114856f, 2.281785f, 0f, 0f), new Keyframe(0.2482903f, 2.271654f, 0f, 0f), new Keyframe(0.3f, 0.01670286f, 0f, 0f)); | ||
| AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.00136725f, 0f, 0f), new Keyframe(0.1482391f, 0.005405405f, 0f, 0f), new Keyframe(0.2650336f, 0.002480127f, 0f, 0f)); | ||
|
|
||
| AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.2f,0.5f,0f)} ).setWaveNoise().setWaveNoiseScale(1000)); | ||
|
|
||
| LeanAudio.play( audioClip ); //a:fvb:8,,.00136725,,,.1482391,.005405405,,,.2650336,.002480127,,,8~8,,.005464481,1.83897,,.1114856,2.281785,,,.2482903,2.271654,,,.3,.01670286,,,8~.2,.5,,~~0~~3,1000,1 | ||
| } | ||
| } |
| @@ -0,0 +1,68 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| // This project demonstrates how you can use the spline behaviour for a multi-track game (like an endless runner style) | ||
|
|
||
| public class PathSplineTrackCS : MonoBehaviour { | ||
|
|
||
| public GameObject car; | ||
| public GameObject carInternal; | ||
| public GameObject trackTrailRenderers; | ||
|
|
||
| public Transform[] trackOnePoints; | ||
|
|
||
| private LTSpline track; | ||
| private int trackIter = 1; | ||
| private float trackPosition; // ratio 0,1 of the avatars position on the track | ||
|
|
||
| void Start () { | ||
| // Make the track from the provided transforms | ||
| track = new LTSpline( new Vector3[] {trackOnePoints[0].position, trackOnePoints[1].position, trackOnePoints[2].position, trackOnePoints[3].position, trackOnePoints[4].position, trackOnePoints[5].position, trackOnePoints[6].position} ); | ||
|
|
||
| // Optional technique to show the trails in game | ||
| LeanTween.moveSpline( trackTrailRenderers, track, 2f ).setOrientToPath(true).setRepeat(-1); | ||
| } | ||
|
|
||
| void Update () { | ||
| // Switch tracks on keyboard input | ||
| float turn = Input.GetAxis("Horizontal"); | ||
| if(Input.anyKeyDown){ | ||
| if(turn<0f && trackIter>0){ | ||
| trackIter--; | ||
| playSwish(); | ||
| }else if(turn>0f && trackIter < 2){ // We have three track "rails" so stopping it from going above 3 | ||
| trackIter++; | ||
| playSwish(); | ||
| } | ||
| // Move the internal local x of the car to simulate changing tracks | ||
| LeanTween.moveLocalX(carInternal, (trackIter-1)*6f, 0.3f).setEase(LeanTweenType.easeOutBack); | ||
|
|
||
| } | ||
|
|
||
| // Update avatar's position on correct track | ||
| track.place( car.transform, trackPosition ); | ||
|
|
||
| trackPosition += Time.deltaTime * 0.03f;// * Input.GetAxis("Vertical"); // Uncomment to have the forward and backwards controlled by the directional arrows | ||
|
|
||
| if (trackPosition < 0f) // We need to keep the ratio between 0-1 so after one we will loop back to the beginning of the track | ||
| trackPosition = 1f; | ||
| else if(trackPosition>1f) | ||
| trackPosition = 0f; | ||
| } | ||
|
|
||
| // Use this for visualizing what the track looks like in the editor (for a full suite of spline tools check out the LeanTween Editor) | ||
| void OnDrawGizmos(){ | ||
| LTSpline.drawGizmo( trackOnePoints, Color.red); | ||
| } | ||
|
|
||
| // Make your own LeanAudio sounds at http://leanaudioplay.dentedpixel.com | ||
| void playSwish(){ | ||
| AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 0.005464481f, 1.83897f, 0f), new Keyframe(0.1114856f, 2.281785f, 0f, 0f), new Keyframe(0.2482903f, 2.271654f, 0f, 0f), new Keyframe(0.3f, 0.01670286f, 0f, 0f)); | ||
| AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.00136725f, 0f, 0f), new Keyframe(0.1482391f, 0.005405405f, 0f, 0f), new Keyframe(0.2650336f, 0.002480127f, 0f, 0f)); | ||
|
|
||
| AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.2f,0.5f,0f)} ).setWaveNoise().setWaveNoiseScale(1000)); | ||
|
|
||
| LeanAudio.play( audioClip ); //a:fvb:8,,.00136725,,,.1482391,.005405405,,,.2650336,.002480127,,,8~8,,.005464481,1.83897,,.1114856,2.281785,,,.2482903,2.271654,,,.3,.01670286,,,8~.2,.5,,~~0~~3,1000,1 | ||
| } | ||
| } |
| @@ -0,0 +1,46 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using DentedPixel; | ||
|
|
||
| public class PathSplines : MonoBehaviour { | ||
|
|
||
| public Transform[] trans; | ||
|
|
||
| LTSpline cr; | ||
| private GameObject avatar1; | ||
|
|
||
| void OnEnable(){ | ||
| // create the path | ||
| cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} ); | ||
| // cr = new LTSpline( new Vector3[] {new Vector3(-1f,0f,0f), new Vector3(0f,0f,0f), new Vector3(4f,0f,0f), new Vector3(20f,0f,0f), new Vector3(30f,0f,0f)} ); | ||
| } | ||
|
|
||
| void Start () { | ||
| avatar1 = GameObject.Find("Avatar1"); | ||
|
|
||
| // Tween automatically | ||
| LeanTween.move(avatar1, cr, 6.5f).setOrientToPath(true).setRepeat(1).setOnComplete( ()=>{ | ||
| Vector3[] next = new Vector3[] {trans[4].position, trans[3].position, trans[2].position, trans[1].position, trans[0].position}; | ||
| LeanTween.moveSpline( avatar1, next, 6.5f); // move it back to the start without an LTSpline | ||
| }).setEase(LeanTweenType.easeOutQuad); | ||
| } | ||
|
|
||
| private float iter; | ||
| void Update () { | ||
| // Or Update Manually | ||
| // cr.place( avatar1.transform, iter ); | ||
|
|
||
| iter += Time.deltaTime*0.07f; | ||
| if(iter>1.0f) | ||
| iter = 0.0f; | ||
| } | ||
|
|
||
| void OnDrawGizmos(){ | ||
| // Debug.Log("drwaing"); | ||
| if(cr==null) | ||
| OnEnable(); | ||
| Gizmos.color = Color.red; | ||
| if(cr!=null) | ||
| cr.gizmoDraw(); // To Visualize the path, use this method | ||
| } | ||
| } |
| @@ -0,0 +1,233 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System; | ||
| using System.Threading; | ||
| using DentedPixel; | ||
|
|
||
| public class TestingAllCS : MonoBehaviour { | ||
| public AnimationCurve customAnimationCurve; | ||
| public Transform pt1; | ||
| public Transform pt2; | ||
| public Transform pt3; | ||
| public Transform pt4; | ||
| public Transform pt5; | ||
|
|
||
| public delegate void NextFunc(); | ||
| private int exampleIter = 0; | ||
| private string[] exampleFunctions = new string[] { /**/"updateValue3Example", "loopTestClamp", "loopTestPingPong", "moveOnACurveExample", "customTweenExample", "moveExample", "rotateExample", "scaleExample", "updateValueExample", "delayedCallExample", "alphaExample", "moveLocalExample", "rotateAroundExample", "colorExample" }; | ||
| public bool useEstimatedTime = true; | ||
| private GameObject ltLogo; | ||
| private TimingType timingType = TimingType.SteadyNormalTime; | ||
| private int descrTimeScaleChangeId; | ||
| private Vector3 origin; | ||
|
|
||
| public enum TimingType{ | ||
| SteadyNormalTime, | ||
| IgnoreTimeScale, | ||
| HalfTimeScale, | ||
| VariableTimeScale, | ||
| Length | ||
| } | ||
|
|
||
| void Awake(){ | ||
| // LeanTween.init(3200); // 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. | ||
| } | ||
|
|
||
| void Start () { | ||
| ltLogo = GameObject.Find("LeanTweenLogo"); | ||
| LeanTween.delayedCall(1f, cycleThroughExamples); | ||
| origin = ltLogo.transform.position; | ||
|
|
||
| // alphaExample(); | ||
| } | ||
|
|
||
| void pauseNow(){ | ||
| Time.timeScale = 0f; | ||
| Debug.Log("pausing"); | ||
| } | ||
|
|
||
| void OnGUI(){ | ||
| string label = useEstimatedTime ? "useEstimatedTime" : "timeScale:"+Time.timeScale; | ||
| GUI.Label(new Rect(0.03f*Screen.width,0.03f*Screen.height,0.5f*Screen.width,0.3f*Screen.height), label); | ||
| } | ||
|
|
||
| void endlessCallback(){ | ||
| Debug.Log("endless"); | ||
| } | ||
|
|
||
| void cycleThroughExamples(){ | ||
| if(exampleIter==0){ | ||
| int iter = (int)timingType + 1; | ||
| if(iter>(int)TimingType.Length) | ||
| iter = 0; | ||
| timingType = (TimingType)iter; | ||
| useEstimatedTime = timingType==TimingType.IgnoreTimeScale; | ||
| Time.timeScale = useEstimatedTime ? 0 : 1f; // pause the Time Scale to show the effectiveness of the useEstimatedTime feature (this is very usefull with Pause Screens) | ||
| if(timingType==TimingType.HalfTimeScale) | ||
| Time.timeScale = 0.5f; | ||
|
|
||
| if(timingType==TimingType.VariableTimeScale){ | ||
| descrTimeScaleChangeId = LeanTween.value( gameObject, 0.01f, 10.0f, 3f).setOnUpdate( (float val)=>{ | ||
| //Debug.Log("timeScale val:"+val); | ||
| Time.timeScale = val; | ||
| }).setEase(LeanTweenType.easeInQuad).setUseEstimatedTime(true).setRepeat(-1).id; | ||
| }else{ | ||
| Debug.Log("cancel variable time"); | ||
| LeanTween.cancel( descrTimeScaleChangeId ); | ||
| } | ||
| } | ||
| gameObject.BroadcastMessage( exampleFunctions[ exampleIter ] ); | ||
|
|
||
| // Debug.Log("cycleThroughExamples time:"+Time.time + " useEstimatedTime:"+useEstimatedTime); | ||
| float delayTime = 1.1f; | ||
| LeanTween.delayedCall( gameObject, delayTime, cycleThroughExamples).setUseEstimatedTime(useEstimatedTime); | ||
|
|
||
| exampleIter = exampleIter+1>=exampleFunctions.Length ? 0 : exampleIter + 1; | ||
| } | ||
|
|
||
| public void updateValue3Example(){ | ||
| Debug.Log("updateValue3Example Time:"+Time.time); | ||
| LeanTween.value( gameObject, updateValue3ExampleCallback, new Vector3(0.0f, 270.0f, 0.0f), new Vector3(30.0f, 270.0f, 180f), 0.5f ).setEase(LeanTweenType.easeInBounce).setRepeat(2).setLoopPingPong().setOnUpdateVector3(updateValue3ExampleUpdate).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void updateValue3ExampleUpdate( Vector3 val){ | ||
| //Debug.Log("val:"+val+" obj:"+obj); | ||
| } | ||
|
|
||
| public void updateValue3ExampleCallback( Vector3 val ){ | ||
| ltLogo.transform.eulerAngles = val; | ||
| // Debug.Log("updateValue3ExampleCallback:"+val); | ||
| } | ||
|
|
||
| public void loopTestClamp(){ | ||
| Debug.Log("loopTestClamp Time:"+Time.time); | ||
| GameObject cube1 = GameObject.Find("Cube1"); | ||
| cube1.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); | ||
| LeanTween.scaleZ( cube1, 4.0f, 1.0f).setEase(LeanTweenType.easeOutElastic).setRepeat(7).setLoopClamp().setUseEstimatedTime(useEstimatedTime);// | ||
| } | ||
|
|
||
| public void loopTestPingPong(){ | ||
| Debug.Log("loopTestPingPong Time:"+Time.time); | ||
| GameObject cube2 = GameObject.Find("Cube2"); | ||
| cube2.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); | ||
| LeanTween.scaleY( cube2, 4.0f, 1.0f ).setEase(LeanTweenType.easeOutQuad).setLoopPingPong(4).setUseEstimatedTime(useEstimatedTime); | ||
| //LeanTween.scaleY( cube2, 4.0f, 1.0f, LeanTween.options().setEaseOutQuad().setRepeat(8).setLoopPingPong().setUseEstimatedTime(useEstimatedTime) ); | ||
| } | ||
|
|
||
| public void colorExample(){ | ||
| GameObject lChar = GameObject.Find("LCharacter"); | ||
| LeanTween.color( lChar, new Color(1.0f,0.0f,0.0f,0.5f), 0.5f ).setEase(LeanTweenType.easeOutBounce).setRepeat(2).setLoopPingPong().setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void moveOnACurveExample(){ | ||
| Debug.Log("moveOnACurveExample Time:"+Time.time); | ||
|
|
||
| Vector3[] path = new Vector3[] { origin,pt1.position,pt2.position,pt3.position,pt3.position,pt4.position,pt5.position,origin}; | ||
| LeanTween.move( ltLogo, path, 1.0f ).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void customTweenExample(){ | ||
| Debug.Log("customTweenExample starting pos:"+ltLogo.transform.position+" origin:"+origin); | ||
|
|
||
| LeanTween.moveX( ltLogo, -10.0f, 0.5f ).setEase(customAnimationCurve).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.moveX( ltLogo, 0.0f, 0.5f ).setEase(customAnimationCurve).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void moveExample(){ | ||
| Debug.Log("moveExample"); | ||
|
|
||
| LeanTween.move( ltLogo, new Vector3(-2f,-1f,0f), 0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.move( ltLogo, origin, 0.5f).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void rotateExample(){ | ||
| Debug.Log("rotateExample"); | ||
|
|
||
| Hashtable returnParam = new Hashtable(); | ||
| returnParam.Add("yo", 5.0); | ||
|
|
||
| LeanTween.rotate( ltLogo, new Vector3(0f,360f,0f), 1f).setEase(LeanTweenType.easeOutQuad).setOnComplete(rotateFinished).setOnCompleteParam(returnParam).setOnUpdate(rotateOnUpdate).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void rotateOnUpdate( float val ){ | ||
| //Debug.Log("rotating val:"+val); | ||
| } | ||
|
|
||
| public void rotateFinished( object hash ){ | ||
| Hashtable h = hash as Hashtable; | ||
| Debug.Log("rotateFinished hash:"+h["yo"]); | ||
| } | ||
|
|
||
| public void scaleExample(){ | ||
| Debug.Log("scaleExample"); | ||
|
|
||
| Vector3 currentScale = ltLogo.transform.localScale; | ||
| LeanTween.scale( ltLogo, new Vector3(currentScale.x+0.2f,currentScale.y+0.2f,currentScale.z+0.2f), 1f ).setEase(LeanTweenType.easeOutBounce).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void updateValueExample(){ | ||
| Debug.Log("updateValueExample"); | ||
| Hashtable pass = new Hashtable(); | ||
| pass.Add("message", "hi"); | ||
| LeanTween.value( gameObject, (Action<float, object>)updateValueExampleCallback, ltLogo.transform.eulerAngles.y, 270f, 1f ).setEase(LeanTweenType.easeOutElastic).setOnUpdateParam(pass).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void updateValueExampleCallback( float val, object hash ){ | ||
| // Hashtable h = hash as Hashtable; | ||
| // Debug.Log("message:"+h["message"]+" val:"+val); | ||
| Vector3 tmp = ltLogo.transform.eulerAngles; | ||
| tmp.y = val; | ||
| ltLogo.transform.eulerAngles = tmp; | ||
| } | ||
|
|
||
| public void delayedCallExample(){ | ||
| Debug.Log("delayedCallExample"); | ||
|
|
||
| LeanTween.delayedCall(0.5f, delayedCallExampleCallback).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void delayedCallExampleCallback(){ | ||
| Debug.Log("Delayed function was called"); | ||
| Vector3 currentScale = ltLogo.transform.localScale; | ||
|
|
||
| LeanTween.scale( ltLogo, new Vector3(currentScale.x-0.2f,currentScale.y-0.2f,currentScale.z-0.2f), 0.5f ).setEase(LeanTweenType.easeInOutCirc).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void alphaExample(){ | ||
| Debug.Log("alphaExample"); | ||
|
|
||
| GameObject lChar = GameObject.Find ("LCharacter"); | ||
| LeanTween.alpha( lChar, 0.0f, 0.5f ).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.alpha( lChar, 1.0f, 0.5f ).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void moveLocalExample(){ | ||
| Debug.Log("moveLocalExample"); | ||
|
|
||
| GameObject lChar = GameObject.Find ("LCharacter"); | ||
| Vector3 origPos = lChar.transform.localPosition; | ||
| LeanTween.moveLocal( lChar, new Vector3(0.0f,2.0f,0.0f), 0.5f ).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.moveLocal( lChar, origPos, 0.5f ).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void rotateAroundExample(){ | ||
| Debug.Log("rotateAroundExample"); | ||
|
|
||
| GameObject lChar = GameObject.Find ("LCharacter"); | ||
| LeanTween.rotateAround( lChar, Vector3.up, 360.0f, 1.0f ).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| public void loopPause(){ | ||
| GameObject cube1 = GameObject.Find("Cube1"); | ||
| LeanTween.pause(cube1); | ||
| } | ||
|
|
||
| public void loopResume(){ | ||
| GameObject cube1 = GameObject.Find("Cube1"); | ||
| LeanTween.resume(cube1 ); | ||
| } | ||
|
|
||
| public void punchTest(){ | ||
| LeanTween.moveX( ltLogo, 7.0f, 1.0f ).setEase(LeanTweenType.punch).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
| } |
| @@ -0,0 +1,186 @@ | ||
| #pragma strict | ||
| import DentedPixel; | ||
|
|
||
| public var customAnimationCurve:AnimationCurve; | ||
| public var shakeCurve:AnimationCurve; | ||
|
|
||
| public var pt1:Transform; | ||
| public var pt2:Transform; | ||
| public var pt3:Transform; | ||
| public var pt4:Transform; | ||
| public var pt5:Transform; | ||
|
|
||
| function Awake(){ | ||
| LeanTween.init(400); // 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. | ||
| } | ||
|
|
||
| function Start () { | ||
| ltLogo = GameObject.Find("LeanTweenLogo"); | ||
| cycleThroughExamples(); | ||
| //LeanTween.delayedCall(1.0f, cycleThroughExamples); | ||
| // loopTestClamp(); | ||
| // loopTestPingPong(); | ||
| // LeanTween.delayedCall(2.6, loopPause); | ||
| // LeanTween.delayedCall(4.5, loopResume); | ||
| // LeanTween.delayedCall(1.5, loopCancel); | ||
| } | ||
|
|
||
| function OnGUI(){ | ||
| GUI.Label(Rect(0.03*Screen.width,0.03*Screen.height,0.5*Screen.width,0.3*Screen.height), "useEstimatedTime:"+useEstimatedTime); | ||
| } | ||
|
|
||
| private var exampleIter:int = 0; | ||
| private var exampleFunctions = [updateValue3Example,loopTestPingPong,loopTestClamp,moveOnACurveExample,punchTest, customTweenExample, moveExample, rotateExample, scaleExample, updateValueExample, alphaExample, moveLocalExample, delayedCallExample, rotateAroundExample]; | ||
| private var useEstimatedTime:boolean = true; | ||
| private var ltLogo:GameObject; | ||
| private var cube1:GameObject; | ||
| private var cube2:GameObject; | ||
|
|
||
| function cycleThroughExamples(){ | ||
|
|
||
| if(exampleIter==0){ | ||
| useEstimatedTime = !useEstimatedTime; | ||
| Time.timeScale = useEstimatedTime ? 0 : 1; // pause the Time Scale to show the effectiveness of the useEstimatedTime feature (this is very usefull with Pause Screens) | ||
| } | ||
| exampleFunctions[ exampleIter ](); | ||
| exampleIter = exampleIter+1>=exampleFunctions.length ? 0 : exampleIter + 1; | ||
|
|
||
| LeanTween.delayedCall( 1.05, cycleThroughExamples).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function updateValue3Example(){ | ||
| Debug.Log("updateValue3Example"); | ||
| LeanTween.value( ltLogo, updateValue3ExampleCallback, new Vector3(0.0, 270.0, 0.0), new Vector3(30.0, 270.0, 180), 0.5).setEase(LeanTweenType.easeInBounce).setLoopPingPong().setRepeat(2).setOnUpdateVector3(updateValue3ExampleUpdate).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function updateValue3ExampleUpdate( val:Vector3 ){ | ||
| Debug.Log("val:"+val); | ||
| } | ||
|
|
||
| function updateValue3ExampleCallback( val:Vector3 ){ | ||
| ltLogo.transform.eulerAngles = val; | ||
| } | ||
|
|
||
| function loopTestClamp(){ | ||
| Debug.Log("loopTestClamp"); | ||
| cube1 = GameObject.Find("Cube1"); | ||
| cube1.transform.localScale.z = 1.0; | ||
| moveId = LeanTween.scaleZ( cube1, 4.0, 1.0).setEase(LeanTweenType.easeOutElastic).setLoopClamp().setRepeat(7).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function loopTestPingPong(){ | ||
| Debug.Log("loopTestPingPong"); | ||
| cube2 = GameObject.Find("Cube2"); | ||
| cube2.transform.localScale.y = 1.0; | ||
| pingPongDescrId = LeanTween.scaleY( cube2, 4.0, 1.0).setEase(LeanTweenType.easeOutQuad).setLoopPingPong(4).setUseEstimatedTime(useEstimatedTime).id; | ||
| } | ||
|
|
||
| function moveOnACurveExample(){ | ||
| Debug.Log("moveOnACurveExample"); | ||
| var path:Vector3[] = [ltLogo.transform.position,pt1.position,pt2.position,pt3.position,pt3.position,pt4.position,pt5.position,ltLogo.transform.position]; | ||
| LeanTween.move( ltLogo, path, 1.0).setEase(LeanTweenType.easeInQuad).setOrientToPath(true).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function punchTest(){ | ||
| LeanTween.moveX( ltLogo, 7, 1.0).setEase(LeanTweenType.punch).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function customTweenExample(){ | ||
| Debug.Log("customTweenExample"); | ||
|
|
||
| LeanTween.moveX( ltLogo, -10, 0.5).setEase(customAnimationCurve).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.moveX( ltLogo, 0, 0.5).setDelay(0.5).setEase(customAnimationCurve).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function moveExample(){ | ||
| Debug.Log("moveExample"); | ||
|
|
||
| LeanTween.move( ltLogo, new Vector3(-2f,-1f,0f), 0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.move( ltLogo, ltLogo.transform.position, 0.5f).setDelay(0.5).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function rotateExample(){ | ||
| Debug.Log("rotateExample"); | ||
|
|
||
| LeanTween.rotate( ltLogo, Vector3(0,360,0), 1.0).setEase(LeanTweenType.easeOutQuad).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function scaleExample(){ | ||
| Debug.Log("scaleExample"); | ||
|
|
||
| var currentScale:Vector3 = ltLogo.transform.localScale; | ||
| LeanTween.scale( ltLogo, new Vector3(currentScale.x+0.2,currentScale.y+0.2,currentScale.z+0.2), 1).setEase(LeanTweenType.easeOutBounce).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function updateValueExample(){ | ||
| Debug.Log("updateValueExample"); | ||
| LeanTween.value( ltLogo, updateValueExampleCallback, ltLogo.transform.eulerAngles.y, 270.0, 1).setEase(LeanTweenType.easeOutElastic).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function updateValueExampleCallback( val:float ){ | ||
| ltLogo.transform.eulerAngles.y = val; | ||
| } | ||
|
|
||
| function delayedCallExample(){ | ||
| Debug.Log("delayedCallExample"); | ||
|
|
||
| LeanTween.delayedCall(0.5, delayedCallExampleCallback).setUseEstimatedTime(useEstimatedTime); | ||
| // LeanTween.delayedCall(gameObject, 1, delayedCallCallback); // pass an object of type GameObject value in case you want the tween to quit if this gameObject is ever destroyed (this is useful with tweens the might be interrupted when a new level is loaded). | ||
| } | ||
|
|
||
| function delayedCallExampleCallback(){ | ||
| Debug.Log("Delayed function was called"); | ||
| var currentScale:Vector3 = gameObject.transform.localScale; | ||
| LeanTween.scale( ltLogo, new Vector3(currentScale.x-0.2,currentScale.y-0.2,currentScale.z-0.2), 0.5).setEase(LeanTweenType.easeInOutCirc).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function alphaExample(){ | ||
| Debug.Log("alphaExample"); | ||
|
|
||
| var cube:GameObject = GameObject.Find ("LCharacter"); | ||
| LeanTween.alpha( cube, 0.0f, 0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.alpha( cube, 1.0f, 0.5f).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function moveLocalExample(){ | ||
| Debug.Log("moveLocalExample"); | ||
|
|
||
| var cube:GameObject = GameObject.Find ("LCharacter"); | ||
| var origPos:Vector3 = cube.transform.localPosition; | ||
| LeanTween.moveLocal( cube, new Vector3(0.0f,2.0f,0.0f), 0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| LeanTween.moveLocal( cube, origPos, 0.5f).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function rotateAroundExample(){ | ||
| Debug.Log("rotateAroundExample"); | ||
|
|
||
| var cube:GameObject = GameObject.Find ("LCharacter"); | ||
| LeanTween.rotateAround( cube, Vector3.up, 360.0f, 1.0f ).setUseEstimatedTime(useEstimatedTime); | ||
| } | ||
|
|
||
| function moveXExample(){ | ||
| LeanTween.moveX( ltLogo, 5, 0.5); | ||
| } | ||
|
|
||
| function rotateXExample(){ | ||
|
|
||
| } | ||
|
|
||
| function scaleXExample(){ | ||
|
|
||
| } | ||
|
|
||
| private var moveId:LTDescr; | ||
| private var pingPongDescrId:int; | ||
|
|
||
| function loopPause(){ | ||
| moveId.pause(); | ||
| } | ||
|
|
||
| function loopResume(){ | ||
| moveId.resume(); | ||
| } | ||
|
|
||
| function loopCancel(){ | ||
| LeanTween.cancel( pingPongDescrId ); | ||
| } |