コード例 #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //Prepare maps
            var nodes = new NativeArray <T>(_mapSize, Allocator.TempJob);

            var prepareNodesJob = new PrepareNodesJob
            {
                Nodes = nodes,
            };

            var prepareMapHandle = prepareNodesJob.Schedule(this, inputDeps);

            var sortNodesHandle = nodes.SortJob(prepareMapHandle);

            //Path Finding

            var pathFindingJob = new PathFindingJob
            {
                MapSize        = _mapSize,
                Nodes          = nodes,
                ResultECB      = resultECB.CreateCommandBuffer().ToConcurrent(),
                CleanECB       = cleanECB.CreateCommandBuffer().ToConcurrent(),
                IterationLimit = _iterationLimit,
                PathNodeLimit  = _pathNodeLimit
            };

            var pathFindingHandle = pathFindingJob.Schedule(this, sortNodesHandle);

            resultECB.AddJobHandleForProducer(pathFindingHandle);
            return(pathFindingHandle);
        }
コード例 #2
0
    protected override void OnUpdate()
    {
        NativeList <Node>      nodeList      = nodes;
        NativeList <Neighbour> neighbourList = neighbours;

        NativeList <JobHandle> pathFindDeps = new NativeList <JobHandle>(Allocator.Temp);
        List <PathFindingJob>  pathFindJobs = new List <PathFindingJob>();

        Entities.ForEach((Entity entity, ref AgentData agentData) =>
        {
            if (agentData.navMeshNodeIndex == -1)
            {
                FindClosestNodeToAgent closestNode = new FindClosestNodeToAgent
                {
                    agent = entity,
                    agentComponentData = GetComponentDataFromEntity <AgentData>(),
                    nodes = nodeList
                };

                pathFindDeps.Add(closestNode.Schedule());
            }

            if (!agentData.hasPath && agentData.navMeshNodeIndex != -1)
            {
                PathFindingJob PathFindJob = new PathFindingJob
                {
                    entity     = entity,
                    startIndex = agentData.navMeshNodeIndex,
                    endIndex   = UnityEngine.Random.Range(0, nodeList.Length - 1),
                    nodes      = nodeList,
                    neighbours = neighbourList,
                    parents    = new NativeArray <int>(nodeList.Length, Allocator.TempJob)
                                 //pathBuffer = GetBufferFromEntity<PathBuffer>()
                };

                pathFindDeps.Add(PathFindJob.Schedule());
                pathFindJobs.Add(PathFindJob);
            }
        });

        JobHandle.CompleteAll(pathFindDeps);

        foreach (PathFindingJob pfjob in pathFindJobs)
        {
            new AddToPathBuffer
            {
                endIndex           = pfjob.endIndex,
                entity             = pfjob.entity,
                nodes              = nodeList,
                neighbors          = neighbourList,
                pathBuffer         = GetBufferFromEntity <PathBuffer>(),
                agentComponentData = GetComponentDataFromEntity <AgentData>(),
                parents            = pfjob.parents
            }.Run();
        }

        pathFindDeps.Dispose();
    }