public static Entity GenerateEntity(EntityCommandBuffer.ParallelWriter ecb, int jobIndex, ProceduralGenerationSpawnData spawnData)
        {
            Entity entity = ecb.CreateEntity(jobIndex);

            // ecb.addComponent(entity,new ProceduralGenerationElement(ecb, proceduralAreaEntity, spawnData.EntityPrefab));
            return(entity);
        }
        void IJobChunk.Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <SouffleDeFeuStats> _souffleStatsArray   = chunk.GetNativeArray(_souffleHandle);
            NativeArray <AbilityPerform>    _abilityPerformArray = chunk.GetNativeArray(_abilityPerform);
            NativeArray <Entity>            _entityArray         = chunk.GetNativeArray(_entityHandle);

            for (int i = 0; i < chunk.ChunkEntityCount; i++)
            {
                //_ecb.CreateEntity(chunkIndex, _souffleDeFeu);
                if (_abilityPerformArray[i]._couldownSkillOne <= 0)
                {
                    SouffleDeFeuTemp _souffleDeFeuTemp = new SouffleDeFeuTemp
                    {
                        _damage   = _souffleStatsArray[i]._damage,
                        _position = _souffleStatsArray[i]._position,
                        _radius   = _souffleStatsArray[i]._radius,
                        _team     = _souffleStatsArray[i]._team
                    };
                    Entity     _entityTemp    = _ecb.CreateEntity(chunkIndex, _souffleDeFeu);
                    int        _newHashRegion = Mathf.RoundToInt(_souffleStatsArray[i]._position.x * GameSetting.MAP_WIDTH + _souffleStatsArray[i]._position.y);
                    HashRegion _hRegion       = new HashRegion()
                    {
                        _hashRegion = 1
                    };
                    _ecb.SetComponent <SouffleDeFeuTemp>(chunkIndex, _entityTemp, _souffleDeFeuTemp);
                    _ecb.SetSharedComponent <HashRegion>(chunkIndex, _entityTemp, _hRegion);
                }
            }
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> _entityArray = chunk.GetNativeArray(_entityHandle);
            EntityArchetype      _archetype   = _entityArchetype;

            _ecb.CreateEntity(chunkIndex, _archetype);
        }
Пример #4
0
            public void Execute()
            {
                if (!queue.TryDequeue(out Spawn spawn))
                {
                    return;
                }

                var entity = spawn.Prefab.Equals(Entity.Null) ? CommandBuffer.CreateEntity(nativeThreadIndex) : CommandBuffer.Instantiate(nativeThreadIndex, spawn.Prefab);

                foreach (IBufferElementData buffer in spawn.BufferList)
                {
                    addBuffer.MakeGenericMethod(buffer.GetType()).Invoke(
                        CommandBuffer,
                        new object[] { nativeThreadIndex, entity }
                        );
                }

                foreach (IComponentData component in spawn.ComponentList)
                {
                    addComponent.MakeGenericMethod(component.GetType()).Invoke(
                        CommandBuffer,
                        new object[] { nativeThreadIndex, entity, component }
                        );
                }
            }
        protected override void OnUpdate()
        {
            // The command buffer to record commands,
            // which are executed by the command buffer system later in the frame
            EntityCommandBuffer.ParallelWriter commandBuffer
                = CommandBufferSystem.CreateCommandBuffer().AsParallelWriter();
            //The DataToSpawn component tells us how many entities with buffers to create
            Entities.ForEach((Entity spawnEntity, int entityInQueryIndex, in DataToSpawn data) =>
            {
                for (int e = 0; e < data.EntityCount; e++)
                {
                    //Create a new entity for the command buffer
                    Entity newEntity = commandBuffer.CreateEntity(entityInQueryIndex);

                    //Create the dynamic buffer and add it to the new entity
                    DynamicBuffer <MyBufferElement> buffer =
                        commandBuffer.AddBuffer <MyBufferElement>(entityInQueryIndex, newEntity);

                    //Reinterpret to plain int buffer
                    DynamicBuffer <int> intBuffer = buffer.Reinterpret <int>();

                    //Optionally, populate the dynamic buffer
                    for (int j = 0; j < data.ElementCount; j++)
                    {
                        intBuffer.Add(j);
                    }
                }

                //Destroy the DataToSpawn entity since it has done its job
                commandBuffer.DestroyEntity(entityInQueryIndex, spawnEntity);
            }).ScheduleParallel();

            CommandBufferSystem.AddJobHandleForProducer(this.Dependency);
        }
Пример #6
0
 /// <summary>
 /// Use this to initialize a dynamic buffer just to temporary use other wise use AddBuffer()
 /// </summary>
 /// <param name="ecb"></param>
 /// <param name="addBuffer"></param>
 public DynamicBufferEntityBufferElement(EntityCommandBuffer.ParallelWriter ecb, int jobIndex, bool addBuffer = false)
 {
     mEntity = ecb.CreateEntity(jobIndex);
     if (addBuffer)
     {
         ecb.AddBuffer <EntityBufferElement>(jobIndex, mEntity);
     }
 }
Пример #7
0
 public DynamicBufferColorKeyDataBufferElement(EntityCommandBuffer.ParallelWriter ecb, int jobIndex)
 {
     this.dataEntity = ecb.CreateEntity(jobIndex);
     this.buffer     = ecb.AddBuffer <ColorKeyDataBufferElement>(jobIndex, dataEntity);
     this.buffer.Add(new ColorKeyDataBufferElement {
         Value = new ColorKeyData(float3.zero, 0)
     });
     this.buffer.Add(new ColorKeyDataBufferElement {
         Value = new ColorKeyData(new float3(1f, 1f, 1f), 1)
     });
 }
 /// <summary>
 /// sets up the entity and buffer for entity prefab
 /// </summary>
 /// <param name="ecb"></param>
 /// <param name="jobIndex"></param>
 public static void SetupPrefabs(EntityCommandBuffer.ParallelWriter ecb, int jobIndex)
 {
     if (AllSpawnDatas.dataEntity == Entity.Null)
     {
         AllSpawnDatas.dataEntity = ecb.CreateEntity(jobIndex);
         AllSpawnDatas.buffer     = ecb.AddBuffer <EntityPrefabBufferElement>(jobIndex, AllSpawnDatas.dataEntity);
         Debug.Log("Entity_Prefab: static entity and buffer is setup");
     }
     else
     {
         Debug.LogWarning("Entity_Prefab: data are already setup.");
     }
 }
Пример #9
0
            public void Execute()
            {
                var levelRequest = commandBuffer.CreateEntity(0);

                commandBuffer.AddComponent(0, levelRequest, new CreateLevelRequest
                {
                    position = new int2(0, 0),
                    size     = new int2(width, height)
                });

                var player = commandBuffer.Instantiate(0, playerPrefab.value);

                commandBuffer.SetComponent(0, player, new Translation {
                    Value = float3.zero
                });
            }
Пример #10
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        float  deltaTime   = Time.DeltaTime;
        double elapsedTime = Time.ElapsedTime;
        float3 moveDir     = new float3(-1f, 0f, 0f);
        float  moveSpeed   = 4f;

        EntityCommandBuffer entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer();

        EntityCommandBuffer.ParallelWriter entityCommandBufferParallelWriter = entityCommandBuffer.AsParallelWriter();
        EntityArchetype eventEntityArchetype = EntityManager.CreateArchetype(typeof(EventComponent));

        double ElapsedTime = Time.ElapsedTime;

        JobHandle jobHandle = Entities.ForEach((int entityInQueryIndex, ref Translation translation, ref TestData pipe) =>
        {
            float xBefore      = translation.Value.x;
            translation.Value += moveDir * moveSpeed * deltaTime;
            float xAfter       = translation.Value.x;

            if (pipe.isTrigger && xBefore > 0 && xAfter <= 0)
            {
                // Passed the Player
                Entity eventEntity = entityCommandBufferParallelWriter.CreateEntity(entityInQueryIndex, eventEntityArchetype);
                entityCommandBufferParallelWriter.SetComponent(entityInQueryIndex, eventEntity, new EventComponent
                {
                    ElapsedTime = ElapsedTime
                });
            }
        }).Schedule(inputDeps);

        endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

        EntityCommandBuffer captureEventsEntityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer();

        Entities.WithoutBurst().ForEach((Entity entity, ref EventComponent eventComponent) =>
        {
            Debug.Log(eventComponent.ElapsedTime + " ### " + ElapsedTime);
            OnPipePassed?.Invoke(this, EventArgs.Empty);
            captureEventsEntityCommandBuffer.DestroyEntity(entity);
        }).Run();

        return(jobHandle);
    }
Пример #11
0
        public void Execute(int index)
        {
            var chosenEntity      = ChosenEntities[index];
            var chosenEntityValue = IntBufferData[chosenEntity][0].Value;

            var chosenBoolBuffer = BoolBufferData[chosenEntity];

            if (chosenBoolBuffer[0].Value)
            {
                return;
            }

            var updatedBuffer = ECB.SetBuffer <BoolData>(index, chosenEntity);

            updatedBuffer.Add(new BoolData {
                Value = true
            });

            var generatedBuffer = ECB.AddBuffer <GeneratedEntityData>(index, chosenEntity);

            for (int i = 0; i < NumbersToAdd.Length; i++)
            {
                var numToAdd = NumbersToAdd[i];

                var newEntity = ECB.CreateEntity(index);
                var intBuffer = ECB.AddBuffer <IntData>(index, newEntity);
                intBuffer.Add(new IntData {
                    Value = chosenEntityValue + numToAdd
                });
                var boolBuffer = ECB.AddBuffer <BoolData>(index, newEntity);
                boolBuffer.Add(new BoolData {
                    Value = false
                });

                generatedBuffer.Add(new GeneratedEntityData {
                    GeneratedEntity = newEntity
                });
            }
        }
    protected override void OnUpdate()
    {
        EntityArchetype roadArch = roadSegmentArchitecture;

        EntityCommandBuffer.ParallelWriter ecb = entityCommandBuffer.CreateCommandBuffer().AsParallelWriter();
        Entities.ForEach((Entity entity, int entityInQueryIndex, in CubicBezier cubicBezier) =>
        {
            // Todo: IJobParallelFor
            float t   = 1.0f / cubicBezier.segments;
            float3 p1 = cubicBezier.p0;
            for (int i = 1; i <= cubicBezier.segments; i++)
            {
                float3 p2 = Evaluate(cubicBezier, t * i);
                Entity e  = ecb.CreateEntity(entityInQueryIndex, roadArch);
                ecb.SetComponent(entityInQueryIndex, e, new RoadSegment
                {
                    initial = p1,
                    final   = p2
                });
                p1 = p2;
            }
            ecb.DestroyEntity(entityInQueryIndex, entity);
        }).ScheduleParallel(Dependency).Complete(); // Do not schedule parallel. It will operate on only one element any
    }
Пример #13
0
 public void TriggerEvent(int entityInQueryIndex)
 {
     entityCommandBufferConcurrent.CreateEntity(entityInQueryIndex, entityArchetype);
 }
Пример #14
0
 public void TriggerEvent(int entityInQueryIndex)
 {
     parallelWriter.CreateEntity(entityInQueryIndex, entityArchetype);
 }
Пример #15
0
 public void TriggerEvent(int entityInQueryIndex)
 {
     entityCommandBufferParallelWriter.CreateEntity(entityInQueryIndex, entityArchetype);
 }
Пример #16
0
 public Entity Create(EntityArchetype archetype = new EntityArchetype())
 {
     return(_ecb.CreateEntity(_jobIndex, archetype));
 }
 public DynamicBufferEntityPrefab(EntityCommandBuffer.ParallelWriter ecb, int jobIndex)
 {
     dataEntity = ecb.CreateEntity(jobIndex);
     buffer     = ecb.AddBuffer <EntityPrefabBufferElement>(jobIndex, dataEntity);
 }