Я построил приложение для Android в Unity, которое содержит сцены, в моем приложении есть 3 сцены, одна из них в Apk Build, а другие 2 - адресаты (упакованные как .bundle), и я хранил их на SD -карте. В сцене, которая находится в сборке APK, есть 2 кнопки для загрузки этих упакованных сцен (хранящихся на SD -карте) с SD -карты во время выполнения, но когда я строю APK и установлен на устройстве и открываю ее, я нажимаю на одну из кнопков, затем сцены, хранящиеся/загруженные на SD -карту, не загружены. . < /p>
Я хочу получить доступ к SD -карте и файлам из нее во время выполнения в приложении и загрузить файлы внутри него в приложении. Я хочу прочитать сохраненные данные с SD Card. < /p>
Android версия: Android 7
api Уровень: 25 < /p>
code. разрешение < /p>
< /code>
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using UnityEngine.Android;
using System.Collections;
public class AddressablesSDCardLoader : MonoBehaviour
{
private string sdCardPath;
private string addressablesPath;
[Header("Addressable scene key (as defined in Addressables)")]
public string sceneToLoad; // this is editable in Inspector
void Start()
{
#if UNITY_ANDROID
if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
{
Permission.RequestUserPermission(Permission.ExternalStorageRead);
}
#endif
StartCoroutine(InitializeAddressablesFromSD());
}
IEnumerator InitializeAddressablesFromSD()
{
#if UNITY_ANDROID && !UNITY_EDITOR
yield return new WaitForSeconds(1f);
sdCardPath = ExternalStorageUtil.GetExternalSDCardPath();
if (string.IsNullOrEmpty(sdCardPath))
{
Debug.LogError("Failed to detect SD Card path.");
yield break;
}
addressablesPath = $"file://{sdCardPath}/YourGame/Addressables";
Addressables.InternalIdTransformFunc = (location) =>
{
string fileName = System.IO.Path.GetFileName(location.InternalId);
return $"{addressablesPath}/{fileName}";
};
#endif
yield return Addressables.InitializeAsync();
Debug.Log("Addressables initialized from SD card.");
}
public void LoadAssignedScene()
{
LoadScene(sceneToLoad); // Load scene from Inspector-assigned key
}
public void LoadScene(string sceneAddress)
{
Addressables.LoadSceneAsync(sceneAddress, LoadSceneMode.Single).Completed += OnSceneLoaded;
}
private void OnSceneLoaded(AsyncOperationHandle handle)
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log("Scene loaded successfully from SD card!");
}
else
{
Debug.LogError("Failed to load scene.");
}
}
}
< /code>
So, please if someone know about it can provide me the solution
Подробнее здесь: https://stackoverflow.com/questions/797 ... at-runtime