/// <summary> /// Adds a waypoint before the current destination /// </summary> /// <param name="targetPosition">The target position in world coordinates</param> public void AddWaypointPrev(Vector2 targetPosition) { if (current == null) { WaypointList.AddFirst(targetPosition); } else { WaypointList.AddBefore(current, targetPosition); } }
/// <summary> /// Adds a waypoint at the given index position in the path /// </summary> /// <param name="targetPosition">The target position in world coordinates</param> /// <param name="index">Position in the waypoint list where the target should be inserted at</param> public void AddWaypointAt(Vector2 targetPosition, int index) { if (index < 0) { throw new IndexOutOfRangeException(); } if (!WaypointList.Any()) { WaypointList.AddLast(targetPosition); } var currentIndex = 0; var currentNode = WaypointList.First; while (currentIndex < index) { if (currentNode == WaypointList.Last) { if (index > currentIndex + 1) { throw new IndexOutOfRangeException(); } WaypointList.AddLast(targetPosition); return; } else { currentNode = currentNode.Next; currentIndex++; } } WaypointList.AddBefore(currentNode, targetPosition); }