You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.3 KiB

7 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. using DentedPixel;
  4. public class GeneralBasicCS : MonoBehaviour {
  5. public GameObject prefabAvatar;
  6. void Start () {
  7. // Setup
  8. GameObject avatarRotate = GameObject.Find("AvatarRotate");
  9. GameObject avatarScale = GameObject.Find("AvatarScale");
  10. GameObject avatarMove = GameObject.Find("AvatarMove");
  11. // Rotate Example
  12. LeanTween.rotateAround( avatarRotate, Vector3.forward, 360f, 5f);
  13. // Scale Example
  14. LeanTween.scale( avatarScale, new Vector3(1.7f, 1.7f, 1.7f), 5f).setEase(LeanTweenType.easeOutBounce);
  15. LeanTween.moveX( avatarScale, avatarScale.transform.position.x + 5f, 5f).setEase(LeanTweenType.easeOutBounce); // Simultaneously target many different tweens on the same object
  16. // Move Example
  17. LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-9f, 0f, 1f), 2f).setEase(LeanTweenType.easeInQuad);
  18. // Delay
  19. LeanTween.move( avatarMove, avatarMove.transform.position + new Vector3(-6f, 0f, 1f), 2f).setDelay(3f);
  20. // Chain properties (delay, easing with a set repeating of type ping pong)
  21. LeanTween.scale( avatarScale, new Vector3(0.2f, 0.2f, 0.2f), 1f).setDelay(7f).setEase(LeanTweenType.easeInOutCirc).setLoopPingPong( 3 );
  22. // Call methods after a certain time period
  23. LeanTween.delayedCall(gameObject, 0.2f, advancedExamples);
  24. }
  25. // Advanced Examples
  26. // It might be best to master the basics first, but this is included to tease the many possibilies LeanTween provides.
  27. void advancedExamples(){
  28. LeanTween.delayedCall(gameObject, 14f, ()=>{
  29. for(int i=0; i < 10; i++){
  30. // Instantiate Container
  31. GameObject rotator = new GameObject("rotator"+i);
  32. rotator.transform.position = new Vector3(10.2f,2.85f,0f);
  33. // Instantiate Avatar
  34. GameObject dude = (GameObject)GameObject.Instantiate(prefabAvatar, Vector3.zero, prefabAvatar.transform.rotation );
  35. dude.transform.parent = rotator.transform;
  36. dude.transform.localPosition = new Vector3(0f,1.5f,2.5f*i);
  37. // Scale, pop-in
  38. dude.transform.localScale = new Vector3(0f,0f,0f);
  39. LeanTween.scale(dude, new Vector3(0.65f,0.65f,0.65f), 1f).setDelay(i*0.2f).setEase(LeanTweenType.easeOutBack);
  40. // Color like the rainbow
  41. float period = LeanTween.tau/10*i;
  42. float red = Mathf.Sin(period + LeanTween.tau*0f/3f) * 0.5f + 0.5f;
  43. float green = Mathf.Sin(period + LeanTween.tau*1f/3f) * 0.5f + 0.5f;
  44. float blue = Mathf.Sin(period + LeanTween.tau*2f/3f) * 0.5f + 0.5f;
  45. Color rainbowColor = new Color(red, green, blue);
  46. LeanTween.color(dude, rainbowColor, 0.3f).setDelay(1.2f + i*0.4f);
  47. // Push into the wheel
  48. LeanTween.moveZ(dude, 0f, 0.3f).setDelay(1.2f + i*0.4f).setEase(LeanTweenType.easeSpring).setOnComplete(
  49. ()=>{
  50. LeanTween.rotateAround(rotator, Vector3.forward, -1080f, 12f);
  51. }
  52. );
  53. // Jump Up and back down
  54. LeanTween.moveLocalY(dude,4f,1.2f).setDelay(5f + i*0.2f).setLoopPingPong(1).setEase(LeanTweenType.easeInOutQuad);
  55. // Alpha Out, and destroy
  56. LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete(
  57. ()=>{
  58. Destroy( rotator ); // destroying parent as well
  59. }
  60. );
  61. }
  62. }).setOnCompleteOnStart(true).setRepeat(-1); // Have the OnComplete play in the beginning and have the whole group repeat endlessly
  63. }
  64. }