public int endIndex; // ending key index public static AMPath GenerateCurve(List <AMKey> keys, int _startIndex) { AMPath newPath = new AMPath(); // sort the keys by frame List <Vector3> _path = new List <Vector3>(); newPath.startIndex = _startIndex; newPath.endIndex = _startIndex; newPath.endFrame = keys[_startIndex].frame; _path.Add((keys[_startIndex] as AMTranslationKey).position); // get path from startIndex until the next linear interpolation key (inclusive) for (int i = _startIndex + 1; i < keys.Count; i++) { AMTranslationKey key = keys[i] as AMTranslationKey; _path.Add(key.position); newPath.endFrame = keys[i].frame; newPath.endIndex = i; if (!keys[_startIndex].canTween || key.interp != (int)AMTranslationKey.Interpolation.Curve) { break; } } newPath.interp = (int)AMTranslationKey.Interpolation.Curve; newPath.path = _path.ToArray(); return(newPath); }
public static AMPath GenerateLinear(List <AMKey> keys, int _startIndex) { AMPath newPath = new AMPath(); // sort the keys by frame List <Vector3> _path = new List <Vector3>(); newPath.startIndex = _startIndex; newPath.endIndex = _startIndex; newPath.endFrame = keys[_startIndex].frame; _path.Add((keys[_startIndex] as AMTranslationKey).position); int nextIndex = _startIndex + 1; if (nextIndex < keys.Count) { AMTranslationKey key = keys[nextIndex] as AMTranslationKey; _path.Add(key.position); newPath.endFrame = keys[nextIndex].frame; newPath.endIndex = nextIndex; } newPath.interp = (int)AMTranslationKey.Interpolation.Linear; newPath.path = _path.ToArray(); return(newPath); }
// update cache (optimized) public override void updateCache(AMITarget target) { base.updateCache(target); // get all paths and add them to the action list for (int i = 0; i < keys.Count; i++) { AMTranslationKey key = keys[i] as AMTranslationKey; int interp = key.interp; int easeType = key.easeType; key.version = version; AMPath path = new AMPath(keys, i); key.endFrame = path.endFrame; key.pathPreview = null; if (!key.canTween) { if (path.endIndex == keys.Count - 1) { AMTranslationKey lastKey = keys[path.endIndex] as AMTranslationKey; lastKey.interp = (int)AMTranslationKey.Interpolation.None; lastKey.endFrame = lastKey.frame; lastKey.path = new Vector3[0]; } } else { key.path = path.path; } //invalidate some keys in between if (path.startIndex < keys.Count - 1) { for (i = path.startIndex + 1; i <= path.endIndex - 1; i++) { key = keys[i] as AMTranslationKey; key.version = version; key.interp = interp; key.easeType = easeType; key.endFrame = key.frame; key.path = new Vector3[0]; } i = path.endIndex - 1; } } }
public static AMPath GenerateSingle(AMKey key, int _startIndex) { AMPath newPath = new AMPath(); // sort the keys by frame newPath.startIndex = _startIndex; newPath.endIndex = _startIndex; newPath.endFrame = key.frame; newPath.path = new Vector3[] { (key as AMTranslationKey).position }; newPath.interp = (int)AMTranslationKey.Interpolation.None; return(newPath); }
// update cache (optimized) public override void updateCache(AMITarget target) { base.updateCache(target); // get all paths and add them to the action list for (int i = 0; i < keys.Count; i++) { AMTranslationKey key = keys[i] as AMTranslationKey; int interp = key.interp; int easeType = key.easeType; key.version = version; AMPath path; switch ((AMTranslationKey.Interpolation)key.interp) { case AMKey.Interpolation.Curve: path = AMPath.GenerateCurve(keys, i); break; case AMKey.Interpolation.Linear: path = AMPath.GenerateLinear(keys, i); break; default: path = AMPath.GenerateSingle(keys[i], i); break; } key.endFrame = path.endFrame; key.pathPreview = null; if (!key.canTween) { if (path.endIndex == keys.Count - 1) { AMTranslationKey lastKey = keys[path.endIndex] as AMTranslationKey; lastKey.interp = (int)AMTranslationKey.Interpolation.None; lastKey.endFrame = lastKey.frame; lastKey.path = new Vector3[0]; } } else { key.path = path.path; } //invalidate some keys in between if (path.startIndex < keys.Count - 1) { int _endInd = path.endIndex; if (_endInd < keys.Count - 1) { _endInd--; } for (i = path.startIndex + 1; i <= _endInd; i++) { key = keys[i] as AMTranslationKey; key.version = version; key.interp = interp; key.easeType = easeType; key.endFrame = key.frame; key.path = new Vector3[0]; } i = _endInd; } } }