예제 #1
0
    public static Texture2D GetImageFromLocal(int id, string url, eImageType type)
    {
        Texture2D tex = null;

        byte[] fileData;

        string directory_path = Application.persistentDataPath + "/" + type.ToString();
        string file_name      = Path.GetFileName(url);
        string file_path      = directory_path + "/" + id.ToString() + "/" + file_name;

        if (Directory.Exists(directory_path + "/" + id.ToString()))
        {
            string[] contain_files = Directory.GetFiles(directory_path + "/" + id.ToString(), "*.png");

            for (int i = 0; i < contain_files.Length; i++)
            {
                if (Path.GetFileName(contain_files [i]) != file_name)
                {
                    File.Delete(contain_files [i]);
                }
            }
        }

        if (File.Exists(file_path))
        {
            fileData = File.ReadAllBytes(file_path);
            tex      = new Texture2D(1, 1);
            tex.LoadImage(fileData);             //..this will auto-resize the texture dimensions.
        }
        return(tex);
    }
예제 #2
0
    public static void SaveImageToLocal(int id, string url, Texture2D texture, eImageType type)
    {
        string directory_path = Application.persistentDataPath;

        directory_path = directory_path + "/" + type.ToString();

        if (Directory.Exists(directory_path) == false)
        {
            Directory.CreateDirectory(directory_path);
        }

        string file_name = Path.GetFileName(url);

        //DELETE OLD FORMAT
        string _temp_old_file = directory_path + "/" + id.ToString() + ".png";

        if (File.Exists(_temp_old_file))
        {
            File.Delete(_temp_old_file);
        }

        string new_directory = directory_path + "/" + id.ToString();
        string file_path     = new_directory + "/" + file_name;

        if (Directory.Exists(new_directory) == false)
        {
            Directory.CreateDirectory(new_directory);
        }
        else
        {
            string[] contain_files = Directory.GetFiles(new_directory, "*.png");

            for (int i = 0; i < contain_files.Length; i++)
            {
                if (contain_files[i] != file_name)
                {
                    File.Delete(contain_files [i]);
                }
            }
        }

        if (File.Exists(file_path) == false)
        {
            File.WriteAllBytes(file_path, texture.EncodeToPNG());
            Q.Utils.QDebug.Log(file_path);
        }
    }