Ejemplo n.º 1
0
 // 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;
 }
Ejemplo n.º 2
0
        void Start()
        {
            // Ensure gameobject conversion when loading a scene
            World.All[0].GetOrCreateSystem <InitializationSystemGroup>().Update();

            _size = Plane.GetComponent <DotsNavPlane>().Size;
            FindObjectOfType <CameraController>().Initialize(_size);
            _r = new Random((uint)DateTime.Now.Ticks);

            var placedStarts = new List <Circle>();
            var placedGoals  = new List <Circle>();

            for (int i = 0; i < AgentAmount; i++)
            {
                var agent = Instantiate(AgentPrefab);

                var preferredSpeed = _r.NextFloat(PreferredSpeedMin, PreferredSpeedMin + PreferredSpeedRange);
                agent.GetComponent <DemoAgent>().PreferredSpeed            = preferredSpeed;
                agent.GetComponent <DotsNavLocalAvoidanceAgent>().MaxSpeed = preferredSpeed * MaxSpeedFactor;

                var r            = AgentMinRadius + i * AgentRadiusRange / AgentAmount;
                var dotsNavAgent = agent.GetComponent <DotsNavAgent>();
                dotsNavAgent.Radius        = r;
                dotsNavAgent.Plane         = Plane;
                agent.transform.localScale = new Vector3(r, r, r) * 2;

                var    cycles = 0;
                float2 pos;
                do
                {
                    pos = -_size / 2 + new float2(r + _r.NextFloat() * (_size.x - 2 * r), r + _r.NextFloat() * (SpawnRectHeight - 2 * r));
                } while (placedStarts.Any(p => math.length(p.Position - pos) < r + p.Radius) && ++cycles < 1000);

                agent.transform.position = pos.ToXxY();
                placedStarts.Add(new Circle {
                    Position = pos, Radius = r
                });

                cycles = 0;

                do
                {
                    pos = _size / 2 - new float2(r + _r.NextFloat() * (_size.x - 2 * r), r + _r.NextFloat() * (SpawnRectHeight - 2 * r));
                } while (placedGoals.Any(p => math.length(p.Position - pos) < r + p.Radius) && ++cycles < 1000);

                placedGoals.Add(new Circle {
                    Position = pos, Radius = r
                });

                agent.FindPath(pos.ToXxY());
            }

            Help.gameObject.SetActive(!Application.isEditor && !Closed);

            for (int i = 0; i < ObstacleAmount; i++)
            {
                Insert();
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
    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;
    }
Ejemplo n.º 5
0
        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;
        }