void Reset() { duration = Mathf.Clamp(duration, float.Epsilon, duration); CleanUp(); float curLength = 0; for (int i = 0; i < pathPoints.Length - 1; ++i) { curLength = (pathPoints[i + 1] - pathPoints[i]).magnitude; if (curLength == 0) { continue; } SegInfo si = new SegInfo { FromPos = pathPoints[i], ToPos = pathPoints[i + 1], length = curLength, isReversed = false, }; segInfoList.Add(si); length += curLength; } valid = segInfoList.Count > 0; if (valid) { speed = length / duration; } }
public void Restart() { Reset(); if (valid) { curSegInfo = segInfoList[0]; UpdateRotation(); } }
void OnSegEnd() { onSegEnd?.Invoke(curSegIndex); curSegProgess -= curSegInfo.length; curSegIndex++; if (curSegIndex < segInfoList.Count) { curSegInfo = segInfoList[curSegIndex]; UpdateRotation(); } else { OnLoopEnd(); } }
void OnLoopEnd() { onLoopEnd?.Invoke(curLoopIndex); curLoopIndex++; if (loops < 0 || curLoopIndex < loops) { if (loopType == LoopType.PingPong) { segInfoList.Reverse(); IsReversed = segInfoList.IsReversed; } curSegIndex = 0; curSegInfo = segInfoList[curSegIndex]; UpdateRotation(); curSegProgess = 0; } else { valid = false; } }
public void Add(SegInfo segInfo) { segInfoList.Add(segInfo); }