Exemple #1
0
        private LinkedListNode <Vector2> PeekPrev()
        {
            if (!WaypointList.Any())
            {
                return(null);
            }

            if (current != WaypointList.First)
            {
                return(current.Next);
            }
            else if (current == WaypointList.First && IsClosedNavMesh)
            {
                return(waypointList.Last);
            }
            else   /*if (current == WaypointList.First && !IsClosedNavMesh)*/
            {
                return(null);
            }
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
 /// <summary>
 /// Checks if the waypoint list is empty or null.
 /// </summary>
 public bool IsEmpty()
 {
     return(WaypointList == null || !WaypointList.Any());
 }