Ejemplo n.º 1
0
    private void DetermineRootPath()
    {
        //No more Application.persistentDataPath as it will never return the SD card.

        #if UNITY_ANDROID && !UNITY_EDITOR
        m_RootPath        = DataPathPlugin.GetFirstWriteableExternalDataPath();
        m_RootPicturePath = DataPathPlugin.GetExternalStoragePublicDirectory();
        //int numberOfStorageDevices = DataPathPlugin.GetExternalDataPathCount();

        ////Backwards as we prefer an external SD card!
        //for (int i = (numberOfStorageDevices - 1); i >= 0; --i)
        //{
        //    if (DataPathPlugin.CanReadExternalDataPath(i) && DataPathPlugin.CanWriteExternalDataPath(i))
        //    {
        //        m_RootPath = DataPathPlugin.GetExternalDataPath(i);
        //        break;
        //    }
        //}
        #endif

        m_RootDirectory        = new DirectoryInfo(m_RootPath);
        m_RootPictureDirectory = new DirectoryInfo(m_RootPicturePath);

        Debug.Log("Registered root path: " + m_RootPath);
        Debug.Log("Registered picture root path: " + m_RootPicturePath);
    }
Ejemplo n.º 2
0
    //Picture Serialization
    public bool SerializePicture(Picture picture)
    {
        if (picture == null)
        {
            return(false);
        }

        DirectoryInfo pictureDirectory = m_RootPictureDirectory;

        if (m_PictureFolder != "")
        {
            pictureDirectory = FindOrCreateDirectory(m_RootPictureDirectory, m_PictureFolder);
        }

        byte[] bytes = picture.Texture.EncodeToPNG();

        string fileName = string.Format(m_PictureFileName, GameClock.Instance.GetDateTime().ToString("dd-MM-yyyy_HH-mm-ss"));

        fileName = FindUniqueFileName(pictureDirectory, fileName);

        string path = pictureDirectory.FullName + Path.DirectorySeparatorChar + fileName;

        File.WriteAllBytes(path, bytes);

        picture.TextureFilePath = path;

        Debug.Log("Picture succesfully saved!");

        #if UNITY_ANDROID && !UNITY_EDITOR
        DataPathPlugin.RunMediaScanner(path);
        #endif

        return(true);
    }
Ejemplo n.º 3
0
    private void Awake()
    {
        string rootPath = DataPathPlugin.DetermineRootPath();

        if (rootPath != "")
        {
            m_RootPath = rootPath;
        }

        Debug.Log("Registered root path: " + m_RootPath);
    }
Ejemplo n.º 4
0
    public bool DeleteFile(string path)
    {
        try
        {
            File.Delete(path);

            #if UNITY_ANDROID && !UNITY_EDITOR
            DataPathPlugin.RunMediaScanner(path);
            #endif

            return(true);
        }
        catch (Exception e)
        {
            Debug.LogWarning(e.Message);
            return(false);
        }
    }
Ejemplo n.º 5
0
    //Utility
    public static string DetermineRootPath()
    {
        //No more Application.persistentDataPath as it will never return the SD card.

        #if UNITY_ANDROID && !UNITY_EDITOR
        int numberOfStorageDevices = DataPathPlugin.GetExternalDataPathCount();

        //Backwards as we prefer an external SD card!
        for (int i = (numberOfStorageDevices - 1); i >= 0; --i)
        {
            if (DataPathPlugin.CanReadExternalDataPath(i) && DataPathPlugin.CanWriteExternalDataPath(i))
            {
                return(DataPathPlugin.GetExternalDataPath(i));
            }
        }
        #endif

        return("");
    }