WriteTo() static private method

static private WriteTo ( Texture2D cacheTexture, string cacheFile, bool compress ) : bool
cacheTexture UnityEngine.Texture2D
cacheFile string
compress bool
return bool
        private static TextureInfoWrapper RebuildCache(TexInfo Texture, bool compress, bool mipmaps)
        {
            Texture.loadOriginalFirst = true;
            ActiveTextureManagement.DBGLog("Loading texture...");
            TextureConverter.GetReadable(Texture, mipmaps);
            ActiveTextureManagement.DBGLog("Texture loaded.");

            TextureInfoWrapper cacheTexture = Texture.texture;
            Texture2D          tex          = cacheTexture.texture;

            String textureName = cacheTexture.name;
            String cacheFile   = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName;

            ActiveTextureManagement.DBGLog("Rebuilding Cache... " + Texture.name);

            ActiveTextureManagement.DBGLog("Saving cache file " + cacheFile + ".imgcache");
            tex.Apply(mipmaps);
            Color32[] colors   = tex.GetPixels32();
            bool      hasAlpha = TextureConverter.WriteTo(tex, cacheFile + ".imgcache", compress);

            String originalTextureFile = Texture.filename;
            String cacheConfigFile     = cacheFile + ".tcache";

            ActiveTextureManagement.DBGLog("Created Config for" + originalTextureFile);

            String hashString = GetMD5String(originalTextureFile);

            ConfigNode config = new ConfigNode();

            config.AddValue("md5", hashString); ActiveTextureManagement.DBGLog("md5: " + hashString);
            config.AddValue("orig_format", Path.GetExtension(originalTextureFile)); ActiveTextureManagement.DBGLog("orig_format: " + Path.GetExtension(originalTextureFile));
            config.AddValue("orig_width", Texture.width.ToString()); ActiveTextureManagement.DBGLog("orig_width: " + Texture.width.ToString());
            config.AddValue("orig_height", Texture.height.ToString()); ActiveTextureManagement.DBGLog("orig_height: " + Texture.height.ToString());
            config.AddValue("is_normal", cacheTexture.isNormalMap.ToString()); ActiveTextureManagement.DBGLog("is_normal: " + cacheTexture.isNormalMap.ToString());
            config.AddValue("is_compressed", compress); ActiveTextureManagement.DBGLog("is_compressed: " + compress);
            config.AddValue("width", Texture.resizeWidth.ToString()); ActiveTextureManagement.DBGLog("width: " + Texture.resizeWidth.ToString());
            config.AddValue("height", Texture.resizeHeight.ToString()); ActiveTextureManagement.DBGLog("height: " + Texture.resizeHeight.ToString());
            config.AddValue("hasAlpha", hasAlpha); ActiveTextureManagement.DBGLog("hasAlpha: " + hasAlpha.ToString());
            config.AddValue("hasMipmaps", mipmaps); ActiveTextureManagement.DBGLog("hasMipmaps: " + hasAlpha.ToString());
            config.Save(cacheConfigFile);
            ActiveTextureManagement.DBGLog("Saved Config.");

            if (compress)
            {
                tex.Compress(true);
            }
            cacheTexture.isCompressed = compress;
            tex.Apply(false, Texture.makeNotReadable);

            cacheTexture.isReadable = !Texture.makeNotReadable;

            return(cacheTexture);
        }
Esempio n. 2
0
        private static GameDatabase.TextureInfo RebuildCache(TexInfo Texture, bool compress, bool mipmaps, bool makeNotReadable)
        {
            Texture.loadOriginalFirst = true;
            ActiveTextureManagement.DBGLog("Loading texture...");
            TextureConverter.GetReadable(Texture, mipmaps);
            ActiveTextureManagement.DBGLog("Texture loaded.");

            GameDatabase.TextureInfo cacheTexture = Texture.texture;
            Texture2D tex = cacheTexture.texture;

            String textureName = cacheTexture.name;
            String cacheFile   = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName;

            if (Texture.needsResize)
            {
                ActiveTextureManagement.DBGLog("Rebuilding Cache... " + Texture.name);

                ActiveTextureManagement.DBGLog("Saving cache file " + cacheFile + ".pngcache");
                TextureConverter.WriteTo(cacheTexture.texture, cacheFile + ".pngcache");

                String originalTextureFile = Texture.filename;
                String cacheConfigFile     = cacheFile + ".tcache";
                ActiveTextureManagement.DBGLog("Created Config for" + originalTextureFile);

                String hashString = GetMD5String(originalTextureFile);

                ConfigNode config = new ConfigNode();
                config.AddValue("md5", hashString); ActiveTextureManagement.DBGLog("md5: " + hashString);
                config.AddValue("orig_format", Path.GetExtension(originalTextureFile)); ActiveTextureManagement.DBGLog("orig_format: " + Path.GetExtension(originalTextureFile));
                config.AddValue("orig_width", Texture.width.ToString()); ActiveTextureManagement.DBGLog("orig_width: " + Texture.width.ToString());
                config.AddValue("orig_height", Texture.height.ToString()); ActiveTextureManagement.DBGLog("orig_height: " + Texture.height.ToString());
                config.AddValue("is_normal", cacheTexture.isNormalMap.ToString()); ActiveTextureManagement.DBGLog("is_normal: " + cacheTexture.isNormalMap.ToString());
                config.AddValue("width", Texture.resizeWidth.ToString()); ActiveTextureManagement.DBGLog("width: " + Texture.resizeWidth.ToString());
                config.AddValue("height", Texture.resizeHeight.ToString()); ActiveTextureManagement.DBGLog("height: " + Texture.resizeHeight.ToString());

                config.Save(cacheConfigFile);
                ActiveTextureManagement.DBGLog("Saved Config.");
            }
            else
            {
                String directory = Path.GetDirectoryName(cacheFile + ".none");
                if (File.Exists(directory))
                {
                    File.Delete(directory);
                }
                Directory.CreateDirectory(directory);
            }

            if (compress)
            {
                tex.Compress(true);
            }
            cacheTexture.isCompressed = compress;
            if (!makeNotReadable)
            {
                tex.Apply(mipmaps);
            }
            else
            {
                tex.Apply(mipmaps, true);
            }
            cacheTexture.isReadable = !makeNotReadable;

            return(cacheTexture);
        }