AMKey.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [Serializable]
  5. public class AMKey : ScriptableObject
  6. {
  7. public static AMKey CreateTrackType(string track_type)
  8. {
  9. AMKey result = null;
  10. if (track_type != null)
  11. {
  12. if (!(track_type == "Translation"))
  13. {
  14. if (!(track_type == "Rotation"))
  15. {
  16. if (!(track_type == "Event"))
  17. {
  18. if (!(track_type == "Property"))
  19. {
  20. if (track_type == "Animation")
  21. {
  22. result = new AMAnimationKey();
  23. }
  24. }
  25. else
  26. {
  27. result = new AMPropertyKey();
  28. }
  29. }
  30. else
  31. {
  32. result = new AMEventKey();
  33. }
  34. }
  35. else
  36. {
  37. result = new AMRotationKey();
  38. }
  39. }
  40. else
  41. {
  42. result = new AMTranslationKey();
  43. }
  44. }
  45. return result;
  46. }
  47. public AnimationCurve easeCurve
  48. {
  49. get
  50. {
  51. if (this._cachedEaseCurve == null || this._cachedEaseCurve.keys.Length <= 0)
  52. {
  53. this._cachedEaseCurve = this.getCustomEaseCurve();
  54. }
  55. return this._cachedEaseCurve;
  56. }
  57. }
  58. public virtual void destroy()
  59. {
  60. UnityEngine.Object.DestroyImmediate(this);
  61. }
  62. public virtual AMKey CreateClone()
  63. {
  64. AMKey result = ScriptableObject.CreateInstance<AMKey>();
  65. Debug.LogError("Animator: No override for CreateClone()");
  66. return result;
  67. }
  68. public virtual void CreateFromStringData(string data_text)
  69. {
  70. Debug.LogError("No override for CreateFromStringData()");
  71. }
  72. public virtual string ToStringData()
  73. {
  74. Debug.LogError("No override for ToStringData()");
  75. return string.Empty;
  76. }
  77. public bool setEaseType(int easeType)
  78. {
  79. if (easeType != this.easeType)
  80. {
  81. this.easeType = easeType;
  82. if (easeType == 32 && this.customEase.Count <= 0)
  83. {
  84. this.customEase = new List<float>
  85. {
  86. 0f,
  87. 0f,
  88. 1f,
  89. 1f,
  90. 1f,
  91. 1f,
  92. 1f,
  93. 1f
  94. };
  95. }
  96. return true;
  97. }
  98. return false;
  99. }
  100. public void setCustomEase(AnimationCurve curve)
  101. {
  102. this.customEase = new List<float>();
  103. foreach (Keyframe keyframe in curve.keys)
  104. {
  105. this.customEase.Add(keyframe.time);
  106. this.customEase.Add(keyframe.value);
  107. this.customEase.Add(keyframe.inTangent);
  108. this.customEase.Add(keyframe.outTangent);
  109. }
  110. this._cachedEaseCurve = null;
  111. }
  112. public AnimationCurve getCustomEaseCurve()
  113. {
  114. AnimationCurve animationCurve = new AnimationCurve();
  115. if (this.customEase.Count < 0)
  116. {
  117. return animationCurve;
  118. }
  119. if (this.customEase.Count % 4 != 0)
  120. {
  121. Debug.LogError("Animator: Error retrieving custom ease.");
  122. return animationCurve;
  123. }
  124. for (int i = 0; i < this.customEase.Count; i += 4)
  125. {
  126. animationCurve.AddKey(new Keyframe(this.customEase[i], this.customEase[i + 1], this.customEase[i + 2], this.customEase[i + 3]));
  127. }
  128. return animationCurve;
  129. }
  130. public bool hasCustomEase()
  131. {
  132. return this.easeType == 32;
  133. }
  134. public int frame;
  135. public int easeType = 21;
  136. public List<float> customEase = new List<float>();
  137. private AnimationCurve _cachedEaseCurve;
  138. }