Example #1
0
        public Rect GetTexture(Chunk chunk, BlockPos pos, Direction direction)
        {
            if (UsesConnectedTextures)
            {
                string blockName = chunk.GetBlock(pos).Controller.Name();

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

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

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

            if (m_Textures.Count > 1)
            {
                float randomNumber = m_NoiseGen.Generate(pos.x, pos.y, pos.z);
                randomNumber += 1;
                randomNumber /= 2;
                randomNumber *= m_Textures.Count;

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

            Debug.LogError("There were no textures for " + TextureName);
            return(new Rect());
        }
Example #2
0
        public void Load(bool loadEmpty = false)
        {
            if (!m_HasInited)
            {
                Debug.LogError("TextureIndex needs to be Initialized first!");
                return;
            }

            if (loadEmpty)
            {
                return;
            }

            List <Texture2D> atlasTextures = new List <Texture2D>();

            atlasTextures.AddRange(m_NormalTextures);

            if (m_ConnectedTextures.Count != 0)
            {
                atlasTextures.AddRange(ConnectedTextures.GenerateConnectedTextures(m_ConnectedTextures));
            }

            m_Atlas = new Texture2D(8192, 8192)
            {
                filterMode = FilterMode.Point
            };

            Rect[] rects = m_Atlas.PackTextures(atlasTextures.ToArray(), 0, 8192, false);

            for (int i = 0; i < atlasTextures.Count; i++)
            {
                if (!atlasTextures[i])
                {
                    continue;
                }

                string[] fileName = atlasTextures[i].name.ToString().Split('-');
                Rect     texture  = rects[i];

                string textureName          = fileName[0];
                int    connectedTextureType = -1;

                for (int n = 0; n < fileName.Length; n++)
                {
                    switch (fileName[n][0])
                    {
                    case 'c':
                        int.TryParse(fileName[n].Substring(1), out connectedTextureType);
                        break;

                    default:
                        break;
                    }
                }

                TextureCollection collection;
                if (!Textures.TryGetValue(textureName, out collection))
                {
                    collection = new TextureCollection(textureName);
                    Textures.Add(textureName, collection);
                }

                collection.AddTexture(texture, connectedTextureType);
            }
        }