Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new block with a specified color value index
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="color"></param>
        public static void AddCube(int x, int y, int z, int color)
        {
            if (Singleton == null)
            {
                return;
            }

            int chunkX   = Mathf.FloorToInt(x / 16f);
            int chunkY   = Mathf.FloorToInt(y / 16f);
            int chunkZ   = Mathf.FloorToInt(z / 16f);
            int chunkKey = Singleton.Vector3ToInt(chunkX, chunkY, chunkZ);

            ChunkController chunk = Singleton.GetChunkByBlock(x, y, z);

            if (chunk == null)
            {
                chunk = Singleton.CreateChunk(chunkX, chunkY, chunkZ);
                Singleton.chunks.Add(chunkKey, chunk);
            }

            int paletteWidth = ColorPaletteManager.GetPaletteWidth();
            int colorX       = color % paletteWidth;
            int colorY       = Mathf.FloorToInt(color / paletteWidth);

            chunk.AddCube(Mathf.Abs(x - chunkX * 16), Mathf.Abs(y - chunkY * 16), Mathf.Abs(z - chunkZ * 16), colorX, colorY);
        }
Ejemplo n.º 2
0
        public static Mesh GetCompleteMesh()
        {
            if (Singleton == null)
            {
                return(null);
            }

            var chunks   = Singleton.chunks.Values.ToArray();
            var combines = new CombineInstance[chunks.Length];

            for (int i = 0; i < chunks.Length; i++)
            {
                ChunkController chunk = chunks[i];

                combines[i].mesh      = chunk.GetMesh();
                combines[i].transform = chunk.transform.localToWorldMatrix;
            }

            var wholeMesh = new Mesh();

            wholeMesh.CombineMeshes(combines);

            wholeMesh.RecalculateNormals();
            wholeMesh.RecalculateTangents();
            wholeMesh.RecalculateBounds();

            return(wholeMesh);
        }
Ejemplo n.º 3
0
        public static void RemoveChunk(int x, int y, int z)
        {
            if (Singleton == null)
            {
                return;
            }

            ChunkController chunk = Singleton.GetChunk(x, y, z);

            if (chunk == null)
            {
                return;
            }

            Destroy(chunk.gameObject);
            Singleton.chunks.Remove(Singleton.Vector3ToInt(x, y, z));
        }
Ejemplo n.º 4
0
        public static void RemoveCube(int x, int y, int z)
        {
            if (Singleton == null)
            {
                return;
            }

            int chunkX = Mathf.FloorToInt(x / 16f);
            int chunkY = Mathf.FloorToInt(y / 16f);
            int chunkZ = Mathf.FloorToInt(z / 16f);

            ChunkController chunk = Singleton.GetChunkByBlock(x, y, z);

            if (chunk == null)
            {
                return;
            }

            chunk.RemoveCube(Mathf.Abs(x - chunkX * 16), Mathf.Abs(y - chunkY * 16), Mathf.Abs(z - chunkZ * 16));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new block using the current closestColor
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        public static void AddCube(int x, int y, int z)
        {
            if (Singleton == null)
            {
                return;
            }

            int chunkX   = Mathf.FloorToInt(x / 16f);
            int chunkY   = Mathf.FloorToInt(y / 16f);
            int chunkZ   = Mathf.FloorToInt(z / 16f);
            int chunkKey = Singleton.Vector3ToInt(chunkX, chunkY, chunkZ);

            ChunkController chunk = Singleton.GetChunkByBlock(x, y, z);

            if (chunk == null)
            {
                chunk = Singleton.CreateChunk(chunkX, chunkY, chunkZ);
                Singleton.chunks.Add(chunkKey, chunk);
            }

            var closestColor = ColorpickerController.GetClosestColor();

            chunk.AddCube(Mathf.Abs(x - chunkX * 16), Mathf.Abs(y - chunkY * 16), Mathf.Abs(z - chunkZ * 16), closestColor.x, closestColor.y);
        }