private TextureConfig[] LoadAllTextures()
        {
            TextureConfig[] allConfigs = new ConfigLoader <TextureConfig>(new[] { config.textureFolder }).AllConfigs();

            // Load all files in Textures folder
            Texture2D[] sourceTextures = Resources.LoadAll <Texture2D>(config.textureFolder);

            Dictionary <string, Texture2D> sourceTexturesLookup = new Dictionary <string, Texture2D>();

            foreach (var texture in sourceTextures)
            {
                sourceTexturesLookup.Add(texture.name, texture);
            }

            for (int i = 0; i < allConfigs.Length; i++)
            {
                var cfg = allConfigs[i];

                for (int n = 0; n < cfg.textures.Length; n++)
                {
                    cfg.textures[n].texture2d = Texture2DFromConfig(cfg.textures[n], sourceTexturesLookup);
                }

                if (cfg.type == TextureConfigType.Connected)
                {
                    // Create all 48 possibilities from the 5 supplied textures
                    Texture2D[]             newTextures       = ConnectedTextures.ConnectedTexturesFromBaseTextures(cfg.textures);
                    TextureConfig.Texture[] connectedTextures = new TextureConfig.Texture[48];

                    for (int x = 0; x < newTextures.Length; x++)
                    {
                        connectedTextures[x].index     = x;
                        connectedTextures[x].texture2d = newTextures[x];
                    }

                    cfg.textures = connectedTextures;
                }
            }

            return(allConfigs);
        }
Exemple #2
0
        public void AddTexture(Rect uvs, TextureConfig.Texture texture)
        {
            switch (m_textureType)
            {
            case TextureConfigType.Connected:
                m_uvs[texture.index] = uvs;
                break;

            default:
                if (texture.weight <= 0)
                {
                    texture.weight = 1;
                }
                // Add the texture multiple times to raise the chance it's selected randomly
                for (int i = 0; i < texture.weight; i++)
                {
                    m_uvs.Add(uvs);
                }
                break;
            }
        }
Exemple #3
0
        private Texture2D Texture2DFromConfig(TextureConfig.Texture texture, Dictionary <string, Texture2D> sourceTexturesLookup)
        {
            Texture2D file;

            if (!sourceTexturesLookup.TryGetValue(texture.file, out file))
            {
                Debug.LogError("Config referred to nonexistent file: " + texture.file);
                return(null);
            }

            //No width or height means this texture is the whole file
            if (texture.width == 0 && texture.height == 0)
            {
                return(file);
            }

            //If theres a width and a height fetch the pixels specified by the rect as a texture
            Texture2D newTexture = new Texture2D(texture.width, texture.height, config.textureFormat, file.mipmapCount < 1);

            newTexture.SetPixels(0, 0, texture.width, texture.height, file.GetPixels(texture.xPos, texture.yPos, texture.width, texture.height));
            return(newTexture);
        }