示例#1
0
        public void UpdateObstacle(ObstacleVertex obstacle, Int3[] vertices, Matrix4x4 matrix)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException("Vertices must not be null");
            }
            if (obstacle == null)
            {
                throw new ArgumentNullException("Obstacle must not be null");
            }
            if (vertices.Length < 2)
            {
                throw new ArgumentException("Less than 2 vertices in an obstacle");
            }
            if (obstacle.split)
            {
                throw new ArgumentException("Obstacle is not a start vertex. You should only pass those ObstacleVertices got from AddObstacle method calls");
            }
            if (this.Multithreading && this.doubleBuffering)
            {
                for (int i = 0; i < this.workers.Length; i++)
                {
                    this.workers[i].WaitOne();
                }
            }
            int            index = 0;
            ObstacleVertex next  = obstacle;

            do
            {
                while (next.next.split)
                {
                    next.next      = next.next.next;
                    next.next.prev = next;
                }
                if (index >= vertices.Length)
                {
                    Debug.DrawLine((Vector3)next.prev.position, (Vector3)next.position, Color.red);
                    throw new ArgumentException("Obstacle has more vertices than supplied for updating (" + vertices.Length + " supplied)");
                }
                next.position = (Int3)matrix.MultiplyPoint3x4((Vector3)vertices[index]);
                index++;
                next = next.next;
            }while (next != obstacle);
            next = obstacle;
            do
            {
                Int3 num3 = next.next.position - next.position;
                next.dir = num3.xz.normalized;
                next     = next.next;
            }while (next != obstacle);
            this.ScheduleCleanObstacles();
            this.UpdateObstacles();
        }
示例#2
0
        public ObstacleVertex AddObstacle(Int3[] vertices, int height, Matrix4x4 matrix, RVOLayer layer = (RVOLayer)2)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException("Vertices must not be null");
            }
            if (vertices.Length < 2)
            {
                throw new ArgumentException("Less than 2 vertices in an obstacle");
            }
            ObstacleVertex item    = null;
            ObstacleVertex vertex2 = null;
            bool           flag    = matrix == Matrix4x4.identity;

            if (this.Multithreading && this.doubleBuffering)
            {
                for (int j = 0; j < this.workers.Length; j++)
                {
                    this.workers[j].WaitOne();
                }
            }
            for (int i = 0; i < vertices.Length; i++)
            {
                ObstacleVertex vertex3 = new ObstacleVertex();
                if (item == null)
                {
                    item = vertex3;
                }
                else
                {
                    vertex2.next = vertex3;
                }
                vertex3.prev     = vertex2;
                vertex3.layer    = layer;
                vertex3.position = !flag ? ((Int3)matrix.MultiplyPoint3x4((Vector3)vertices[i])) : vertices[i];
                vertex3.height   = height;
                vertex2          = vertex3;
            }
            vertex2.next = item;
            item.prev    = vertex2;
            ObstacleVertex next = item;

            do
            {
                Int3 num3 = next.next.position - next.position;
                next.dir = num3.xz.normalized;
                next     = next.next;
            }while (next != item);
            this.obstacles.Add(item);
            this.UpdateObstacles();
            return(item);
        }
示例#3
0
 public void RemoveObstacle(ObstacleVertex v)
 {
     if (v == null)
     {
         throw new ArgumentNullException("Vertex must not be null");
     }
     if (this.Multithreading && this.doubleBuffering)
     {
         for (int i = 0; i < this.workers.Length; i++)
         {
             this.workers[i].WaitOne();
         }
     }
     this.obstacles.Remove(v);
     this.UpdateObstacles();
 }
示例#4
0
 public void OnEnable()
 {
     if (this.addedObstacles != null)
     {
         if (this.sim == null)
         {
             throw new Exception("This should not happen! Make sure you are not overriding the OnDisable function");
         }
         for (int i = 0; i < this.addedObstacles.Count; i++)
         {
             ObstacleVertex next    = this.addedObstacles[i];
             ObstacleVertex vertex2 = next;
             do
             {
                 next.layer = this.layer;
                 next       = next.next;
             }while (next != vertex2);
             this.sim.AddObstacle(this.addedObstacles[i]);
         }
     }
 }
示例#5
0
        private void CleanObstacles()
        {
            for (int i = 0; i < this.obstacles.Count; i++)
            {
                ObstacleVertex vertex = this.obstacles[i];
                ObstacleVertex next   = vertex;
                goto Label_0038;
Label_001B:
                next.next      = next.next.next;
                next.next.prev = next;
Label_0038:
                do
                {
                    if (next.next.split)
                    {
                        goto Label_001B;
                    }
                    next = next.next;
                }while (next != vertex);
            }
        }