AMAction.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [Serializable]
  5. public class AMAction : ScriptableObject
  6. {
  7. public AnimationCurve easeCurve
  8. {
  9. get
  10. {
  11. if (this._cachedEaseCurve == null || this._cachedEaseCurve.keys.Length <= 0)
  12. {
  13. this._cachedEaseCurve = this.getCustomEaseCurve();
  14. }
  15. return this._cachedEaseCurve;
  16. }
  17. }
  18. public virtual string ToString(int codeLanguage, int frameRate)
  19. {
  20. return "(Error: No override for ToString)";
  21. }
  22. public virtual void execute(int frameRate, float delayModifier, string trackId)
  23. {
  24. Debug.LogError("Animator: No override for execute.");
  25. }
  26. public float getWaitTime(int frameRate, float delay)
  27. {
  28. return ((float)this.startFrame - 1f) / (float)frameRate - delay;
  29. }
  30. public virtual int getNumberOfFrames()
  31. {
  32. return 1;
  33. }
  34. public void destroy()
  35. {
  36. UnityEngine.Object.DestroyImmediate(this);
  37. }
  38. public virtual AnimatorTimeline.JSONAction getJSONAction(int frameRate)
  39. {
  40. return null;
  41. }
  42. public void setCustomEase(AnimationCurve curve)
  43. {
  44. this.customEase = new List<float>();
  45. foreach (Keyframe keyframe in curve.keys)
  46. {
  47. this.customEase.Add(keyframe.time);
  48. this.customEase.Add(keyframe.value);
  49. this.customEase.Add(keyframe.inTangent);
  50. this.customEase.Add(keyframe.outTangent);
  51. }
  52. }
  53. public AnimationCurve getCustomEaseCurve()
  54. {
  55. AnimationCurve animationCurve = new AnimationCurve();
  56. if (this.customEase.Count < 0)
  57. {
  58. return animationCurve;
  59. }
  60. if (this.customEase.Count % 4 != 0)
  61. {
  62. Debug.LogError("Animator: Error retrieving custom ease.");
  63. return animationCurve;
  64. }
  65. for (int i = 0; i < this.customEase.Count; i += 4)
  66. {
  67. animationCurve.AddKey(new Keyframe(this.customEase[i], this.customEase[i + 1], this.customEase[i + 2], this.customEase[i + 3]));
  68. }
  69. return animationCurve;
  70. }
  71. public bool hasCustomEase()
  72. {
  73. return this.easeType == 32;
  74. }
  75. public string getEaseString(int codeLanguage)
  76. {
  77. string text = string.Empty;
  78. if (this.hasCustomEase())
  79. {
  80. if (codeLanguage == 0)
  81. {
  82. text += "\"easecurve\", AMTween.GenerateCurve(new float[]{";
  83. for (int i = 0; i < this.easeCurve.keys.Length; i++)
  84. {
  85. text = text + this.easeCurve.keys[i].time.ToString() + "f, ";
  86. text = text + this.easeCurve.keys[i].value.ToString() + "f, ";
  87. text = text + this.easeCurve.keys[i].inTangent.ToString() + "f, ";
  88. text = text + this.easeCurve.keys[i].outTangent.ToString() + "f";
  89. if (i < this.easeCurve.keys.Length - 1)
  90. {
  91. text += ", ";
  92. }
  93. }
  94. text += "})";
  95. }
  96. else
  97. {
  98. text += "\"easecurve\": AMTween.GenerateCurve([";
  99. for (int j = 0; j < this.easeCurve.keys.Length; j++)
  100. {
  101. text = text + this.easeCurve.keys[j].time.ToString() + ", ";
  102. text = text + this.easeCurve.keys[j].value.ToString() + ", ";
  103. text = text + this.easeCurve.keys[j].inTangent.ToString() + ", ";
  104. text += this.easeCurve.keys[j].outTangent.ToString();
  105. if (j < this.easeCurve.keys.Length - 1)
  106. {
  107. text += ", ";
  108. }
  109. }
  110. text += "])";
  111. }
  112. }
  113. else
  114. {
  115. AMTween.EaseType easeType = (AMTween.EaseType)this.easeType;
  116. text = text + "\"easetype\", \"" + easeType.ToString() + "\"";
  117. }
  118. return text;
  119. }
  120. public void setupJSONActionEase(AnimatorTimeline.JSONAction a)
  121. {
  122. a.easeType = this.easeType;
  123. if (this.hasCustomEase())
  124. {
  125. a.customEase = this.customEase.ToArray();
  126. }
  127. else
  128. {
  129. a.customEase = new float[0];
  130. }
  131. }
  132. public int startFrame;
  133. public int easeType = 21;
  134. public List<float> customEase = new List<float>();
  135. private AnimationCurve _cachedEaseCurve;
  136. }