Unity. Android. Save files disappears after updating an App

后端 未结 2 638
礼貌的吻别
礼貌的吻别 2021-01-20 01:57

I\'m creating pretty simple game in Unity, and want to save results, time, etc. I use System.IO for it, and everything works fine, but when i update my app from \'.apk\' all

2条回答
  •  生来不讨喜
    2021-01-20 02:43

    Samsung and many other Android devices use a serial number as the mount point for external sdcards. Building on @Kardux's (original) answer for internal storage, the following will favor external storage (without a specific directory), then search for the internal sdcard as a fallback.

    public static string GetAndroidInternalFilesDir()
    {
        string[] potentialDirectories = new string[]
        {
            "/storage",
            "/sdcard",
            "/storage/emulated/0",
            "/mnt/sdcard",
            "/storage/sdcard0",
            "/storage/sdcard1"
        };
    
        if(Application.platform == RuntimePlatform.Android)
        {
            for(int i = 0; i < potentialDirectories.Length; i++)
            {
                if(Directory.Exists(potentialDirectories[i]))
                {
                    return potentialDirectories[i];
                }
            }
        }
        return "";
    }
    

    Note: This assumes the external storage directory appears first in a directory list. It then prioritizes the attempts to access storage by likelihood of success and adds /storage/emulated/0, which many devices can access when unable to access /sdcard.

提交回复
热议问题