//Save the text of the displayed information in a file. //(*)To write to External Storage on Android, you need permission in the 'AndroidManifest.xml' file. // //表示されている情報のテキストをファイルに保存する。 //※Android で External Storage に書き込みをするには、「AndroidManifest.xml」にパーミッションが必要。 //Required : <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> public void SaveInfoText() { #if UNITY_EDITOR Debug.Log("SaveInfoText called"); #elif UNITY_ANDROID if (AndroidPlugin.IsExternalStorageMountedReadWrite()) { if (displayText != null && !string.IsNullOrEmpty(displayText.text)) { string path = AndroidPlugin.GetExternalStorageDirectoryDocuments(); //API 19 or higher if (string.IsNullOrEmpty(path)) { path = AndroidPlugin.GetExternalStorageDirectory(); } string file = path + "/info_" + DateTime.Now.ToString("yyMMdd_HHmmss") + ".txt"; if (SaveText(displayText.text, file)) { XDebug.Log("Save to : " + file); if (OnToast != null) { OnToast.Invoke(saveSuccessMessage); } if (OnMediaScan != null) { OnMediaScan.Invoke(file); } } } } #endif }
// Update is called once per frame //private void Update () { //} //Get the storage information //ストレージの情報を取得する public void GetInfo() { XDebug.Clear(); //XDebug.Log("Application.dataPath = " + Application.dataPath); //ゲームデータのフォルダーパスを返します(読み取り専用) XDebug.Log("Application.persistentDataPath = " + Application.persistentDataPath); //永続的なデータディレクトリのパスを返します(読み取り専用) //XDebug.Log("Application.streamingAssetsPath = " + Application.streamingAssetsPath); //StreamingAssets フォルダーへのパスが含まれています(読み取り専用) //XDebug.Log("Application.temporaryCachePath = " + Application.temporaryCachePath); //一時的なデータ、キャッシュのディレクトリパスを返します(読み取り専用)値はデータを保存できる一時的なディレクトリパスです。 #if !UNITY_EDITOR && UNITY_ANDROID XDebug.Log("----------------------------"); XDebug.Log("IsExternalStorageEmulated = " + AndroidPlugin.IsExternalStorageEmulated()); XDebug.Log("IsExternalStorageRemovable = " + AndroidPlugin.IsExternalStorageRemovable()); XDebug.Log("IsExternalStorageMounted = " + AndroidPlugin.IsExternalStorageMounted()); XDebug.Log("IsExternalStorageMountedReadOnly = " + AndroidPlugin.IsExternalStorageMountedReadOnly()); XDebug.Log("IsExternalStorageMountedReadWrite = " + AndroidPlugin.IsExternalStorageMountedReadWrite()); XDebug.Log("GetExternalStorageState = " + AndroidPlugin.GetExternalStorageState()); XDebug.Log("GetExternalStorageDirectory = " + AndroidPlugin.GetExternalStorageDirectory()); XDebug.Log("GetExternalStorageDirectoryAlarms = " + AndroidPlugin.GetExternalStorageDirectoryAlarms()); XDebug.Log("GetExternalStorageDirectoryDCIM = " + AndroidPlugin.GetExternalStorageDirectoryDCIM()); XDebug.Log("GetExternalStorageDirectoryDocuments = " + AndroidPlugin.GetExternalStorageDirectoryDocuments()); XDebug.Log("GetExternalStorageDirectoryDownloads = " + AndroidPlugin.GetExternalStorageDirectoryDownloads()); XDebug.Log("GetExternalStorageDirectoryMovies = " + AndroidPlugin.GetExternalStorageDirectoryMovies()); XDebug.Log("GetExternalStorageDirectoryMusic = " + AndroidPlugin.GetExternalStorageDirectoryMusic()); XDebug.Log("GetExternalStorageDirectoryNotifications = " + AndroidPlugin.GetExternalStorageDirectoryNotifications()); XDebug.Log("GetExternalStorageDirectoryPictures = " + AndroidPlugin.GetExternalStorageDirectoryPictures()); XDebug.Log("GetExternalStorageDirectoryPodcasts = " + AndroidPlugin.GetExternalStorageDirectoryPodcasts()); XDebug.Log("GetExternalStorageDirectoryRingtones = " + AndroidPlugin.GetExternalStorageDirectoryRingtones()); #endif }
bool isSaving = false; //Ignore while saving. //Run screenshot public void ScreenShot() { if (isSaving) { return; //Ignore while saving. } string fileName = filePrefix + DateTime.Now.ToString("yyMMdd_HHmmss") + ".png"; string dir = Application.persistentDataPath; #if UNITY_EDITOR dir = Application.dataPath + "/.."; #elif UNITY_ANDROID if (!AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE")) { XDebug.Log("'WRITE_EXTERNAL_STORAGE' permission denied."); return; } dir = AndroidPlugin.GetExternalStorageDirectoryPictures(); if (string.IsNullOrEmpty(dir)) { dir = AndroidPlugin.GetExternalStorageDirectory(); } #endif string path = dir + "/" + fileName; StartCoroutine(StartScreenshot(path)); }
// Update is called once per frame //private void Update() //{ //} //Run screenshot with automatic path public void StartScreenshot() { string fileName = filePrefix + DateTime.Now.ToString("yyMMdd_HHmmss") + ".png"; string dir = Application.persistentDataPath; //I think that you may add processing for each platform here. #if UNITY_EDITOR dir = Application.dataPath + "/.."; #elif UNITY_ANDROID if (toExternalStorageOnAndroid) { if (!AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE")) { if (OnError != null) { OnError.Invoke("'WRITE_EXTERNAL_STORAGE' permission denied."); } return; } dir = AndroidPlugin.GetExternalStorageDirectoryPictures(); if (string.IsNullOrEmpty(dir)) { dir = AndroidPlugin.GetExternalStorageDirectory(); } } #endif string path = dir + "/" + fileName; StartScreenshot(path); }
bool isSaving = false; //Ignore while saving. //Run screenshot public void ScreenShot() { if (isSaving) { return; //Ignore while saving. } string fileName = filePrefix + DateTime.Now.ToString("yyMMdd_HHmmss") + ".png"; string dir = Application.persistentDataPath; #if UNITY_EDITOR dir = Application.dataPath + "/.."; #elif UNITY_ANDROID dir = AndroidPlugin.GetExternalStorageDirectoryPictures(); if (string.IsNullOrEmpty(dir)) { dir = AndroidPlugin.GetExternalStorageDirectory(); } #endif string path = dir + "/" + fileName; StartCoroutine(StartScreenshot(path)); }