Exemple #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var query           = GetEntityQuery(typeof(Tag_Ennemy), ComponentType.ReadOnly <Position>());
            var targetEntities  = query.ToEntityArray(Allocator.TempJob);
            var targetPositions = query.ToComponentDataArray <Position>(Allocator.TempJob);

            var targets = new NativeArray <EntityWithPosition>(targetEntities.Length, Allocator.TempJob);

            for (var i = 0; i < targetEntities.Length; i++)
            {
                targets[i] = new EntityWithPosition()
                {
                    entity   = targetEntities[i],
                    position = targetPositions[i].Value
                };
            }

            targetEntities.Dispose();
            targetPositions.Dispose();

            var job = new SetTargetJob
            {
                targets = targets,
                ecb     = endSimulationEcbSystem.CreateCommandBuffer().ToConcurrent()
            };

            var handle = job.Schedule(this, inputDeps);

            endSimulationEcbSystem.AddJobHandleForProducer(handle);

            return(handle);
        }
Exemple #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            EntityQuery               eq           = GetEntityQuery(typeof(TargetTag), ComponentType.ReadOnly <Translation>());
            NativeArray <Entity>      entities     = eq.ToEntityArray(Allocator.TempJob);
            NativeArray <Translation> translations = eq.ToComponentDataArray <Translation>(Allocator.TempJob);

            NativeArray <EntityWithPosition> targetEntitysWithPosition = new NativeArray <EntityWithPosition>(entities.Length, Allocator.TempJob);

            for (int i = 0; i < entities.Length; i++)
            {
                targetEntitysWithPosition[i] = new EntityWithPosition()
                {
                    Entity   = entities[i],
                    Position = translations[i].Value
                };
            }

            entities.Dispose();
            translations.Dispose();

            NativeArray <Entity> foundTargets = new NativeArray <Entity>(
                GetEntityQuery(typeof(NPCTag), ComponentType.Exclude <HasTarget>()).CalculateEntityCount(),
                Allocator.TempJob);

            FindTargetJob findTargetJob = new FindTargetJob()
            {
                TargetArray     = targetEntitysWithPosition,
                SelectedTargets = foundTargets
            };
            JobHandle findTargetJobHandle = findTargetJob.Schedule(this, inputDeps);

            SetTargetJob setTargetJob = new SetTargetJob()
            {
                EntityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
                TargetArray         = foundTargets
            };
            JobHandle setTargetJobHandle = setTargetJob.Schedule(this, findTargetJobHandle);

            endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(setTargetJobHandle);
            return(setTargetJobHandle);
        }