Problems and solutions when using unity obb (EasyAR 3.0.1)
1. AR target is not recognized.
2. Obb won't load in android marshmallow version.
solution.
1. When splitting to obb, we need to load the target image onto the mobile device.
unity First Scene Add
private IEnumerator ExtractState()
{
string[] filesInOBB = {
"image.jpg", "image2.png", // your Image targets
};
foreach (var filename in filesInOBB)
{
string uri = Application.streamingAssetsPath + "/Foldername/" + filename;
string outputFilePath = Application.persistentDataPath + "/Foldername/" + filename;
if (!Directory.Exists(Path.GetDirectoryName(outputFilePath)))
Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
UnityWebRequest request = UnityWebRequest.Get(uri);
yield return request.SendWebRequest();
Save(request, outputFilePath);
yield return new WaitForEndOfFrame();
}
}
private void Save(UnityWebRequest request, string outputPath)
{
FileStream fs = new FileStream(outputPath, System.IO.FileMode.Create);
fs.Write(request.downloadHandler.data, 0, (int)request.downloadedBytes);
fs.Close();
// Verify that the File has been actually stored
if (File.Exists(outputPath))
{
Debug.Log("File successfully saved at: " + outputPath);
}
else
{
Debug.Log("Failure!! - File does not exist at: " + outputPath);
}
}
2. For marshmallows, unity runtime permission is required.
No matter how applied to the Androidmanifast.xml file, the obb will not load.
- Unity 2017.4
https://assetstore.unity.com/packages/tools/integration/android-runtime-permissions-117803
Take this and load the permissions. An example of the above assets is on Git Hub.
https://github.com/yasirkula/UnityAndroidRuntimePermissions
But that's not the end here.
The obb is loaded but the AR target is not recognized with an invalid key in Easyar.
Just turn off the app and start again.
That part should be corrected by EasyAR.
For now, I did an App Restart in Unity.
If it doesn't work, it will restart infinitely, so you must script it only once.
ex)
IEnumerator PermissionState()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidRuntimePermissions.Permission[] result = AndroidRuntimePermissions.RequestPermissions("android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE");
while (true)
{
if (result[0] == AndroidRuntimePermissions.Permission.Granted &&
result[1] == AndroidRuntimePermissions.Permission.Granted)
{
break;
}
yield return null;
}
#endif
yield return null;
}
- Unity 2018.3
Unity provides RunTime permissions.
IEnumerator PermissionState()
{
#if PLATFORM_ANDROID
Permission.RequestUserPermission(Permission.ExternalStorageWrite);
Permission.RequestUserPermission(Permission.ExternalStorageRead);
yield return null;
while (true)
{
if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead) &&
Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
{
break;
}
yield return null;
}
#endif
yield return null;
}