示例#1
0
        /// <inheritdoc />
        protected sealed override void OnUpdate()
        {
            //NativeHashmap can't resize when they are in concurent mode so prepare free place before
            _spatialHash.PrepareFreePlace((int)(_addGroup.CalculateEntityCount() * 1.5F)); //strangely resize just for the good length doesn't give enough space

            OnPreUpdate();

            Dependency = new AddSpatialHashingJob {
                SpatialHash = _spatialHash.ToConcurrent()
            }.Schedule(_addGroup, Dependency);
            Dependency = new AddSpatialHashingEndJob {
                CommandBuffer = CommandBuffer.AsParallelWriter()
            }.Schedule(_addGroup, Dependency);

            var updateRemoveJob = new UpdateSpatialHashingRemoveFastJob();

            updateRemoveJob.SetSpatialHash(ref _spatialHash);
            Dependency = updateRemoveJob.ScheduleSingle(_updateGroup, Dependency);
            Dependency = new UpdateSpatialHashingAddFastJob {
                SpatialHash = _spatialHash.ToConcurrent()
            }.Schedule(_updateGroup, Dependency);

            if (RemoveUpdateComponent)
            {
                CommandBuffer.RemoveComponent(_updateGroup, typeof(TZ)); //Remove all component from query
            }
            var removeJob = new RemoveSpatialHashingJob();

            removeJob.SetSpatialHash(ref _spatialHash);
            Dependency = removeJob.ScheduleSingle(_removeGroup, Dependency);

            CommandBuffer.RemoveComponent(_removeGroup, typeof(TY)); //Remove all component from query

            OnPostUpdate();

            AddJobHandleForProducer(Dependency);
        }