using System; using System.Collections.Generic; using UnityEngine; [Serializable] public class AMAction : ScriptableObject { public AnimationCurve easeCurve { get { if (this._cachedEaseCurve == null || this._cachedEaseCurve.keys.Length <= 0) { this._cachedEaseCurve = this.getCustomEaseCurve(); } return this._cachedEaseCurve; } } public virtual string ToString(int codeLanguage, int frameRate) { return "(Error: No override for ToString)"; } public virtual void execute(int frameRate, float delayModifier, string trackId) { Debug.LogError("Animator: No override for execute."); } public float getWaitTime(int frameRate, float delay) { return ((float)this.startFrame - 1f) / (float)frameRate - delay; } public virtual int getNumberOfFrames() { return 1; } public void destroy() { UnityEngine.Object.DestroyImmediate(this); } public virtual AnimatorTimeline.JSONAction getJSONAction(int frameRate) { return null; } 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); } } 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 string getEaseString(int codeLanguage) { string text = string.Empty; if (this.hasCustomEase()) { if (codeLanguage == 0) { text += "\"easecurve\", AMTween.GenerateCurve(new float[]{"; for (int i = 0; i < this.easeCurve.keys.Length; i++) { text = text + this.easeCurve.keys[i].time.ToString() + "f, "; text = text + this.easeCurve.keys[i].value.ToString() + "f, "; text = text + this.easeCurve.keys[i].inTangent.ToString() + "f, "; text = text + this.easeCurve.keys[i].outTangent.ToString() + "f"; if (i < this.easeCurve.keys.Length - 1) { text += ", "; } } text += "})"; } else { text += "\"easecurve\": AMTween.GenerateCurve(["; for (int j = 0; j < this.easeCurve.keys.Length; j++) { text = text + this.easeCurve.keys[j].time.ToString() + ", "; text = text + this.easeCurve.keys[j].value.ToString() + ", "; text = text + this.easeCurve.keys[j].inTangent.ToString() + ", "; text += this.easeCurve.keys[j].outTangent.ToString(); if (j < this.easeCurve.keys.Length - 1) { text += ", "; } } text += "])"; } } else { AMTween.EaseType easeType = (AMTween.EaseType)this.easeType; text = text + "\"easetype\", \"" + easeType.ToString() + "\""; } return text; } public void setupJSONActionEase(AnimatorTimeline.JSONAction a) { a.easeType = this.easeType; if (this.hasCustomEase()) { a.customEase = this.customEase.ToArray(); } else { a.customEase = new float[0]; } } public int startFrame; public int easeType = 21; public List customEase = new List(); private AnimationCurve _cachedEaseCurve; }