123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [Serializable]
- public class AMAnimationTrack : AMTrack
- {
- public override string getTrackType()
- {
- return "Animation";
- }
- public bool setObject(GameObject obj)
- {
- if (this.obj != obj)
- {
- this.obj = obj;
- return true;
- }
- return false;
- }
- public void addKey(int _frame, AnimationClip _clip, WrapMode _wrapMode)
- {
- foreach (AMKey amkey in this.keys)
- {
- AMAnimationKey amanimationKey = (AMAnimationKey)amkey;
- if (amanimationKey.frame == _frame)
- {
- amanimationKey.amClip = _clip;
- amanimationKey.wrapMode = _wrapMode;
- this.updateCache();
- return;
- }
- }
- AMAnimationKey amanimationKey2 = ScriptableObject.CreateInstance<AMAnimationKey>();
- amanimationKey2.frame = _frame;
- amanimationKey2.amClip = _clip;
- amanimationKey2.wrapMode = _wrapMode;
- this.keys.Add(amanimationKey2);
- this.updateCache();
- }
- public override void updateCache()
- {
- base.destroyCache();
- this.cache = new List<AMAction>();
- base.sortKeys();
- for (int i = 0; i < this.keys.Count; i++)
- {
- AMAnimationAction amanimationAction = ScriptableObject.CreateInstance<AMAnimationAction>();
- amanimationAction.startFrame = this.keys[i].frame;
- amanimationAction.obj = this.obj;
- amanimationAction.amClip = (this.keys[i] as AMAnimationKey).amClip;
- amanimationAction.wrapMode = (this.keys[i] as AMAnimationKey).wrapMode;
- amanimationAction.crossfade = (this.keys[i] as AMAnimationKey).crossfade;
- amanimationAction.crossfadeTime = (this.keys[i] as AMAnimationKey).crossfadeTime;
- this.cache.Add(amanimationAction);
- }
- base.updateCache();
- }
- public void previewFrame(float frame, float frameRate)
- {
- if (!this.obj)
- {
- return;
- }
- if (this.cache.Count <= 0)
- {
- return;
- }
- bool flag = false;
- for (int i = this.cache.Count - 1; i >= 0; i--)
- {
- if ((float)this.cache[i].startFrame <= frame)
- {
- AnimationClip amClip = (this.cache[i] as AMAnimationAction).amClip;
- if (amClip)
- {
- amClip.wrapMode = (this.cache[i] as AMAnimationAction).wrapMode;
- amClip.SampleAnimation(this.obj, this.getTime(frameRate, frame - (float)this.cache[i].startFrame));
- }
- flag = true;
- break;
- }
- }
- Animation component = this.obj.GetComponent<Animation>();
- if (!flag && component.clip)
- {
- component.clip.SampleAnimation(this.obj, 0f);
- }
- }
- public float getTime(float frameRate, float numberOfFrames)
- {
- return numberOfFrames / frameRate;
- }
- public override AnimatorTimeline.JSONInit getJSONInit()
- {
- return null;
- }
- public override List<GameObject> getDependencies()
- {
- List<GameObject> list = new List<GameObject>();
- if (this.obj)
- {
- list.Add(this.obj);
- }
- return list;
- }
- public override List<GameObject> updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences)
- {
- List<GameObject> list = new List<GameObject>();
- if (!this.obj)
- {
- return list;
- }
- int i = 0;
- while (i < oldReferences.Count)
- {
- if (oldReferences[i] == this.obj)
- {
- if (!newReferences[i].GetComponent(typeof(Animation)))
- {
- Debug.LogWarning("Animator: Animation Track component 'Animation' not found on new reference for GameObject '" + this.obj.name + "'. Duplicate not replaced.");
- list.Add(oldReferences[i]);
- return list;
- }
- this.obj = newReferences[i];
- break;
- }
- else
- {
- i++;
- }
- }
- return list;
- }
- public GameObject obj;
- }
|