Esempio n. 1
0
 /// <summary>
 /// Finds a simulator in the scene.
 ///
 /// Saves found simulator in <see cref="sim"/>.
 ///
 /// \throws System.InvalidOperationException When no RVOSimulator could be found.
 /// </summary>
 protected void FindSimulator()
 {
     if (RVOSimulator.active == null)
     {
         throw new System.InvalidOperationException("No RVOSimulator could be found in the scene. Please add one to any GameObject");
     }
     sim = RVOSimulator.active.GetSimulator();
 }
Esempio n. 2
0
 /// <summary>Adds obstacles for a navmesh/recast graph</summary>
 void AddGraphObstacles(Pathfinding.RVO.ISimulator simulator, INavmesh navmesh)
 {
     GraphUtilities.GetContours(navmesh, (vertices, cycle) => {
         var verticesV3 = new Vector3[vertices.Count];
         for (int i = 0; i < verticesV3.Length; i++)
         {
             verticesV3[i] = (Vector3)vertices[i];
         }
         // Pool the 'vertices' list to reduce allocations
         ListPool <Int3> .Release(vertices);
         obstacles.Add(simulator.AddObstacle(verticesV3, wallHeight, cycle));
     });
 }
Esempio n. 3
0
        /// <summary>Adds obstacles for a grid graph</summary>
        void AddGraphObstacles(Pathfinding.RVO.ISimulator sim, GridGraph grid)
        {
            bool reverse = Vector3.Dot(grid.transform.TransformVector(Vector3.up), sim.MovementPlane == MovementPlane.XY ? Vector3.back : Vector3.up) > 0;

            GraphUtilities.GetContours(grid, vertices => {
                // Check if the contour is traced in the wrong direction from the one we want it in.
                // If we did not do this then instead of the obstacles keeping the agents OUT of the walls
                // they would keep them INSIDE the walls.
                if (reverse)
                {
                    System.Array.Reverse(vertices);
                }
                obstacles.Add(sim.AddObstacle(vertices, wallHeight, true));
            }, wallHeight * 0.4f);
        }