123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 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<float>();
- 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<float> customEase = new List<float>();
- private AnimationCurve _cachedEaseCurve;
- }
|