Example #1
0
        public static void Add(string ID, Texture2D texture, string directory = "", SAVE_TYPES saveType = SAVE_TYPES.PNG)
        {
            if (!texture)
            {
                return;
            }
            byte[] bytes = texture.EncodeToPNG();

            ID        = TextureVault.GenerateIdentifier(ID);
            directory = TextureVault.GetDirectory(directory);
            string fileName = TextureVault.GetFilename(directory, ID);

            if (File.Exists(fileName))
            {
                //Debug.LogFormat("[{0}] {1}", "TextureVault", "File exists in vault, halting " + fileName);
                return;
            }

            if (!TextureVault.DirectoryExists(directory))
            {
                //Debug.LogFormat("[{0}] {1} {2}", "TextureVault", "Directory does not exists create", directory);
                Directory.CreateDirectory(directory);
            }

            //Debug.LogFormat("[{0}] {1} {2} {3}", "TextureVault", "Saving to vault", fileName, texture);
            File.WriteAllBytes(fileName, bytes);
        }
Example #2
0
        public static void LoadTextureItem(string ID, SuccessHandler onSuccess, ErrorHandler onError, string directory = "")
        {
            if (TextureVault.Get(ID, directory))
            {
                ID        = TextureVault.GenerateIdentifier(ID);
                directory = TextureVault.GetDirectory(directory);

                string fileName = TextureVault.GetFilename(directory, ID);


                if (textureCache.ContainsKey(fileName))
                {
                    Touch(fileName);
                    Debug.Log("From Cache " + fileName + " " + textureCache.Count);
                    onSuccess(textureCache[fileName].texture);
                    return;
                }

                byte[] data = File.ReadAllBytes(fileName);

                Texture2D texture2D = new Texture2D(2, 2);
                if (texture2D.LoadImage(data, true))
                {
                    textureCache.Add(fileName, new TextureVaultHistory(fileName, texture2D));
                    CleanupCache();
                    onSuccess(texture2D);
                    return;
                }
            }
            onError();
        }
Example #3
0
        public static bool Get(string ID, string directory = "")
        {
            ID        = TextureVault.GenerateIdentifier(ID);
            directory = TextureVault.GetDirectory(directory);

            string fileName = TextureVault.GetFilename(directory, ID);

            if (textureCache.ContainsKey(fileName))
            {
                return(true);
            }

            if (TextureVault.DirectoryExists(directory))
            {
                return(File.Exists(fileName));
            }
            return(false);
        }