Exemplo n.º 1
0
        protected override void OnUpdate()
        {
            if (First)
            {
                Entities.ForEach((Entity entity, ref PathFindingData data) =>
                {
                    if (!hasDensityPresent && data.avoidMethod == CollisionAvoidanceMethod.DensityGrid)
                    {
                        hasDensityPresent = true;
                    }
                });
            }
            if (!hasDensityPresent)
            {
                return;
            }

            MapChanged();

            EntityQuery entityQuery = GetEntityQuery(typeof(Translation), typeof(Walker), typeof(CollisionParameters));

            var clearJob = new ClearJob()
            {
                array = densityMatrix
            };
            var clearHandle = clearJob.Schedule(densityMatrix.Length, batchSize);

            var job = new SetProbabilityJob()
            {
                quadrantHashMap = densityMatrix, oneLayer = Map.OneLayer, max = Map.Values
            };

            var handle = JobForEachExtensions.Schedule(job, entityQuery, clearHandle);

            ForeachColliders();
            var addJob = new AddArrayJob()
            {
                from = collidersDensity, to = densityMatrix
            };
            var addHandle = addJob.Schedule(densityMatrix.Length, batchSize, handle);

            addHandle.Complete();
            //Debug();
        }
        private void NewGoalPointAdded()
        {
            var clearJob = new ClearJob()
            {
                array    = densityMatrix,
                array2   = tempMatrix,
                minIndex = densityMatrix.Length - Map.OneLayer * (goalPoints.Length - LastGoalPointCount)
            };
            var clearHandle = clearJob.Schedule(densityMatrix.Length, batchSize);

            clearHandle.Complete();

            while (LastGoalPointCount < goalPoints.Length)
            {
                var index = QuadrantVariables.IndexFromPosition(goalPoints[LastGoalPointCount], float3.zero, Map.Values);
                densityMatrix[index.key + Map.OneLayer * LastGoalPointCount] = 0.5f;
                tempMatrix[index.key + Map.OneLayer * LastGoalPointCount]    = 0.5f;
                LastGoalPointCount++;
            }
        }