public void Restart() { m_spline = Spline; m_t = Offset % 1; m_curveIndex = Spline.ToCurveIndex(m_t); m_isCompleted = false; IsRunning = true; }
private void Move() { int curveIndex = m_spline.ToCurveIndex(m_t); if (m_curveIndex != curveIndex || m_t >= 1.0f) { CheckBranches(curveIndex); } float t = m_t; UpdatePosition(t); float v = m_spline.GetVelocity(t).magnitude; v *= m_spline.CurveCount; if (m_t >= 1.0f) { if (m_spline.NextSpline != null) { int nextControlPointIndex = m_spline.NextControlPointIndex; m_curveIndex = nextControlPointIndex / 3; m_spline = m_spline.NextSpline; if (m_spline.NextControlPointIndex > 0) { m_t = ((float)m_curveIndex) / m_spline.CurveCount; m_curveIndex++; } else { m_t = ((float)m_curveIndex) / m_spline.CurveCount; } Debug.Log("Next Spline " + m_curveIndex); CheckBranches(m_curveIndex); } else { m_t = (m_t - 1.0f) + (Time.deltaTime * Speed) / v; if (!m_spline.Loop && !IsLoop) { m_t = 1.0f; m_isCompleted = true; IsRunning = false; m_isRunning = false; Completed.Invoke(); } if (IsLoop) { if (m_spline != Spline) { Restart(); } } } } else { m_t += (Time.deltaTime * Speed) / v; } }