TestingPunch.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using UnityEngine;
  2. using System.Collections;
  3. using DentedPixel;
  4. public class TestingPunch : MonoBehaviour {
  5. public AnimationCurve exportCurve;
  6. public float overShootValue = 1f;
  7. private LTDescr descr;
  8. void Start () {
  9. //LeanTween.rotateAround(gameObject, gameObject.transform.rotation.eulerAngles, 360f, 5f).setDelay(1f).setEase(LeanTweenType.easeOutBounce);
  10. Debug.Log( "exported curve:" + curveToString(exportCurve) );
  11. }
  12. void Update ()
  13. {
  14. LeanTween.dtManual = Time.deltaTime;
  15. if (Input.GetKeyDown(KeyCode.Q))
  16. {
  17. //LeanTween.scale(this.gameObject, Vector3.one*3f, 1.0f).setEase(LeanTweenType.easeSpring).setUseManualTime(true);
  18. //print("scale punch time independent!");
  19. LeanTween.moveLocalX(gameObject, 5, 1).setOnComplete( () => {
  20. Debug.Log("on complete move local X");
  21. }).setOnCompleteOnStart(true);
  22. GameObject light = GameObject.Find("DirectionalLight");
  23. Light lt = light.GetComponent<Light>();
  24. LeanTween.value(lt.gameObject, lt.intensity, 0.0f, 1.5f)
  25. .setEase(LeanTweenType.linear)
  26. .setLoopPingPong()
  27. .setRepeat(-1)
  28. .setOnUpdate((float val)=>{
  29. lt.intensity = val;
  30. });
  31. }
  32. if (Input.GetKeyDown(KeyCode.S))
  33. {
  34. print("scale punch!");
  35. tweenStatically( this.gameObject );
  36. LeanTween.scale(this.gameObject, new Vector3(1.15f, 1.15f, 1.15f), 0.6f);
  37. LeanTween.rotateAround(this.gameObject, Vector3.forward, -360f, 0.3f).setOnComplete(() =>
  38. {
  39. LeanTween.rotateAround(this.gameObject, Vector3.forward, -360f, 0.4f).setOnComplete(() =>
  40. {
  41. LeanTween.scale(this.gameObject, new Vector3(1f, 1f, 1f), 0.1f);
  42. LeanTween.value(this.gameObject, (v) =>
  43. {
  44. }, 0, 1, 0.3f).setDelay(1);
  45. });
  46. });
  47. }
  48. if (Input.GetKeyDown(KeyCode.T))
  49. {
  50. Vector3[] pts = new Vector3[] {new Vector3(-1f,0f,0f), new Vector3(0f,0f,0f), new Vector3(4f,0f,0f), new Vector3(20f,0f,0f)};
  51. descr = LeanTween.move(gameObject, pts, 15f).setOrientToPath(true).setDirection(1f).setOnComplete( ()=>{
  52. Debug.Log("move path finished");
  53. });
  54. }
  55. if (Input.GetKeyDown(KeyCode.Y)) // Reverse the move path
  56. {
  57. descr.setDirection(-descr.direction);
  58. }
  59. if (Input.GetKeyDown(KeyCode.R))
  60. {
  61. // LeanTween.rotate(this.gameObject, Vector3.one, 1.0f).setEase(LeanTweenType.punch);
  62. LeanTween.rotateAroundLocal(this.gameObject, this.transform.forward, -80f, 5.0f).setPoint(new Vector3(1.25f, 0f, 0f));
  63. print("rotate punch!");
  64. }
  65. if (Input.GetKeyDown(KeyCode.M))
  66. {
  67. // LeanTween.move(this.gameObject, new Vector3(0f,0f,1f), 1.0f).setEase(LeanTweenType.punch);
  68. print("move punch!");
  69. Time.timeScale = 0.25f;
  70. float start = Time.realtimeSinceStartup;
  71. LeanTween.moveX( this.gameObject, 1f, 1f).setOnComplete( destroyOnComp ).setOnCompleteParam( this.gameObject ).setOnComplete( ()=>{
  72. float end = Time.realtimeSinceStartup;
  73. float diff = end - start;
  74. Debug.Log("start:"+start+" end:"+end+" diff:"+diff+" x:"+this.gameObject.transform.position.x);
  75. }).setEase(LeanTweenType.easeInBack).setOvershoot( overShootValue ).setPeriod(0.3f);
  76. }
  77. if (Input.GetKeyDown(KeyCode.C))
  78. {
  79. LeanTween.color( this.gameObject, new Color(1f, 0f, 0f, 0.5f), 1f);
  80. Color to = new Color(Random.Range(0f,1f),0f,Random.Range(0f,1f),0.0f);
  81. GameObject l = GameObject.Find("LCharacter");
  82. LeanTween.color( l, to, 4.0f ).setLoopPingPong(1).setEase(LeanTweenType.easeOutBounce);
  83. }
  84. if (Input.GetKeyDown(KeyCode.E))
  85. {
  86. LeanTween.delayedCall(gameObject,0.3f, delayedMethod).setRepeat(4).setOnCompleteOnRepeat(true).setOnCompleteParam( "hi" );
  87. }
  88. if (Input.GetKeyDown(KeyCode.V))
  89. {
  90. LeanTween.value( gameObject, updateColor, new Color(1.0f,0.0f,0.0f,1.0f), Color.blue, 4.0f );//.setRepeat(2).setLoopPingPong().setEase(LeanTweenType.easeOutBounce);
  91. }
  92. if (Input.GetKeyDown(KeyCode.P))
  93. {
  94. LeanTween.delayedCall(0.05f, enterMiniGameStart).setOnCompleteParam( new object[]{""+5} );
  95. }
  96. if(Input.GetKeyDown(KeyCode.U)){
  97. #if !UNITY_FLASH
  98. LeanTween.value(gameObject, (Vector2 val)=>{
  99. // Debug.Log("tweening vec2 val:"+val);
  100. transform.position = new Vector3(val.x, transform.position.y, transform.position.z);
  101. }, new Vector2(0f,0f), new Vector2(5f,100f), 1f ).setEase(LeanTweenType.easeOutBounce);
  102. GameObject l = GameObject.Find("LCharacter");
  103. Debug.Log("x:"+l.transform.position.x+" y:"+l.transform.position.y);
  104. LeanTween.value(l, new Vector2( l.transform.position.x, l.transform.position.y), new Vector2( l.transform.position.x, l.transform.position.y+5), 1f ).setOnUpdate(
  105. (Vector2 val)=>{
  106. Debug.Log("tweening vec2 val:"+val);
  107. l.transform.position = new Vector3(val.x, val.y, transform.position.z);
  108. }
  109. );
  110. #endif
  111. }
  112. }
  113. static void tweenStatically( GameObject gameObject ){
  114. Debug.Log("Starting to tween...");
  115. LeanTween.value(gameObject, (val)=>{
  116. Debug.Log("tweening val:"+val);
  117. }, 0f, 1f, 1f);
  118. }
  119. void enterMiniGameStart( object val ){
  120. object[] arr = (object [])val;
  121. int lvl = int.Parse((string)arr[0]);
  122. Debug.Log("level:"+lvl);
  123. }
  124. void updateColor( Color c ){
  125. GameObject l = GameObject.Find("LCharacter");
  126. // Debug.Log("new col:"+c);
  127. l.GetComponent<Renderer>().material.color = c;
  128. }
  129. void delayedMethod( object myVal ){
  130. string castBack = myVal as string;
  131. Debug.Log("delayed call:"+Time.time +" myVal:"+castBack);
  132. }
  133. void destroyOnComp( object p ){
  134. GameObject g = (GameObject)p;
  135. Destroy( g );
  136. }
  137. string curveToString( AnimationCurve curve) {
  138. string str = "";
  139. for(int i = 0; i < curve.length; i++){
  140. str += "new Keyframe("+curve[i].time+"f, "+curve[i].value+"f)";
  141. if(i<curve.length-1)
  142. str += ", ";
  143. }
  144. return "new AnimationCurve( "+str+" )";
  145. }
  146. }