private void CheckBranches(int curveIndex) { int pointIndex = curveIndex * 3; if (m_t >= 1.0f) { pointIndex += 3; } m_curveIndex = curveIndex; if (m_spline.HasBranches(pointIndex)) { ForkEventArgs args = new ForkEventArgs(m_spline, pointIndex); Fork.Invoke(args); if (args.SelectBranchIndex > -1 && args.SelectBranchIndex < args.Branches.Length) { Debug.Log("CurveIndex " + m_curveIndex); Debug.Log("Selected Branch " + args.SelectBranchIndex); m_spline = args.Branches[args.SelectBranchIndex]; m_t = 0.0f; m_curveIndex = 0; } } }
public void OnFork(ForkEventArgs args) { float min = float.MaxValue; int minIndex = -1; if (args.NextCurveIndex != -1) { min = args.Spline.EvalCurveLength(args.NextCurveIndex); } for (int i = 0; i < args.Branches.Length; ++i) { SplineBase branch = args.Branches[i]; float len = branch.EvalCurveLength(0); if (len < min) { min = len; minIndex = i; } } args.SelectBranchIndex = minIndex; }
public void OnFork(ForkEventArgs args) { int r = Random.Range(args.NextCurveIndex == -1 ? 0 : -1, args.Branches.Length); args.SelectBranchIndex = r; }