123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using UnityEngine;
- [Serializable]
- public class AMTranslationTrack : AMTrack
- {
- public Transform obj
- {
- get
- {
- return this._obj;
- }
- set
- {
- if (value != null && this.cache.Count <= 0)
- {
- this.cachedInitialPosition = value.position;
- }
- this._obj = value;
- if (this._obj != null)
- {
- this.objName = this._obj.name;
- }
- else
- {
- this.objName = string.Empty;
- }
- }
- }
- public override string getTrackType()
- {
- return "Translation";
- }
- public void addKey(int _frame, Vector3 _position, int _interp, int _easeType)
- {
- foreach (AMKey amkey in this.keys)
- {
- AMTranslationKey amtranslationKey = (AMTranslationKey)amkey;
- if (amtranslationKey.frame == _frame)
- {
- amtranslationKey.position = _position;
- amtranslationKey.interp = _interp;
- amtranslationKey.easeType = _easeType;
- this.updateCache();
- return;
- }
- }
- AMTranslationKey amtranslationKey2 = ScriptableObject.CreateInstance<AMTranslationKey>();
- amtranslationKey2.frame = _frame;
- amtranslationKey2.position = _position;
- amtranslationKey2.interp = _interp;
- amtranslationKey2.easeType = _easeType;
- this.keys.Add(amtranslationKey2);
- this.updateCache();
- }
- public void addKey(int _frame, Vector3 _position)
- {
- foreach (AMKey amkey in this.keys)
- {
- AMTranslationKey amtranslationKey = (AMTranslationKey)amkey;
- if (amtranslationKey.frame == _frame)
- {
- amtranslationKey.position = _position;
- this.updateCache();
- return;
- }
- }
- AMTranslationKey amtranslationKey2 = ScriptableObject.CreateInstance<AMTranslationKey>();
- amtranslationKey2.frame = _frame;
- amtranslationKey2.position = _position;
- this.keys.Add(amtranslationKey2);
- this.updateCache();
- }
- public bool changeObject(Transform _obj)
- {
- this.obj = _obj;
- this.updateCache();
- return true;
- }
- public override void previewFrame(float frame, AMTrack extraTrack = null)
- {
- if (!this.obj)
- {
- return;
- }
- if (string.IsNullOrEmpty(this.objName))
- {
- this.objName = this.obj.name;
- }
- if (this.cache.Count <= 0)
- {
- return;
- }
- if (frame <= (float)this.cache[0].startFrame)
- {
- this.obj.position = (this.cache[0] as AMTranslationAction).path[0];
- return;
- }
- if (frame >= (float)(this.cache[this.cache.Count - 1] as AMTranslationAction).endFrame)
- {
- this.obj.position = (this.cache[this.cache.Count - 1] as AMTranslationAction).path[(this.cache[this.cache.Count - 1] as AMTranslationAction).path.Length - 1];
- return;
- }
- foreach (AMAction amaction in this.cache)
- {
- AMTranslationAction amtranslationAction = (AMTranslationAction)amaction;
- if (frame >= (float)amtranslationAction.startFrame && frame <= (float)amtranslationAction.endFrame)
- {
- if (amtranslationAction.path.Length == 1)
- {
- this.obj.position = amtranslationAction.path[0];
- break;
- }
- float num = frame - (float)amtranslationAction.startFrame;
- if (num < 0f)
- {
- num = 0f;
- }
- AnimationCurve curve = null;
- AMTween.EasingFunction easingFunction;
- if (amtranslationAction.hasCustomEase())
- {
- if (AMTranslationTrack.<>f__mg$cache0 == null)
- {
- AMTranslationTrack.<>f__mg$cache0 = new AMTween.EasingFunction(AMTween.customEase);
- }
- easingFunction = AMTranslationTrack.<>f__mg$cache0;
- curve = amtranslationAction.easeCurve;
- }
- else
- {
- easingFunction = AMTween.GetEasingFunction((AMTween.EaseType)amtranslationAction.easeType);
- }
- float value = easingFunction(0f, 1f, num / (float)amtranslationAction.getNumberOfFrames(), curve);
- AMTween.PutOnPath(this.obj, amtranslationAction.path, Mathf.Clamp(value, 0f, 1f));
- break;
- }
- }
- }
- public bool autoKey(Transform _obj, int frame)
- {
- if (!this.obj)
- {
- return false;
- }
- if (_obj != this.obj)
- {
- return false;
- }
- if (this.cache.Count <= 0)
- {
- if (_obj.position != this.cachedInitialPosition)
- {
- this.addKey(frame, _obj.position);
- return true;
- }
- return false;
- }
- else
- {
- Vector3 positionAtFrame = this.getPositionAtFrame((float)frame);
- if (_obj.position != positionAtFrame)
- {
- this.addKey(frame, _obj.position);
- return true;
- }
- return false;
- }
- }
- public Vector3 getPositionAtFrame(float frame)
- {
- if (this.cache.Count <= 0)
- {
- return this.obj.position;
- }
- if (frame <= (float)this.cache[0].startFrame)
- {
- return (this.cache[0] as AMTranslationAction).path[0];
- }
- if (frame >= (float)(this.cache[this.cache.Count - 1] as AMTranslationAction).endFrame)
- {
- return (this.cache[this.cache.Count - 1] as AMTranslationAction).path[(this.cache[this.cache.Count - 1] as AMTranslationAction).path.Length - 1];
- }
- foreach (AMAction amaction in this.cache)
- {
- AMTranslationAction amtranslationAction = (AMTranslationAction)amaction;
- if ((int)frame >= amtranslationAction.startFrame && (int)frame <= amtranslationAction.endFrame)
- {
- if (amtranslationAction.path.Length == 1)
- {
- return amtranslationAction.path[0];
- }
- AnimationCurve curve = null;
- AMTween.EasingFunction easingFunction;
- if (amtranslationAction.hasCustomEase())
- {
- if (AMTranslationTrack.<>f__mg$cache1 == null)
- {
- AMTranslationTrack.<>f__mg$cache1 = new AMTween.EasingFunction(AMTween.customEase);
- }
- easingFunction = AMTranslationTrack.<>f__mg$cache1;
- curve = amtranslationAction.easeCurve;
- }
- else
- {
- easingFunction = AMTween.GetEasingFunction((AMTween.EaseType)amtranslationAction.easeType);
- }
- float num = frame - (float)amtranslationAction.startFrame;
- if (num < 0f)
- {
- num = 0f;
- }
- return AMTween.PointOnPath(amtranslationAction.path, Mathf.Clamp(easingFunction(0f, 1f, num / (float)amtranslationAction.getNumberOfFrames(), curve), 0f, 1f));
- }
- }
- Debug.LogError(string.Concat(new object[]
- {
- "Animator: Could not get ",
- this.obj.name,
- " position at frame '",
- frame,
- "'"
- }));
- return new Vector3(0f, 0f, 0f);
- }
- public override void drawGizmos(float gizmo_size)
- {
- foreach (AMAction amaction in this.cache)
- {
- AMTranslationAction amtranslationAction = (AMTranslationAction)amaction;
- if (amtranslationAction.path.Length > 1)
- {
- AMTween.DrawPath(amtranslationAction.path, new Color(255f, 255f, 255f, 0.5f));
- Gizmos.color = Color.green;
- Gizmos.DrawSphere(amtranslationAction.path[0], gizmo_size);
- Gizmos.DrawSphere(amtranslationAction.path[amtranslationAction.path.Length - 1], gizmo_size);
- }
- }
- }
- private AMPath getPathFromIndex(int startIndex)
- {
- List<Vector3> list = new List<Vector3>();
- int endIndex = startIndex;
- int frame = this.keys[startIndex].frame;
- int frame2 = this.keys[startIndex].frame;
- list.Add((this.keys[startIndex] as AMTranslationKey).position);
- for (int i = startIndex + 1; i < this.keys.Count; i++)
- {
- list.Add((this.keys[i] as AMTranslationKey).position);
- frame2 = this.keys[i].frame;
- endIndex = i;
- if ((this.keys[i] as AMTranslationKey).interp == 1)
- {
- break;
- }
- }
- return new AMPath(list.ToArray(), (this.keys[startIndex] as AMTranslationKey).interp, frame, frame2, startIndex, endIndex);
- }
- public override void updateCache()
- {
- if (this._obj != null)
- {
- this.objName = this._obj.name;
- }
- else
- {
- this.objName = string.Empty;
- }
- base.destroyCache();
- this.cache = new List<AMAction>();
- base.sortKeys();
- for (int i = 0; i < this.keys.Count; i++)
- {
- AMPath pathFromIndex = this.getPathFromIndex(i);
- AMTranslationAction amtranslationAction = ScriptableObject.CreateInstance<AMTranslationAction>();
- amtranslationAction.startFrame = pathFromIndex.startFrame;
- amtranslationAction.endFrame = pathFromIndex.endFrame;
- amtranslationAction.obj = this.obj;
- amtranslationAction.path = pathFromIndex.path;
- amtranslationAction.easeType = (this.keys[i] as AMTranslationKey).easeType;
- amtranslationAction.customEase = new List<float>(this.keys[i].customEase);
- this.cache.Add(amtranslationAction);
- if (i < this.keys.Count - 1)
- {
- i = pathFromIndex.endIndex - 1;
- }
- }
- foreach (AMTrack amtrack in this.parentTake.trackValues)
- {
- if (amtrack is AMOrientationTrack && ((amtrack as AMOrientationTrack).obj == this.obj || (amtrack as AMOrientationTrack).hasTarget(this.obj)))
- {
- amtrack.updateCache();
- }
- }
- base.updateCache();
- }
- public AMTranslationKey getActionStartKeyFor(int frame)
- {
- foreach (AMAction amaction in this.cache)
- {
- AMTranslationAction amtranslationAction = (AMTranslationAction)amaction;
- if (frame >= amtranslationAction.startFrame && frame < amtranslationAction.endFrame)
- {
- return (AMTranslationKey)base.getKeyOnFrame(amtranslationAction.startFrame);
- }
- }
- Debug.LogError("Animator: Action for frame " + frame + " does not exist in cache.");
- return new AMTranslationKey();
- }
- public Vector3 getInitialPosition()
- {
- return (this.keys[0] as AMTranslationKey).position;
- }
- public override AnimatorTimeline.JSONInit getJSONInit()
- {
- if (!this.obj || this.keys.Count <= 0)
- {
- return null;
- }
- AnimatorTimeline.JSONInit jsoninit = new AnimatorTimeline.JSONInit();
- jsoninit.type = "position";
- jsoninit.go = this.obj.gameObject.name;
- AnimatorTimeline.JSONVector3 jsonvector = new AnimatorTimeline.JSONVector3();
- jsonvector.setValue(this.getInitialPosition());
- jsoninit.position = jsonvector;
- return jsoninit;
- }
- public override List<GameObject> getDependencies()
- {
- List<GameObject> list = new List<GameObject>();
- if (this.obj)
- {
- list.Add(this.obj.gameObject);
- }
- return list;
- }
- public override List<GameObject> updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences)
- {
- if (!this.obj)
- {
- return new List<GameObject>();
- }
- for (int i = 0; i < oldReferences.Count; i++)
- {
- if (oldReferences[i] == this.obj.gameObject)
- {
- this.obj = newReferences[i].transform;
- break;
- }
- }
- return new List<GameObject>();
- }
- [SerializeField]
- private Transform _obj;
- public string objName;
- public Vector3 cachedInitialPosition;
- [CompilerGenerated]
- private static AMTween.EasingFunction <>f__mg$cache0;
- [CompilerGenerated]
- private static AMTween.EasingFunction <>f__mg$cache1;
- }
|