using System; using System.Collections.Generic; using UnityEngine; [Serializable] public class AMKey : ScriptableObject { public static AMKey CreateTrackType(string track_type) { AMKey result = null; if (track_type != null) { if (!(track_type == "Translation")) { if (!(track_type == "Rotation")) { if (!(track_type == "Event")) { if (!(track_type == "Property")) { if (track_type == "Animation") { result = new AMAnimationKey(); } } else { result = new AMPropertyKey(); } } else { result = new AMEventKey(); } } else { result = new AMRotationKey(); } } else { result = new AMTranslationKey(); } } return result; } public AnimationCurve easeCurve { get { if (this._cachedEaseCurve == null || this._cachedEaseCurve.keys.Length <= 0) { this._cachedEaseCurve = this.getCustomEaseCurve(); } return this._cachedEaseCurve; } } public virtual void destroy() { UnityEngine.Object.DestroyImmediate(this); } public virtual AMKey CreateClone() { AMKey result = ScriptableObject.CreateInstance(); Debug.LogError("Animator: No override for CreateClone()"); return result; } public virtual void CreateFromStringData(string data_text) { Debug.LogError("No override for CreateFromStringData()"); } public virtual string ToStringData() { Debug.LogError("No override for ToStringData()"); return string.Empty; } public bool setEaseType(int easeType) { if (easeType != this.easeType) { this.easeType = easeType; if (easeType == 32 && this.customEase.Count <= 0) { this.customEase = new List { 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f }; } return true; } return false; } public void setCustomEase(AnimationCurve curve) { this.customEase = new List(); foreach (Keyframe keyframe in curve.keys) { this.customEase.Add(keyframe.time); this.customEase.Add(keyframe.value); this.customEase.Add(keyframe.inTangent); this.customEase.Add(keyframe.outTangent); } this._cachedEaseCurve = null; } public AnimationCurve getCustomEaseCurve() { AnimationCurve animationCurve = new AnimationCurve(); if (this.customEase.Count < 0) { return animationCurve; } if (this.customEase.Count % 4 != 0) { Debug.LogError("Animator: Error retrieving custom ease."); return animationCurve; } for (int i = 0; i < this.customEase.Count; i += 4) { animationCurve.AddKey(new Keyframe(this.customEase[i], this.customEase[i + 1], this.customEase[i + 2], this.customEase[i + 3])); } return animationCurve; } public bool hasCustomEase() { return this.easeType == 32; } public int frame; public int easeType = 21; public List customEase = new List(); private AnimationCurve _cachedEaseCurve; }