예제 #1
0
        public Rect GetTexture(Chunk chunk, ref Vector3Int localPos, Direction direction)
        {
            if (usesConnectedTextures)
            {
                ChunkBlocks blocks    = chunk.blocks;
                int         index     = Helpers.GetChunkIndex1DFrom3D(localPos.x, localPos.y, localPos.z);
                ushort      blockType = blocks.Get(index).Type;

                bool nw = ConnectedTextures.IsSame(blocks, index, -1, 1, direction, blockType);
                bool n  = ConnectedTextures.IsSame(blocks, index, 0, 1, direction, blockType);
                bool ne = ConnectedTextures.IsSame(blocks, index, 1, 1, direction, blockType);
                bool w  = ConnectedTextures.IsSame(blocks, index, -1, 0, direction, blockType);
                bool e  = ConnectedTextures.IsSame(blocks, index, 1, 0, direction, blockType);
                bool se = ConnectedTextures.IsSame(blocks, index, 1, -1, direction, blockType);
                bool s  = ConnectedTextures.IsSame(blocks, index, 0, -1, direction, blockType);
                bool sw = ConnectedTextures.IsSame(blocks, index, -1, -1, direction, blockType);

                return(connectedTextures[ConnectedTextures.GetTexture(n, e, s, w, nw, ne, se, sw)]);
            }

            if (textures.Count == 1)
            {
                return(textures[0]);
            }

            if (textures.Count > 1)
            {
                int hash = localPos.GetHashCode();
                if (hash < 0)
                {
                    hash *= -1;
                }

                float randomNumber = (hash % 100) / 100f;
                randomNumber *= textures.Count;

                return(textures[(int)randomNumber]);
            }


            Debug.LogError("There were no textures for " + textureName);
            return(new Rect());
        }
예제 #2
0
        public Rect GetTexture(Chunk chunk, Vector3Int localPos, Vector3Int globalPos, Direction direction)
        {
            if (usesConnectedTextures)
            {
                int blockType = chunk.world.blocks.Get(globalPos).Type;

                bool wn = ConnectedTextures.IsSame(chunk, globalPos, -1, 1, direction, blockType);
                bool n  = ConnectedTextures.IsSame(chunk, globalPos, 0, 1, direction, blockType);
                bool ne = ConnectedTextures.IsSame(chunk, globalPos, 1, 1, direction, blockType);
                bool w  = ConnectedTextures.IsSame(chunk, globalPos, -1, 0, direction, blockType);
                bool e  = ConnectedTextures.IsSame(chunk, globalPos, 1, 0, direction, blockType);
                bool es = ConnectedTextures.IsSame(chunk, globalPos, 1, -1, direction, blockType);
                bool s  = ConnectedTextures.IsSame(chunk, globalPos, 0, -1, direction, blockType);
                bool sw = ConnectedTextures.IsSame(chunk, globalPos, -1, -1, direction, blockType);

                return(connectedTextures[ConnectedTextures.GetTexture(n, e, s, w, wn, ne, es, sw)]);
            }

            if (textures.Count == 1)
            {
                return(textures[0]);
            }

            if (textures.Count > 1)
            {
                int hash = localPos.GetHashCode();
                if (hash < 0)
                {
                    hash *= -1;
                }

                float randomNumber = (hash % 100) / 100f;
                randomNumber *= textures.Count;

                return(textures[(int)randomNumber]);
            }


            Debug.LogError("There were no textures for " + textureName);
            return(new Rect());
        }