123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [Serializable]
- public class AMTrack : ScriptableObject
- {
- public void setName(int index)
- {
- this.name = "Track" + (index + 1);
- }
- public void setName(string name)
- {
- this.name = name;
- }
- public bool hasKeyOnFrame(int _frame)
- {
- foreach (AMKey amkey in this.keys)
- {
- if (amkey.frame == _frame)
- {
- return true;
- }
- }
- return false;
- }
- public virtual void drawGizmos(float gizmo_size)
- {
- }
- public virtual void previewFrame(float frame, AMTrack extraTrack = null)
- {
- }
- public virtual void updateCache()
- {
- AMCameraFade.doShouldUpdateStill();
- }
- public virtual AnimatorTimeline.JSONInit getJSONInit()
- {
- Debug.LogWarning("Animator: No override for getJSONInit()");
- return new AnimatorTimeline.JSONInit();
- }
- public AMKey getKeyOnFrame(int _frame)
- {
- foreach (AMKey amkey in this.keys)
- {
- if (amkey.frame == _frame)
- {
- return amkey;
- }
- }
- Debug.LogError("Animator: No key found on frame " + _frame);
- return new AMKey();
- }
- public virtual string getTrackType()
- {
- return "Unknown";
- }
- public void sortKeys()
- {
- this.keys.Sort((AMKey c, AMKey d) => c.frame.CompareTo(d.frame));
- }
- public void deleteKeyOnFrame(int frame)
- {
- for (int i = 0; i < this.keys.Count; i++)
- {
- if (this.keys[i].frame == frame)
- {
- this.keys[i].destroy();
- this.keys.RemoveAt(i);
- }
- }
- }
- public void deleteDuplicateKeys()
- {
- this.sortKeys();
- int num = -1;
- for (int i = 0; i < this.keys.Count; i++)
- {
- if (this.keys[i].frame == num)
- {
- this.keys[i].destroy();
- this.keys.RemoveAt(i);
- i--;
- }
- else
- {
- num = this.keys[i].frame;
- }
- }
- }
- public void deleteAllKeys()
- {
- foreach (AMKey amkey in this.keys)
- {
- amkey.destroy();
- }
- this.destroyCache();
- this.keys = new List<AMKey>();
- }
- public void deleteKeysAfter(int frame)
- {
- for (int i = 0; i < this.keys.Count; i++)
- {
- if (this.keys[i].frame > frame)
- {
- this.keys[i].destroy();
- this.keys.RemoveAt(i);
- i--;
- }
- }
- }
- public void destroy()
- {
- foreach (AMKey amkey in this.keys)
- {
- amkey.destroy();
- }
- this.destroyCache();
- UnityEngine.Object.DestroyImmediate(this);
- }
- public virtual List<GameObject> getDependencies()
- {
- return new List<GameObject>();
- }
- public virtual List<GameObject> updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences)
- {
- return new List<GameObject>();
- }
- public void destroyCache()
- {
- if (this.cache == null)
- {
- return;
- }
- foreach (AMAction amaction in this.cache)
- {
- if (!(amaction == null))
- {
- amaction.destroy();
- }
- }
- this.cache = null;
- }
- public void offsetKeysFromBy(int frame, int amount)
- {
- if (this.keys.Count <= 0)
- {
- return;
- }
- for (int i = 0; i < this.keys.Count; i++)
- {
- if (frame <= 0 || this.keys[i].frame >= frame)
- {
- this.keys[i].frame += amount;
- }
- }
- this.updateCache();
- }
- public int shiftOutOfBoundsKeys()
- {
- if (this.keys.Count <= 0)
- {
- return 0;
- }
- this.sortKeys();
- if (this.keys[0].frame >= 1)
- {
- return 0;
- }
- int num = 0;
- num = Mathf.Abs(this.keys[0].frame) + 1;
- foreach (AMKey amkey in this.keys)
- {
- amkey.frame += num;
- }
- this.updateCache();
- return num;
- }
- public AMAction getActionContainingFrame(int frame)
- {
- for (int i = this.cache.Count - 1; i >= 0; i--)
- {
- if (frame >= this.cache[i].startFrame)
- {
- return this.cache[i];
- }
- }
- if (this.cache.Count > 0)
- {
- return this.cache[0];
- }
- Debug.LogError("Animator: No action found for frame " + frame);
- return ScriptableObject.CreateInstance<AMAction>();
- }
- public AMAction getActionForFrame(int startFrame)
- {
- foreach (AMAction amaction in this.cache)
- {
- if (amaction.startFrame == startFrame)
- {
- return amaction;
- }
- }
- Debug.LogError("Animator: No action found for frame " + startFrame);
- return ScriptableObject.CreateInstance<AMAction>();
- }
- public int getActionIndexForFrame(int startFrame)
- {
- for (int i = 0; i < this.cache.Count; i++)
- {
- if (this.cache[i].startFrame == startFrame)
- {
- return i;
- }
- }
- return -1;
- }
- public bool hasActionOnFrame(int _frame)
- {
- foreach (AMAction amaction in this.cache)
- {
- if (amaction.startFrame == _frame)
- {
- return true;
- }
- }
- return false;
- }
- public int getKeyFrameAfterFrame(int frame, bool wholeTake = true)
- {
- foreach (AMKey amkey in this.keys)
- {
- if (amkey.frame > frame)
- {
- return amkey.frame;
- }
- }
- if (!wholeTake)
- {
- return -1;
- }
- if (this.keys.Count > 0)
- {
- return this.keys[0].frame;
- }
- Debug.LogError("Animator: No key found after frame " + frame);
- return -1;
- }
- public int getKeyFrameBeforeFrame(int frame, bool wholeTake = true)
- {
- for (int i = this.keys.Count - 1; i >= 0; i--)
- {
- if (this.keys[i].frame < frame)
- {
- return this.keys[i].frame;
- }
- }
- if (!wholeTake)
- {
- return -1;
- }
- if (this.keys.Count > 0)
- {
- return this.keys[this.keys.Count - 1].frame;
- }
- Debug.LogError("Animator: No key found before frame " + frame);
- return -1;
- }
- public AMKey[] getKeyFramesInBetween(int startFrame, int endFrame)
- {
- List<AMKey> list = new List<AMKey>();
- if (startFrame <= 0 || endFrame <= 0 || startFrame >= endFrame || !this.hasKeyOnFrame(startFrame) || !this.hasKeyOnFrame(endFrame))
- {
- return list.ToArray();
- }
- this.sortKeys();
- foreach (AMKey amkey in this.keys)
- {
- if (amkey.frame >= endFrame)
- {
- break;
- }
- if (amkey.frame > startFrame)
- {
- list.Add(amkey);
- }
- }
- return list.ToArray();
- }
- public float[] getKeyFrameRatiosInBetween(int startFrame, int endFrame)
- {
- List<float> list = new List<float>();
- if (startFrame <= 0 || endFrame <= 0 || startFrame >= endFrame || !this.hasKeyOnFrame(startFrame) || !this.hasKeyOnFrame(endFrame))
- {
- return list.ToArray();
- }
- this.sortKeys();
- foreach (AMKey amkey in this.keys)
- {
- if (amkey.frame >= endFrame)
- {
- break;
- }
- if (amkey.frame > startFrame)
- {
- list.Add((float)(amkey.frame - startFrame) / (float)(endFrame - startFrame));
- }
- }
- return list.ToArray();
- }
- public int id;
- public new string name;
- public List<AMKey> keys = new List<AMKey>();
- public List<AMAction> cache = new List<AMAction>();
- public bool foldout = true;
- public AMTake parentTake;
- }
|