Beispiel #1
0
        public void SpawnChunkRenders(SpawnChunkRendersCommand command)
        {
            World world = World.EntityManager.GetComponentData <World>(command.world);

            if (Bootstrap.instance.isUseModels == false)
            {
                if (world.modelID != 0)
                {
                    return;
                }
            }
            if (World.EntityManager.HasComponent <ZoxID>(command.world) == false)
            {
                Debug.LogError("World does not have ZOXID but has modelID: " + world.modelID);
                return;
            }
            int worldID   = World.EntityManager.GetComponentData <ZoxID>(command.world).id;
            var materials = GetWorldMaterials(worldID);
            //int chunksCount = world.chunks.Length;
            //MapDatam map = null;
            VoxData model = new VoxData();
            NativeArray <Entity> renderEntities = new NativeArray <Entity>(command.renderEntitiesCount * command.materialsCount, Allocator.Temp);

            if (world.modelID == 0)
            {
                //map = worldSpawnSystem.maps[worldID];
                World.EntityManager.Instantiate(worldChunkRenderPrefab, renderEntities);
            }
            else //if (worldSpawnSystem.models.ContainsKey(worldID))
            {
                model = worldSpawnSystem.models[worldID];
                World.EntityManager.Instantiate(modelChunkRenderPrefab, renderEntities);
            }
            var chunkEntities     = world.chunks.ToArray();
            int renderEntityCount = 0;

            for (int i = 0; i < chunkEntities.Length; i++)
            {
                // need to bulk these too
                if (command.isRender[i] == 1)
                {
                    Chunk    chunk = World.EntityManager.GetComponentData <Chunk>(chunkEntities[i]);
                    Entity[] renderEntitiesSmall = new Entity[command.materialsCount];
                    for (int j = 0; j < renderEntitiesSmall.Length; j++)
                    {
                        renderEntitiesSmall[j] = renderEntities[renderEntityCount * command.materialsCount + j];
                    }
                    AddRenderEntitiesToChunk(chunkEntities[i], ref chunk, world, materials, chunk.GetVoxelPosition().ToFloat3(), renderEntitiesSmall, model);
                    World.EntityManager.SetComponentData(chunkEntities[i], chunk);
                    renderEntityCount++;
                }
            }
            renderEntities.Dispose();
        }
Beispiel #2
0
        public static void SpawnChunkRenders(EntityManager EntityManager, Entity world, int renderEntitiesCount, int materialsCount, byte[] isRender)
        {
            SpawnChunkRendersCommand newCommand = new SpawnChunkRendersCommand
            {
                world = world,
                renderEntitiesCount = renderEntitiesCount,
                materialsCount      = materialsCount,
                isRender            = new BlitableArray <byte>(isRender.Length, Allocator.Persistent)
            };

            for (int i = 0; i < isRender.Length; i++)
            {
                newCommand.isRender[i] = isRender[i];
            }
            Entity e = EntityManager.CreateEntity();

            EntityManager.AddComponentData(e, newCommand);
        }