// Navmeshes can be created by instatiating prefabs. Obstacles can then be added by // instantiating prefabs. Both can later be disposed of by destroying the created // gameobjects. Static obstacles however can be inserted in bulk by providing a Burst // compatible obstacle adder as seen below. void Load() { _plane = Instantiate(PlanePrefab); _plane.GetComponent <DotsNavPlane>().Size = Size; _navmesh = _plane.GetComponent <DotsNavNavmesh>(); _navmesh.DrawMode = _drawMode; _shouldInsert = true; }
// Navmeshes can be created by instatiating prefabs. Obstacles can then be added by // instantiating prefabs. Both can later be disposed of by destroying the created // gameobjects. Static obstacles however can be inserted in bulk by providing a Burst // compatible obstacle adder as seen below. void Load() { _navmesh = Instantiate(NavmeshPrefab); _navmesh.DrawMode = _drawMode; var r = new Random((uint)Seed); var amount = _navmesh.InsertObstacleBulk(Amount, new ObstacleAdder(ScaleOffset, Size, r, _vertices, _startEnds)); Output.text = $"Loaded {Amount} obstacles and {amount} vertices\nPress R to reload"; }
/// <summary> /// Casts a ray and reports any collisions found. The entire line segment should be inside the navmesh. /// Collisions are reported in order of their distance from the origin of the line segment. /// </summary> /// <param name="from">The origin of the line segment, needs to be contained in the navmesh</param> /// <param name="to">The destination of the line segment, needs to be contained in the navmesh</param> /// <param name="collectAllHits">Set to false to stop searching after the first collision</param> public static RayCastResult CastSegment(this DotsNavNavmesh navmesh, Vector2 from, Vector2 to, bool collectAllHits = false) { var output = new NativeList <RayCastHit>(Allocator.Persistent); if (navmesh.IsInitialized) { new SegmentCastJob { Input = new SegmentCast(from, to, collectAllHits, output), Navmesh = navmesh.GetNativeNavmesh(), } }
void Awake() { // Ensure gameobject conversion when loading a scene World.All[0].GetOrCreateSystem <InitializationSystemGroup>().Update(); _navmesh = Plane.GetComponent <DotsNavNavmesh>(); FindObjectOfType <CameraController>().Initialize(Plane.Size); _startTime = Time.time; _r = new Random((uint)Seed); UpdateSeedText(); Help.gameObject.SetActive(!Application.isEditor); }
void Awake() { _navmesh = Plane.GetComponent <DotsNavNavmesh>(); foreach (var obstacle in FindObjectsOfType <DotsNavObstacle>()) { var l = new List <Vector2>(); for (int i = 0; i < obstacle.Vertices.Length; i++) { l.Add(obstacle.GetVertexWorldSpace(i).xz); } _toDump.Add(l); } _cameraController = FindObjectOfType <CameraController>(); _cameraController.Initialize(Plane.Size); _lineDrawer = GetComponent <LineDrawer>(); _camera = Camera.main; Help.gameObject.SetActive(!Application.isEditor); _agent = FindObjectOfType <DotsNavPathFindingAgent>(); var tr = _agent.transform; _start = tr.parent; _goal = _start.Find("Goal"); _goal.parent = null; if (Reverse) { var tempPos = _start.position; _start.position = _goal.position; _goal.position = tempPos; } var size = _start.localScale.x; var s = new Vector3(size, size, size); _goal.localScale = s; _agent.GetComponent <DotsNavAgent>().Radius = size / 2; }
void Start() { // Ensure gameobject conversion when loading a scene World.All[0].GetOrCreateSystem <InitializationSystemGroup>().Update(); _navmesh = Plane.GetComponent <DotsNavNavmesh>(); _cameraController = FindObjectOfType <CameraController>(); _cameraController.Initialize(Plane.Size, .5f); _lineDrawer = GetComponent <LineDrawer>(); _camera = Camera.main; Help.gameObject.SetActive(!Application.isEditor); _agent = FindObjectOfType <DotsNavPathFindingAgent>(); var tr = _agent.transform; _start = tr.parent; _goal = _start.Find("Goal"); _goal.parent = null; var size = _start.localScale.x; var s = new Vector3(size, size, size); _goal.localScale = s; _agent.GetComponent <DotsNavAgent>().Radius = size / 2; }