123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 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<AMKey>();
- 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<float>
- {
- 0f,
- 0f,
- 1f,
- 1f,
- 1f,
- 1f,
- 1f,
- 1f
- };
- }
- return true;
- }
- return false;
- }
- 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);
- }
- 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<float> customEase = new List<float>();
- private AnimationCurve _cachedEaseCurve;
- }
|