示例#1
0
    public void GenerateTerrain(int x, int y, int z, int value, int face, BlockTerrain.Chunk chunk, ref CellFace data)
    {
        int?color = GetColor(BlockTerrain.GetData(value));

        data.TextureSlot = color.HasValue ? BlocksData.paintedTextures[TextureSlot] : TextureSlot;
        data.Color       = BlocksData.ColorFromInt(color);
    }
示例#2
0
    public void LoadBlocks()
    {
        // Load from file
        BlocksData = BlocksData.Load(FilePath);

        // remove current scene blocks
        foreach (var sceneBlock in SceneBlocks)
        {
            // Have to se destroyImmediate in editmode
            if (Application.isEditor && !Application.isPlaying)
            {
                DestroyImmediate(sceneBlock.gameObject);
            }
            else
            {
                Destroy(sceneBlock.gameObject);
            }
        }

        // instantiate and setup prefab foreach block in data
        foreach (var block in BlocksData.Blocks)
        {
            var newBlock = Instantiate(BlockPrefab, block.Position, Quaternion.identity, transform);
            newBlock.name = block.Name;

            // don't forget to add it to the list of sceneBlocks
            SceneBlocks.Add(newBlock.transform);
        }
    }
示例#3
0
        // Returns the list of blocks starting from given hash
        public BlocksData BlocksStable(string hash)
        {
            const int limit = 100;

            if (string.IsNullOrEmpty(hash))
            {
                hash = _indexService.GetIndexData(Net).LastBlocks[0].Hash;
            }

            var lastBlock = _indexService.GetIndexData(Net).LastBlockData.LastBlock;
            var lastPage  = ConvUtils.GetNumPages(lastBlock, limit);

            using (var client = CreateApi())
            {
                var blocks        = client.PoolListGetStable(ConvUtils.ConvertHashBack(hash), limit + 1).Pools.Select(p => new BlockInfo(p)).ToList();
                var blocksLimited = blocks.Take(limit).ToList();

                var result = new BlocksData
                {
                    Blocks       = blocksLimited,
                    HaveNextPage = blocks.Count > limit,
                    LastPage     = lastPage,
                    NumStr       = blocksLimited.Any() ? $"{blocksLimited.Last().Number} - {blocksLimited.First().Number} of total {lastBlock}" : "-",
                    LastBlock    = lastBlock
                };
                return(result);
            }
        }
示例#4
0
        // Returns the list of blocks on given page, from cache
        public BlocksData Blocks(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            var lastBlock = _indexService.GetIndexData(Net).LastBlockData.LastBlock;
            var lastPage  = ConvUtils.GetNumPages(IndexService.SizeOutAll, limit);

            // Get the list of cached blocks, from given page (we cache last 100K blocks)
            var blocks = _indexService.GetPools(Net, (page - 1) * limit, limit);

            // Prepare all data for page and return
            var result = new BlocksData
            {
                Page         = page,
                Blocks       = blocks,
                HaveNextPage = page < lastPage,
                LastPage     = lastPage,
                NumStr       = blocks.Any() ? $"{blocks.Last().Number} - {blocks.First().Number} of total {lastBlock}" : "-",
                LastBlock    = lastBlock
            };

            return(result);
        }
示例#5
0
 private void Awake()
 {
     _childrenLeft = GetComponentsInChildren <Enemy>().Length;
     _score        = Resources.Load <ScoreData>("Global/Data/ScoreData");
     _blocksData   = Resources.Load <BlocksData>("EnemyBlocks/AllBlocks");
     _blocksData.Blocks[GetNearest()] = _blocksData.Blocks[GetNearest()].OrderBy(x => _rng.Next()).ToList();
     _spawnBlockEvent = Resources.Load <GameEvent>("EnemyBlocks/Events/SpawnBlock");
 }
示例#6
0
    public List <string> LoadNames()
    {
        string filePath = System.IO.Path.Combine(Application.persistentDataPath, "BlocksData.json");

        if (File.Exists(filePath))
        {
            string     data       = System.IO.File.ReadAllText(filePath);
            BlocksData blocksData = JsonUtility.FromJson <BlocksData>(data);;
            return(blocksData.blockNames);
        }
        else
        {
            Debug.Log("ERROR - FILE NOT FOUND!");
            return(null);
        }
    }
示例#7
0
    public void AllNormalBlockTimeTrial()
    {
        BlockMeshes meshes = new BlockMeshes();

        meshes.Initialize();
        BlocksData data = new BlocksData();

        data.Initialize();

        BlockTerrain.Chunk chunk = new BlockTerrain.Chunk(16, 128, 16);
        MeshGenerator      g     = new MeshGenerator();

        Stopwatch stopwatch = new Stopwatch();

        int count = BlocksData.Blocks.Length;

        for (int i = 0; i < count; i++)
        {
            if (BlocksData.IsTransparent[i])
            {
                try
                {
                    stopwatch.Reset();
                    stopwatch.Start();
                    for (int k = 0; k < 50; k++)
                    {
                        BlocksData.NormalBlocks[i].GenerateTerrain(1, 1, 1, i, chunk, g);
                    }
                    stopwatch.Stop();
                    UnityEngine.Debug.LogFormat("tested block: {0}; time: {1}ms", BlocksData.Blocks[i].Name, stopwatch.ElapsedMilliseconds);
                }
                catch (System.Exception e)
                {
                    //UnityEngine.Debug.LogException(e);
                }
            }
        }
    }
示例#8
0
    public void GenerateFurnitureMeshAlphaTest(FurnitureManager.Furniture furniture, out MeshData mesh)
    {
        Block[] blocks = BlocksData.Blocks;

        int       res         = furniture.Resolution;
        Matrix4x4 matrix      = Matrix4x4.Scale(Vector3.one / res);
        float     uvBlockSize = 0.0625f / res;

        int[] mask = new int[res * res];
        int   u, v, n, w, h, j, i, l, k;

        int[] off;
        int[] x;

        for (int d = 0; d < 3; d++)
        {
            off = new int[] { 0, 0, 0 };
            x   = new int[] { 0, 0, 0 };
            u   = (d + 1) % 3;
            v   = (d + 2) % 3;

            off[d] = 1;

            for (x[d] = -1; x[d] < res;)
            {
                //Debug.LogFormat("x[d]: {0}", x[d]);
                mask = new int[res * res];
                for (n = 0; n < mask.Length; n++)
                {
                    mask[n] = -1;
                }

                n = 0;
                for (x[v] = 0; x[v] < res; x[v]++)
                {
                    for (x[u] = 0; x[u] < res; x[u]++)
                    {
                        int va = furniture.GetCellValue(x[0], x[1], x[2]);
                        int vb = furniture.GetCellValue(x[0] + off[0], x[1] + off[1], x[2] + off[2]);
                        int ia = BlockTerrain.GetContent(va);
                        int ib = BlockTerrain.GetContent(vb);
                        //Debug.LogFormat("{0} and {1}: {2}, {3}", new Point3(x[0], x[1], x[2]), new Point3(x[0] + off[0], x[1] + off[1], x[2] + off[2]), a.Name, b.Name);
                        if (ia == 0 && ib != 0)
                        {
                            Block b = blocks[ib];
                            mask[n]  = b.TextureSlot;
                            mask[n] |= BlocksData.GetBlockColorInt(b, vb) << 8;
                            mask[n] |= 4096;
                        }
                        else if (ia != 0 && ib == 0)
                        {
                            Block a = blocks[ia];
                            mask[n]  = a.TextureSlot;
                            mask[n] |= BlocksData.GetBlockColorInt(a, va) << 8;
                        }
                        n++;
                    }
                }

                ++x[d];
                n = 0;
                for (j = 0; j < res; j++)
                {
                    for (i = 0; i < res;)
                    {
                        if (mask[n] != -1)
                        {
                            for (w = 1; i + w < res && mask[w + n] == mask[n]; w++)
                            {
                            }
                            for (h = 1; h + j < res; h++)
                            {
                                for (k = 0; k < w; k++)
                                {
                                    if (mask[n + k + h * res] != mask[n])
                                    {
                                        goto Done;
                                    }
                                }
                            }
Done:
                            //Debug.LogFormat("quard: {0}, {1}, {2}, {3}; {4}", j, i, h, w, x[d]);

                            x[u] = i;
                            x[v] = j;
                            int[] du = new int[] { 0, 0, 0 };
                            int[] dv = new int[] { 0, 0, 0 };
                            du[u] = w;
                            dv[v] = h;

                            int textureSlot = mask[n] & 255;
                            if (mask[n] >> 12 == 0)
                            {
                                Terrain.FurnitureQuad(
                                    new Vector3(x[0], x[1], x[2]),
                                    new Vector3(x[0] + du[0], x[1] + du[1], x[2] + du[2]),
                                    new Vector3(x[0] + du[0] + dv[0], x[1] + du[1] + dv[1], x[2] + du[2] + dv[2]),
                                    new Vector3(x[0] + dv[0], x[1] + dv[1], x[2] + dv[2]),
                                    x[u], x[v], w, h, uvBlockSize,
                                    textureSlot,
                                    BlocksData.DEFAULT_COLORS[(mask[n] >> 8) & 15]
                                    );
                            }
                            else
                            {
                                Terrain.FurnitureQuad(
                                    new Vector3(x[0], x[1], x[2]),
                                    new Vector3(x[0] + dv[0], x[1] + dv[1], x[2] + dv[2]),
                                    new Vector3(x[0] + du[0] + dv[0], x[1] + du[1] + dv[1], x[2] + du[2] + dv[2]),
                                    new Vector3(x[0] + du[0], x[1] + du[1], x[2] + du[2]),
                                    x[v], x[u], h, w, uvBlockSize,
                                    textureSlot,
                                    BlocksData.DEFAULT_COLORS[(mask[n] >> 8) & 15]
                                    );
                            }

                            for (l = 0; l < h; l++)
                            {
                                for (k = 0; k < w; k++)
                                {
                                    mask[n + k + l * res] = -1;
                                }
                            }
                            i += w;
                            n += w;
                        }
                        else
                        {
                            i++;
                            n++;
                        }
                    }
                }
            }
        }

        //Debug.LogFormat("{0}, {1}, {2}", vertices.Count, colors.Count, uvs.Count);

        Terrain.PushToMesh(out mesh);
        MeshData.Transform(mesh, matrix);
    }
示例#9
0
 public void Dispose()
 {
     BlocksData?.Dispose();
     BlocksOffsetsData?.Dispose();
 }