Exemplo n.º 1
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            if (Enemies.Length == 0)
            {
                return;
            }

            var randomizers = chunk.GetNativeArray(RandomizerType).Reinterpret <Random>();
            var entities    = chunk.GetNativeArray(EntityType);

            for (int i = 0; i < chunk.Count; i++)
            {
                if (randomizers[i].NextFloat(0f, 1f) >= Aggression)
                {
                    continue;
                }

                var target = Enemies[randomizers[i].NextInt(0, Enemies.Length)];
                CommandBuffer.AddComponent(chunkIndex, entities[i], new CTarget {
                    Value = target
                });
                CommandBuffer.AddSharedComponent(chunkIndex, entities[i], new STargetType {
                    Value = TargetTypes.Enemy
                });
            }
        }
        ///Not ready for prime time with BURST yet, maybe with DOTS 1.0
        public static Entity CreateDOTSEntityOnSvelto(int sortKey, EntityCommandBuffer.ParallelWriter writer,
                                                      Entity entityComponentPrefabEntity, EGID egid, bool mustHandleDOTSComponent)
        {
#if !SLOW_SVELTO_ECB
            Entity dotsEntity = writer.Instantiate(sortKey, entityComponentPrefabEntity);

            //SharedComponentData can be used to group the DOTS ECS entities exactly like the Svelto ones
            writer.AddSharedComponent(sortKey, dotsEntity, new DOTSSveltoGroupID(egid.groupID));
            writer.AddComponent(sortKey, dotsEntity, new DOTSSveltoEGID(egid));
            if (mustHandleDOTSComponent)
            {
                writer.AddSharedComponent(sortKey, dotsEntity, new DOTSEntityToSetup(egid.groupID));
            }

            return(dotsEntity);
#endif
            throw new NotSupportedException();
        }
Exemplo n.º 3
0
 public void AddSharedComponent <T>(T component) where T : struct, ISharedComponentData
 {
     _ecb.AddSharedComponent(_jobIndex, _entity, component);
 }