Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static string GetDataFilePath()
- {
- #if UNITY_ANDROID && !UNITY_EDITOR
- try
- {
- System.IntPtr contextWrapper = AndroidJNI.FindClass("android/content/ContextWrapper");
- System.IntPtr contextWrapperGetFilesDir = AndroidJNIHelper.GetMethodID(contextWrapper, "getFilesDir", "()Ljava/io/File;");
- using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- using (AndroidJavaObject unityPlayerCurrentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
- {
- System.IntPtr unityPlayerCurrentActivityRawObject = unityPlayerCurrentActivity.GetRawObject();
- System.IntPtr filesDir = AndroidJNI.CallObjectMethod(unityPlayerCurrentActivityRawObject, contextWrapperGetFilesDir, new jvalue[0]);
- System.IntPtr file = AndroidJNI.FindClass("java/io/File");
- System.IntPtr fileGetAbsolutePath = AndroidJNIHelper.GetMethodID(file, "getAbsolutePath", "()Ljava/lang/String;");
- string absolutePath = AndroidJNI.CallStringMethod(filesDir, fileGetAbsolutePath, new jvalue[0]);
- return absolutePath;
- }
- }
- }
- catch (System.Exception e)
- {
- Debug.Log(e.ToString());
- return Application.persistentDataPath;
- }
- #else
- return Application.persistentDataPath;
- #endif
- }
- public GetPath GetPathScript;
- string Path = $"{GetPathScript.GetDataFilePath()}/{fileName}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement