1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
9 private List<WayPoint> nodes;
13 private float? totalLength;
26 if (!totalLength.HasValue)
28 CalculateTotalLength();
30 return totalLength.Value;
34 public float GetLength(
int? startIndex =
null,
int? endIndex =
null)
38 endIndex ??=
Nodes.Count - 1;
39 if (startIndex == 0 && endIndex ==
Nodes.Count - 1)
43 if (!totalLength.HasValue)
45 CalculateTotalLength();
48 for (
int i = startIndex.Value; i < endIndex.Value; i++)
50 length += nodeDistances[i];
55 private void CalculateTotalLength()
58 nodeDistances.Clear();
59 for (
int i = 0; i < nodes.Count - 1; i++)
61 float distance = Vector2.Distance(nodes[i].WorldPosition, nodes[i + 1].WorldPosition);
62 totalLength += distance;
63 nodeDistances.Add(distance);
67 private readonly List<float> nodeDistances =
new List<float>();
71 nodes =
new List<WayPoint>();
77 if (node ==
null) {
return; }
91 get {
return currentIndex; }
104 if (currentIndex - 1 < 0 || currentIndex - 1 > nodes.Count - 1) {
return null; }
105 return nodes[currentIndex - 1];
113 if (currentIndex < 0 || currentIndex > nodes.Count - 1) {
return null; }
114 return nodes[currentIndex];
122 get {
return nodes; }
129 if (currentIndex + 1 < 0 || currentIndex + 1 > nodes.Count - 1) {
return null; }
130 return nodes[currentIndex+1];
136 get {
return currentIndex >= nodes.Count; }
146 currentIndex = nodeIndex;
151 if (nodes.Count == 0 || currentIndex > nodes.Count - 1) {
return null; }
152 if (Vector2.Distance(simPosition, nodes[currentIndex].SimPosition) < minSimDistance) { currentIndex++; }
void AddNode(WayPoint node)
SteeringPath(bool unreachable=false)
void SkipToNode(int nodeIndex)
WayPoint CheckProgress(Vector2 simPosition, float minSimDistance=0.1f)
float GetLength(int? startIndex=null, int? endIndex=null)