This commit is contained in:
Gerard Gascón 2025-04-24 17:37:25 +02:00
commit 341a877b4a
2338 changed files with 1346408 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 950dff8c2dd5346409806b627ff3691f

View file

@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Following : MonoBehaviour {
public Transform planet;
public Transform followArrow;
public Transform dude1;
public Transform dude2;
public Transform dude3;
public Transform dude4;
public Transform dude5;
public Transform dude1Title;
public Transform dude2Title;
public Transform dude3Title;
public Transform dude4Title;
public Transform dude5Title;
private Color dude1ColorVelocity;
private Vector3 velocityPos;
private void Start()
{
followArrow.gameObject.LeanDelayedCall(3f, moveArrow).setOnStart(moveArrow).setRepeat(-1);
// Follow Local Y Position of Arrow
LeanTween.followDamp(dude1, followArrow, LeanProp.localY, 1.1f);
LeanTween.followSpring(dude2, followArrow, LeanProp.localY, 1.1f);
LeanTween.followBounceOut(dude3, followArrow, LeanProp.localY, 1.1f);
LeanTween.followSpring(dude4, followArrow, LeanProp.localY, 1.1f, -1f, 1.5f, 0.8f);
LeanTween.followLinear(dude5, followArrow, LeanProp.localY, 50f);
// Follow Arrow color
LeanTween.followDamp(dude1, followArrow, LeanProp.color, 1.1f);
LeanTween.followSpring(dude2, followArrow, LeanProp.color, 1.1f);
LeanTween.followBounceOut(dude3, followArrow, LeanProp.color, 1.1f);
LeanTween.followSpring(dude4, followArrow, LeanProp.color, 1.1f, -1f, 1.5f, 0.8f);
LeanTween.followLinear(dude5, followArrow, LeanProp.color, 0.5f);
// Follow Arrow scale
LeanTween.followDamp(dude1, followArrow, LeanProp.scale, 1.1f);
LeanTween.followSpring(dude2, followArrow, LeanProp.scale, 1.1f);
LeanTween.followBounceOut(dude3, followArrow, LeanProp.scale, 1.1f);
LeanTween.followSpring(dude4, followArrow, LeanProp.scale, 1.1f, -1f, 1.5f, 0.8f);
LeanTween.followLinear(dude5, followArrow, LeanProp.scale, 5f);
// Titles
var titleOffset = new Vector3(0.0f, -20f, -18f);
LeanTween.followDamp(dude1Title, dude1, LeanProp.localPosition, 0.6f).setOffset(titleOffset);
LeanTween.followSpring(dude2Title, dude2, LeanProp.localPosition, 0.6f).setOffset(titleOffset);
LeanTween.followBounceOut(dude3Title, dude3, LeanProp.localPosition, 0.6f).setOffset(titleOffset);
LeanTween.followSpring(dude4Title, dude4, LeanProp.localPosition, 0.6f, -1f, 1.5f, 0.8f).setOffset(titleOffset);
LeanTween.followLinear(dude5Title, dude5, LeanProp.localPosition, 30f).setOffset(titleOffset);
// Rotate Planet
var localPos = Camera.main.transform.InverseTransformPoint(planet.transform.position);
LeanTween.rotateAround(Camera.main.gameObject, Vector3.left, 360f, 300f).setPoint(localPos).setRepeat(-1);
}
private float fromY;
private float velocityY;
private Vector3 fromVec3;
private Vector3 velocityVec3;
private Color fromColor;
private Color velocityColor;
private void Update()
{
// Use the smooth methods to follow variables in which ever manner you wish!
fromY = LeanSmooth.spring(fromY, followArrow.localPosition.y, ref velocityY, 1.1f);
fromVec3 = LeanSmooth.spring(fromVec3, dude5Title.localPosition, ref velocityVec3, 1.1f);
fromColor = LeanSmooth.spring(fromColor, dude1.GetComponent<Renderer>().material.color, ref velocityColor, 1.1f);
Debug.Log("Smoothed y:" + fromY + " vec3:" + fromVec3 + " color:" + fromColor);
}
private void moveArrow()
{
LeanTween.moveLocalY(followArrow.gameObject, Random.Range(-100f, 100f), 0f);
var randomCol = new Color(Random.value, Random.value, Random.value);
LeanTween.color(followArrow.gameObject, randomCol, 0f);
var randomVal = Random.Range(5f, 10f);
followArrow.localScale = Vector3.one * randomVal;
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7e619db3c84234f098b8636588c25e4f
timeCreated: 1535223435
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a4fce1b486cc240c4825b3bfd794e9e0
timeCreated: 1461150844
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,83 @@
using UnityEngine;
using System.Collections;
using DentedPixel;
public class GeneralBasic : 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
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a2605544ab2e14c93a780ca20c108cfe
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,102 @@
using UnityEngine;
using System.Collections;
using DentedPixel;
public class GeneralBasics2d : 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
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9b39dd70d168b4cbea9a7b8561d9accc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -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

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8a650682fa3d54a57a2521dbf9f6eac2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -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);
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 94e9a883a33cd40b9be1a63f002c4db2
timeCreated: 1471950328
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,83 @@
#if !UNITY_FLASH
using UnityEngine;
using System.Collections;
using DentedPixel;
public class GeneralEventsListeners : 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

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: cd679d4fbbd8d475ba7187561370c3aa
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,61 @@
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(); // not working yet
// Testing canceling sequence after a bit of time
//LeanTween.delayedCall(3f, () =>
//{
// LeanTween.cancel(seq.id);
//});
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5b54bce4a9ed14e28a4a423c794a2d70
timeCreated: 1488722358
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,56 @@
using UnityEngine;
using System.Collections;
using DentedPixel;
public class GeneralSimpleUI : 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
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 19c352f230e8b46f08abbbd7cc11edb8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,89 @@
using UnityEngine;
using System.Collections;
using DentedPixel;
public class GeneralUISpace : 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();
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cc2ddccee016148b189d987f564ee08e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -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~~
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 674f3c10d8880408e875a9e6c3ee83bb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -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
}
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ac2038ba3961049ed889ae71039982cd
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,32 @@
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};
// 90 degree test
// path = new Vector3[] {new Vector3(7.5f, 0f, 0f), new Vector3(0f, 0f, 2.5f), new Vector3(2.5f, 0f, 0f), new Vector3(0f, 0f, 7.5f)};
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
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 873cb511c724a48bd919ce8a18fa882c
timeCreated: 1493586162
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ef4235237d8d8413c9d5807cf0a1f77b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -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();
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 15c036b11e3ff486ea685da06fa305f6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,125 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DentedPixel;
public class PathSplineEndless : 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
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 784f0e347ee4d4c3b83ca56d6f33f01a
timeCreated: 1460315101
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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 PathSplinePerformance : 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
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5de62495c8a5d49e6b3ca111f8c7e944
timeCreated: 1460894008
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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 PathSplineTrack : 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
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 31af73f8be2864eda9a3fbb6d0d2a9c7
timeCreated: 1460209336
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: de0396ae3eef541c190f0e6962090454
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,647 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DentedPixel;
namespace DentedPixel.LTExamples
{
public class TestingUnitTests : MonoBehaviour
{
public GameObject cube1;
public GameObject cube2;
public GameObject cube3;
public GameObject cube4;
public GameObject cubeAlpha1;
public GameObject cubeAlpha2;
private bool eventGameObjectWasCalled = false, eventGeneralWasCalled = false;
private int lt1Id;
private LTDescr lt2;
private LTDescr lt3;
private LTDescr lt4;
private LTDescr[] groupTweens;
private GameObject[] groupGOs;
private int groupTweensCnt;
private int rotateRepeat;
private int rotateRepeatAngle;
private GameObject boxNoCollider;
private float timeElapsedNormalTimeScale;
private float timeElapsedIgnoreTimeScale;
private bool pauseTweenDidFinish = false;
void Awake()
{
boxNoCollider = GameObject.CreatePrimitive(PrimitiveType.Cube);
Destroy(boxNoCollider.GetComponent(typeof(BoxCollider)) as Component);
}
void Start()
{
// Time.timeScale = 0.25f;
LeanTest.timeout = 46f;
LeanTest.expected = 62;
LeanTween.init(1300);
// add a listener
LeanTween.addListener(cube1, 0, eventGameObjectCalled);
LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING");
LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING");
LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => {
LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME");
});
// dispatch event that is received
LeanTween.dispatchEvent(0);
LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED");
// do not remove listener
LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED");
// remove listener
LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED");
// add a listener
LeanTween.addListener(1, eventGeneralCalled);
// dispatch event that is received
LeanTween.dispatchEvent(1);
LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED");
// remove listener
LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED");
lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id;
LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f);
LeanTween.reset();
// Queue up a bunch of tweens, cancel some of them but expect the remainder to finish
GameObject[] cubes = new GameObject[99];
int[] tweenIds = new int[cubes.Length];
for (int i = 0; i < cubes.Length; i++)
{
GameObject c = cubeNamed("cancel" + i);
tweenIds[i] = LeanTween.moveX(c, 100f, 1f).id;
cubes[i] = c;
}
int onCompleteCount = 0;
LeanTween.delayedCall(cubes[0], 0.2f, () => {
for (int i = 0; i < cubes.Length; i++)
{
if (i % 3 == 0)
{
LeanTween.cancel(cubes[i]);
}
else if (i % 3 == 1)
{
LeanTween.cancel(tweenIds[i]);
}
else if (i % 3 == 2)
{
LTDescr descr = LeanTween.descr(tweenIds[i]);
// Debug.Log("descr:"+descr);
descr.setOnComplete(() => {
onCompleteCount++;
// Debug.Log("onCompleteCount:"+onCompleteCount);
if (onCompleteCount >= 33)
{
LeanTest.expect(true, "CANCELS DO NOT EFFECT FINISHING");
}
});
}
}
});
Vector3[] splineArr = 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) };
LTSpline cr = new LTSpline(splineArr);
cr.place(cube4.transform, 0.5f);
LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)");
LeanTween.color(cube4, Color.green, 0.01f);
// Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2]));
// OnStart Speed Test for ignoreTimeScale vs normal timeScale
GameObject cubeDest = cubeNamed("cubeDest");
Vector3 cubeDestEnd = new Vector3(100f, 20f, 0f);
LeanTween.move(cubeDest, cubeDestEnd, 0.7f);
GameObject cubeToTrans = cubeNamed("cubeToTrans");
LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => {
LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS");
});
GameObject cubeDestroy = cubeNamed("cubeDestroy");
LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true);
LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => {
LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED");
});
GameObject cubeSpline = cubeNamed("cubeSpline");
LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => {
LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS");
});
// This test works when it is positioned last in the test queue (probably worth fixing when you have time)
GameObject jumpCube = cubeNamed("jumpTime");
jumpCube.transform.position = new Vector3(100f, 0f, 0f);
jumpCube.transform.localScale *= 100f;
int jumpTimeId = LeanTween.moveX(jumpCube, 200f, 1f).id;
LeanTween.delayedCall(gameObject, 0.2f, () => {
LTDescr d = LeanTween.descr(jumpTimeId);
float beforeX = jumpCube.transform.position.x;
d.setTime(0.5f);
LeanTween.delayedCall(0.0f, () => { }).setOnStart(() => {
float diffAmt = 1f;// This variable is dependent on a good frame-rate because it evalutes at the next Update
beforeX += Time.deltaTime * 100f * 2f;
LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < diffAmt, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX) + " beforeX:" + beforeX + " now:" + jumpCube.transform.position.x + " dt:" + Time.deltaTime);
});
});
// Tween with time of zero is needs to be set to it's final value
GameObject zeroCube = cubeNamed("zeroCube");
LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() => {
LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:" + zeroCube.transform.position.x);
});
// Scale, and OnStart
GameObject cubeScale = cubeNamed("cubeScale");
LeanTween.scale(cubeScale, new Vector3(5f, 5f, 5f), 0.01f).setOnStart(() => {
LeanTest.expect(true, "ON START WAS CALLED");
}).setOnComplete(() => {
LeanTest.expect(cubeScale.transform.localScale.z == 5f, "SCALE", "expected scale z:" + 5f + " returned:" + cubeScale.transform.localScale.z);
});
// Rotate
GameObject cubeRotate = cubeNamed("cubeRotate");
LeanTween.rotate(cubeRotate, new Vector3(0f, 180f, 0f), 0.02f).setOnComplete(() => {
LeanTest.expect(cubeRotate.transform.eulerAngles.y == 180f, "ROTATE", "expected rotate y:" + 180f + " returned:" + cubeRotate.transform.eulerAngles.y);
});
// RotateAround
GameObject cubeRotateA = cubeNamed("cubeRotateA");
LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() => {
LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND", "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z);
});
// RotateAround 360
GameObject cubeRotateB = cubeNamed("cubeRotateB");
cubeRotateB.transform.position = new Vector3(200f, 10f, 8f);
LeanTween.rotateAround(cubeRotateB, Vector3.forward, 360f, 0.3f).setPoint(new Vector3(5f, 3f, 2f)).setOnComplete(() => {
LeanTest.expect(cubeRotateB.transform.position.ToString() == (new Vector3(200f, 10f, 8f)).ToString(), "ROTATE AROUND 360", "expected rotate pos:" + (new Vector3(200f, 10f, 8f)) + " returned:" + cubeRotateB.transform.position);
});
// Alpha, onUpdate with passing value, onComplete value
LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate((float val) => {
LeanTest.expect(val != 0f, "ON UPDATE VAL");
}).setOnCompleteParam("Hi!").setOnComplete((object completeObj) => {
LeanTest.expect(((string)completeObj) == "Hi!", "ONCOMPLETE OBJECT");
LeanTest.expect(cubeAlpha1.GetComponent<Renderer>().material.color.a == 0.5f, "ALPHA");
});
// Color
float onStartTime = -1f;
LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete(() => {
LeanTest.expect(cubeAlpha2.GetComponent<Renderer>().material.color == Color.cyan, "COLOR");
LeanTest.expect(onStartTime >= 0f && onStartTime < Time.time, "ON START", "onStartTime:" + onStartTime + " time:" + Time.time);
}).setOnStart(() => {
onStartTime = Time.time;
});
// moveLocalY (make sure uses y values)
Vector3 beforePos = cubeAlpha1.transform.position;
LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete(() => {
LeanTest.expect(cubeAlpha1.transform.position.x == beforePos.x && cubeAlpha1.transform.position.z == beforePos.z, "MOVE Y");
});
Vector3 beforePos2 = cubeAlpha2.transform.localPosition;
LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete(() => {
LeanTest.expect(cubeAlpha2.transform.localPosition.x == beforePos2.x && cubeAlpha2.transform.localPosition.y == beforePos2.y, "MOVE LOCAL Z", "ax:" + cubeAlpha2.transform.localPosition.x + " bx:" + beforePos.x + " ay:" + cubeAlpha2.transform.localPosition.y + " by:" + beforePos2.y);
});
AudioClip audioClip = LeanAudio.createAudio(new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)), new AnimationCurve(new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)), LeanAudio.options());
LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f, 0f, 0f), 0.1f).setDelay(0.2f).setOnComplete(() => {
LeanTest.expect(Time.time > 0, "DELAYED SOUND");
});
// Easing Methods
int totalEasingCheck = 0;
int totalEasingCheckSuccess = 0;
for (int j = 0; j < 2; j++)
{
bool isCheckingFrom = j == 1;
int totalTweenTypeLength = (int)LeanTweenType.easeShake;
for (int i = (int)LeanTweenType.notUsed; i < totalTweenTypeLength; i++)
{
LeanTweenType easeType = (LeanTweenType)i;
GameObject cube = cubeNamed("cube" + easeType);
LTDescr descr = LeanTween.moveLocalX(cube, 5, 0.1f).setOnComplete((object obj) => {
GameObject cubeIn = obj as GameObject;
totalEasingCheck++;
if (cubeIn.transform.position.x == 5f)
{
totalEasingCheckSuccess++;
}
if (totalEasingCheck == (2 * totalTweenTypeLength))
{
LeanTest.expect(totalEasingCheck == totalEasingCheckSuccess, "EASING TYPES");
}
}).setOnCompleteParam(cube);
if (isCheckingFrom)
descr.setFrom(-5f);
}
}
// value2
bool value2UpdateCalled = false;
LeanTween.value(gameObject, new Vector2(0, 0), new Vector2(256, 96), 0.1f).setOnUpdate((Vector2 value) => {
value2UpdateCalled = true;
});
LeanTween.delayedCall(0.2f, () => {
LeanTest.expect(value2UpdateCalled, "VALUE2 UPDATE");
});
// check descr
// LTDescr descr2 = LeanTween.descr( descrId );
// LeanTest.expect(descr2 == null,"DESCRIPTION STARTS AS NULL");
StartCoroutine(timeBasedTesting());
}
private GameObject cubeNamed(string name)
{
GameObject cube = Instantiate(boxNoCollider) as GameObject;
cube.name = name;
return cube;
}
IEnumerator timeBasedTesting()
{
yield return new WaitForEndOfFrame();
GameObject cubeNormal = cubeNamed("normalTimeScale");
// float timeElapsedNormal = Time.time;
LeanTween.moveX(cubeNormal, 12f, 1.5f).setIgnoreTimeScale(false).setOnComplete(() => {
timeElapsedNormalTimeScale = Time.time;
});
LTDescr[] descr = LeanTween.descriptions(cubeNormal);
LeanTest.expect(descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION");
GameObject cubeIgnore = cubeNamed("ignoreTimeScale");
LeanTween.moveX(cubeIgnore, 5f, 1.5f).setIgnoreTimeScale(true).setOnComplete(() => {
timeElapsedIgnoreTimeScale = Time.time;
});
yield return new WaitForSeconds(1.5f);
LeanTest.expect(Mathf.Abs(timeElapsedNormalTimeScale - timeElapsedIgnoreTimeScale) < 0.7f, "START IGNORE TIMING", "timeElapsedIgnoreTimeScale:" + timeElapsedIgnoreTimeScale + " timeElapsedNormalTimeScale:" + timeElapsedNormalTimeScale);
// yield return new WaitForSeconds(100f);
Time.timeScale = 4f;
int pauseCount = 0;
LeanTween.value(gameObject, 0f, 1f, 1f).setOnUpdate((float val) => {
pauseCount++;
}).pause();
// Bezier should end at exact end position not just 99% close to it
Vector3[] roundCirc = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(-9.1f, 25.1f, 0f), new Vector3(-1.2f, 15.9f, 0f), new Vector3(-25f, 25f, 0f), new Vector3(-25f, 25f, 0f), new Vector3(-50.1f, 15.9f, 0f), new Vector3(-40.9f, 25.1f, 0f), new Vector3(-50f, 0f, 0f), new Vector3(-50f, 0f, 0f), new Vector3(-40.9f, -25.1f, 0f), new Vector3(-50.1f, -15.9f, 0f), new Vector3(-25f, -25f, 0f), new Vector3(-25f, -25f, 0f), new Vector3(0f, -15.9f, 0f), new Vector3(-9.1f, -25.1f, 0f), new Vector3(0f, 0f, 0f) };
GameObject cubeRound = cubeNamed("bRound");
Vector3 onStartPos = cubeRound.transform.position;
LeanTween.moveLocal(cubeRound, roundCirc, 0.5f).setOnComplete(() => {
LeanTest.expect(cubeRound.transform.position == onStartPos, "BEZIER CLOSED LOOP SHOULD END AT START", "onStartPos:" + onStartPos + " onEnd:" + cubeRound.transform.position);
});
// should be able to retrieve a point
LTBezierPath roundCircPath = new LTBezierPath(roundCirc);
float ratioPoint = roundCircPath.ratioAtPoint(new Vector3(-25f, 25f, 0f));
LeanTest.expect(Mathf.Equals(ratioPoint, 0.25f), "BEZIER RATIO POINT");
// Spline should end at exact end position not just 99% close to it
Vector3[] roundSpline = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(2f, 0f, 0f), new Vector3(0.9f, 2f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f) };
GameObject cubeSpline = cubeNamed("bSpline");
Vector3 onStartPosSpline = cubeSpline.transform.position;
LeanTween.moveSplineLocal(cubeSpline, roundSpline, 0.5f).setOnComplete(() => {
LeanTest.expect(Vector3.Distance(onStartPosSpline, cubeSpline.transform.position) <= 0.01f, "SPLINE CLOSED LOOP SHOULD END AT START", "onStartPos:" + onStartPosSpline + " onEnd:" + cubeSpline.transform.position + " dist:" + Vector3.Distance(onStartPosSpline, cubeSpline.transform.position));
});
// Sequence test, do three tweens and make sure they end at the right points
GameObject cubeSeq = cubeNamed("cSeq");
var seq = LeanTween.sequence().append(LeanTween.moveX(cubeSeq, 100f, 0.2f));
seq.append(0.1f).append(LeanTween.scaleX(cubeSeq, 2f, 0.1f));
seq.append(() => {
LeanTest.expect(cubeSeq.transform.position.x == 100f, "SEQ MOVE X FINISHED", "move x:" + cubeSeq.transform.position.x);
LeanTest.expect(cubeSeq.transform.localScale.x == 2f, "SEQ SCALE X FINISHED", "scale x:" + cubeSeq.transform.localScale.x);
}).setScale(0.2f);
// Bounds check
GameObject cubeBounds = cubeNamed("cBounds");
bool didPassBounds = true;
Vector3 failPoint = Vector3.zero;
LeanTween.move(cubeBounds, new Vector3(10, 10, 10), 0.1f).setOnUpdate((float val) => {
// Debug.LogWarning("cubeBounds x:"+cubeBounds.transform.position.x + " y:"+ cubeBounds.transform.position.y+" z:"+cubeBounds.transform.position.z);
if (cubeBounds.transform.position.x < 0f || cubeBounds.transform.position.x > 10f || cubeBounds.transform.position.y < 0f || cubeBounds.transform.position.y > 10f || cubeBounds.transform.position.z < 0f || cubeBounds.transform.position.z > 10f)
{
didPassBounds = false;
failPoint = cubeBounds.transform.position;
// Debug.LogError("OUT OF BOUNDS");
}
}).setLoopPingPong().setRepeat(8).setOnComplete(() => {
LeanTest.expect(didPassBounds, "OUT OF BOUNDS", "pos x:" + failPoint.x + " y:" + failPoint.y + " z:" + failPoint.z);
});
// Local scale check
//GameObject cubeLocal = cubeNamed("cLocal");
//LeanTween.scale(cubeLocal, new Vector3(0.5f, 0.5f, 0.5f), 0.2f).setOnComplete(() =>
//{
// LeanTest.expect((cubeLocal.transform.localScale.x == 0.5f && cubeLocal.transform.localScale.y == 0.5f && cubeLocal.transform.localScale.z == 0.5f), "SCALE WORKS", "scale x:" + cubeLocal.transform.localScale.x + " y:" + cubeLocal.transform.localScale.y + " z:" + cubeLocal.transform.localScale.z);
//});
// Groups of tweens testing
groupTweens = new LTDescr[1200];
groupGOs = new GameObject[groupTweens.Length];
groupTweensCnt = 0;
int descriptionMatchCount = 0;
for (int i = 0; i < groupTweens.Length; i++)
{
GameObject cube = cubeNamed("c" + i);
cube.transform.position = new Vector3(0, 0, i * 3);
groupGOs[i] = cube;
}
yield return new WaitForEndOfFrame();
bool hasGroupTweensCheckStarted = false;
int setOnStartNum = 0;
int setPosNum = 0;
bool setPosOnUpdate = true;
for (int i = 0; i < groupTweens.Length; i++)
{
Vector3 finalPos = transform.position + Vector3.one * 3f;
Dictionary<string, object> finalDict = new Dictionary<string, object> { { "final", finalPos }, { "go", groupGOs[i] } };
groupTweens[i] = LeanTween.move(groupGOs[i], finalPos, 3f).setOnStart(() => {
setOnStartNum++;
}).setOnUpdate((Vector3 newPosition) => {
if (transform.position.z > newPosition.z)
{
setPosOnUpdate = false;
}
// Debug.LogWarning("New Position: " + newPosition.ToString());
}).
setOnCompleteParam(finalDict).
setOnComplete((object param) => {
Dictionary<string, object> finalDictRetr = param as Dictionary<string, object>;
Vector3 neededPos = (Vector3)finalDictRetr["final"];
GameObject tweenedGo = finalDictRetr["go"] as GameObject;
if (neededPos.ToString() == tweenedGo.transform.position.ToString())
setPosNum++;
else
{
// Debug.Log("neededPos:"+neededPos+" tweenedGo.transform.position:"+tweenedGo.transform.position);
}
if (hasGroupTweensCheckStarted == false)
{
hasGroupTweensCheckStarted = true;
LeanTween.delayedCall(gameObject, 0.1f, () => {
LeanTest.expect(setOnStartNum == groupTweens.Length, "SETONSTART CALLS", "expected:" + groupTweens.Length + " was:" + setOnStartNum);
LeanTest.expect(groupTweensCnt == groupTweens.Length, "GROUP FINISH", "expected " + groupTweens.Length + " tweens but got " + groupTweensCnt);
LeanTest.expect(setPosNum == groupTweens.Length, "GROUP POSITION FINISH", "expected " + groupTweens.Length + " tweens but got " + setPosNum);
LeanTest.expect(setPosOnUpdate, "GROUP POSITION ON UPDATE");
});
}
groupTweensCnt++;
});
if (LeanTween.description(groupTweens[i].id).trans == groupTweens[i].trans)
descriptionMatchCount++;
}
while (LeanTween.tweensRunning < groupTweens.Length)
yield return null;
LeanTest.expect(descriptionMatchCount == groupTweens.Length, "GROUP IDS MATCH");
int expectedSearch = groupTweens.Length + 7;
LeanTest.expect(LeanTween.maxSearch <= expectedSearch, "MAX SEARCH OPTIMIZED", "maxSearch:" + LeanTween.maxSearch + " should be:" + expectedSearch);
LeanTest.expect(LeanTween.isTweening() == true, "SOMETHING IS TWEENING");
// resume item before calling pause should continue item along it's way
float previousXlt4 = cube4.transform.position.x;
lt4 = LeanTween.moveX(cube4, 5.0f, 1.1f).setOnComplete(() => {
LeanTest.expect(cube4 != null && previousXlt4 != cube4.transform.position.x, "RESUME OUT OF ORDER", "cube4:" + cube4 + " previousXlt4:" + previousXlt4 + " cube4.transform.position.x:" + (cube4 != null ? cube4.transform.position.x : 0));
}).setDestroyOnComplete(true);
lt4.resume();
rotateRepeat = rotateRepeatAngle = 0;
LeanTween.rotateAround(cube3, Vector3.forward, 360f, 0.1f).setRepeat(3).setOnComplete(rotateRepeatFinished).setOnCompleteOnRepeat(true).setDestroyOnComplete(true);
yield return new WaitForEndOfFrame();
LeanTween.delayedCall(0.1f * 8f + 1f, rotateRepeatAllFinished);
int countBeforeCancel = LeanTween.tweensRunning;
LeanTween.cancel(lt1Id);
LeanTest.expect(countBeforeCancel == LeanTween.tweensRunning, "CANCEL AFTER RESET SHOULD FAIL", "expected " + countBeforeCancel + " but got " + LeanTween.tweensRunning);
LeanTween.cancel(cube2);
int tweenCount = 0;
for (int i = 0; i < groupTweens.Length; i++)
{
if (LeanTween.isTweening(groupGOs[i]))
tweenCount++;
if (i % 3 == 0)
LeanTween.pause(groupGOs[i]);
else if (i % 3 == 1)
groupTweens[i].pause();
else
LeanTween.pause(groupTweens[i].id);
}
LeanTest.expect(tweenCount == groupTweens.Length, "GROUP ISTWEENING", "expected " + groupTweens.Length + " tweens but got " + tweenCount);
yield return new WaitForEndOfFrame();
tweenCount = 0;
for (int i = 0; i < groupTweens.Length; i++)
{
if (i % 3 == 0)
LeanTween.resume(groupGOs[i]);
else if (i % 3 == 1)
groupTweens[i].resume();
else
LeanTween.resume(groupTweens[i].id);
if (i % 2 == 0 ? LeanTween.isTweening(groupTweens[i].id) : LeanTween.isTweening(groupGOs[i]))
tweenCount++;
}
LeanTest.expect(tweenCount == groupTweens.Length, "GROUP RESUME");
LeanTest.expect(LeanTween.isTweening(cube1) == false, "CANCEL TWEEN LTDESCR");
LeanTest.expect(LeanTween.isTweening(cube2) == false, "CANCEL TWEEN LEANTWEEN");
LeanTest.expect(pauseCount == 0, "ON UPDATE NOT CALLED DURING PAUSE", "expect pause count of 0, but got " + pauseCount);
yield return new WaitForEndOfFrame();
Time.timeScale = 0.25f;
float tweenTime = 0.2f;
float expectedTime = tweenTime * (1f / Time.timeScale);
float start = Time.realtimeSinceStartup;
bool onUpdateWasCalled = false;
LeanTween.moveX(cube1, -5f, tweenTime).setOnUpdate((float val) => {
onUpdateWasCalled = true;
}).setOnComplete(() => {
float end = Time.realtimeSinceStartup;
float diff = end - start;
LeanTest.expect(Mathf.Abs(expectedTime - diff) < 0.06f, "SCALED TIMING DIFFERENCE", "expected to complete in roughly " + expectedTime + " but completed in " + diff);
LeanTest.expect(Mathf.Approximately(cube1.transform.position.x, -5f), "SCALED ENDING POSITION", "expected to end at -5f, but it ended at " + cube1.transform.position.x);
LeanTest.expect(onUpdateWasCalled, "ON UPDATE FIRED");
});
bool didGetCorrectOnUpdate = false;
LeanTween.value(gameObject, new Vector3(1f, 1f, 1f), new Vector3(10f, 10f, 10f), 1f).setOnUpdate((Vector3 val) => {
didGetCorrectOnUpdate = val.x >= 1f && val.y >= 1f && val.z >= 1f;
}).setOnComplete(() => {
LeanTest.expect(didGetCorrectOnUpdate, "VECTOR3 CALLBACK CALLED");
});
yield return new WaitForSeconds(expectedTime);
Time.timeScale = 1f;
int ltCount = 0;
GameObject[] allGos = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach (GameObject go in allGos)
{
if (go.name == "~LeanTween")
ltCount++;
}
LeanTest.expect(ltCount == 1, "RESET CORRECTLY CLEANS UP");
StartCoroutine(lotsOfCancels());
}
IEnumerator lotsOfCancels()
{
yield return new WaitForEndOfFrame();
Time.timeScale = 4f;
int cubeCount = 10;
int[] tweensA = new int[cubeCount];
GameObject[] aGOs = new GameObject[cubeCount];
for (int i = 0; i < aGOs.Length; i++)
{
GameObject cube = Instantiate(boxNoCollider) as GameObject;
cube.transform.position = new Vector3(0, 0, i * 2f);
cube.name = "a" + i;
aGOs[i] = cube;
tweensA[i] = LeanTween.move(cube, cube.transform.position + new Vector3(10f, 0, 0), 0.5f + 1f * (1.0f / (float)aGOs.Length)).id;
LeanTween.color(cube, Color.red, 0.01f);
}
yield return new WaitForSeconds(1.0f);
int[] tweensB = new int[cubeCount];
GameObject[] bGOs = new GameObject[cubeCount];
for (int i = 0; i < bGOs.Length; i++)
{
GameObject cube = Instantiate(boxNoCollider) as GameObject;
cube.transform.position = new Vector3(0, 0, i * 2f);
cube.name = "b" + i;
bGOs[i] = cube;
tweensB[i] = LeanTween.move(cube, cube.transform.position + new Vector3(10f, 0, 0), 2f).id;
}
for (int i = 0; i < aGOs.Length; i++)
{
LeanTween.cancel(aGOs[i]);
GameObject cube = aGOs[i];
tweensA[i] = LeanTween.move(cube, new Vector3(0, 0, i * 2f), 2f).id;
}
yield return new WaitForSeconds(0.5f);
for (int i = 0; i < aGOs.Length; i++)
{
LeanTween.cancel(aGOs[i]);
GameObject cube = aGOs[i];
tweensA[i] = LeanTween.move(cube, new Vector3(0, 0, i * 2f) + new Vector3(10f, 0, 0), 2f).id;
}
for (int i = 0; i < bGOs.Length; i++)
{
LeanTween.cancel(bGOs[i]);
GameObject cube = bGOs[i];
tweensB[i] = LeanTween.move(cube, new Vector3(0, 0, i * 2f), 2f).id;
}
yield return new WaitForSeconds(2.1f);
bool inFinalPlace = true;
for (int i = 0; i < aGOs.Length; i++)
{
if (Vector3.Distance(aGOs[i].transform.position, new Vector3(0, 0, i * 2f) + new Vector3(10f, 0, 0)) > 0.1f)
inFinalPlace = false;
}
for (int i = 0; i < bGOs.Length; i++)
{
if (Vector3.Distance(bGOs[i].transform.position, new Vector3(0, 0, i * 2f)) > 0.1f)
inFinalPlace = false;
}
LeanTest.expect(inFinalPlace, "AFTER LOTS OF CANCELS");
GameObject cubePaused = cubeNamed("cPaused");
cubePaused.LeanMoveX(10f, 1f).setOnComplete(() => {
pauseTweenDidFinish = true;
});
StartCoroutine(pauseTimeNow());
}
IEnumerator pauseTimeNow()
{
yield return new WaitForSeconds(0.5f);
Time.timeScale = 0;
LeanTween.delayedCall(0.5f, () => {
Time.timeScale = 1f;
}).setUseEstimatedTime(true);
LeanTween.delayedCall(1.5f, () => {
LeanTest.expect(pauseTweenDidFinish, "PAUSE BY TIMESCALE FINISHES");
}).setUseEstimatedTime(true);
}
void rotateRepeatFinished()
{
if (Mathf.Abs(cube3.transform.eulerAngles.z) < 0.0001f)
rotateRepeatAngle++;
rotateRepeat++;
}
void rotateRepeatAllFinished()
{
LeanTest.expect(rotateRepeatAngle == 3, "ROTATE AROUND MULTIPLE", "expected 3 times received " + rotateRepeatAngle + " times");
LeanTest.expect(rotateRepeat == 3, "ROTATE REPEAT", "expected 3 times received " + rotateRepeat + " times");
LeanTest.expect(cube3 == null, "DESTROY ON COMPLETE", "cube3:" + cube3);
}
void eventGameObjectCalled(LTEvent e)
{
eventGameObjectWasCalled = true;
}
void eventGeneralCalled(LTEvent e)
{
eventGeneralWasCalled = true;
}
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fef58bd01146344429d022b95c6af872
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,233 @@
using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using DentedPixel;
public class TestingZLegacy : 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);
}
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ed8575995d061498aa84acbaf0b377de
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View file

@ -0,0 +1,269 @@
using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using DentedPixel;
public class TestingZLegacyExt : 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 Transform 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").transform;
LeanTween.delayedCall(1f, cycleThroughExamples);
origin = ltLogo.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 = gameObject.LeanValue(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;
gameObject.LeanDelayedCall( delayTime, cycleThroughExamples).setUseEstimatedTime(useEstimatedTime);
exampleIter = exampleIter + 1 >= exampleFunctions.Length ? 0 : exampleIter + 1;
}
public void updateValue3Example()
{
Debug.Log("updateValue3Example Time:" + Time.time);
gameObject.LeanValue( 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);
Transform cube1 = GameObject.Find("Cube1").transform;
cube1.localScale = new Vector3(1.0f, 1.0f, 1.0f);
cube1.LeanScaleZ( 4.0f, 1.0f).setEase(LeanTweenType.easeOutElastic).setRepeat(7).setLoopClamp().setUseEstimatedTime(useEstimatedTime);//
}
public void loopTestPingPong()
{
Debug.Log("loopTestPingPong Time:" + Time.time);
Transform cube2 = GameObject.Find("Cube2").transform;
cube2.localScale = new Vector3(1.0f, 1.0f, 1.0f);
cube2.LeanScaleY( 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");
lChar.LeanColor( 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 };
ltLogo.LeanMove( path, 1.0f).setEase(LeanTweenType.easeOutQuad).setOrientToPath(true).setUseEstimatedTime(useEstimatedTime);
}
public void customTweenExample()
{
Debug.Log("customTweenExample starting pos:" + ltLogo.position + " origin:" + origin);
ltLogo.LeanMoveX(-10.0f, 0.5f).setEase(customAnimationCurve).setUseEstimatedTime(useEstimatedTime);
ltLogo.LeanMoveX( 0.0f, 0.5f).setEase(customAnimationCurve).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime);
}
public void moveExample()
{
Debug.Log("moveExample");
ltLogo.LeanMove(new Vector3(-2f, -1f, 0f), 0.5f).setUseEstimatedTime(useEstimatedTime);
ltLogo.LeanMove(origin, 0.5f).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime);
}
public void rotateExample()
{
Debug.Log("rotateExample");
Hashtable returnParam = new Hashtable();
returnParam.Add("yo", 5.0);
ltLogo.LeanRotate(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.localScale;
ltLogo.LeanScale(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");
gameObject.LeanValue( (Action<float, object>)updateValueExampleCallback, ltLogo.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.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.localScale;
ltLogo.LeanScale( 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");
lChar.LeanAlpha( 0.0f, 0.5f).setUseEstimatedTime(useEstimatedTime);
lChar.LeanAlpha( 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;
lChar.LeanMoveLocal( new Vector3(0.0f, 2.0f, 0.0f), 0.5f).setUseEstimatedTime(useEstimatedTime);
lChar.LeanMoveLocal( origPos, 0.5f).setDelay(0.5f).setUseEstimatedTime(useEstimatedTime);
}
public void rotateAroundExample()
{
Debug.Log("rotateAroundExample");
GameObject lChar = GameObject.Find("LCharacter");
lChar.LeanRotateAround(Vector3.up, 360.0f, 1.0f).setUseEstimatedTime(useEstimatedTime);
}
public void loopPause()
{
GameObject cube1 = GameObject.Find("Cube1");
cube1.LeanPause();
}
public void loopResume()
{
GameObject cube1 = GameObject.Find("Cube1");
cube1.LeanResume();
}
public void punchTest()
{
ltLogo.LeanMoveX(7.0f, 1.0f).setEase(LeanTweenType.punch).setUseEstimatedTime(useEstimatedTime);
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c5a76b5b44fc4416a82391d1ab9ec33d
timeCreated: 1533844515
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: