Noob question about AssetBundle (iOS)
Hello,
I'm a beginner in Unity dev for a iOS augmented reality app. Here's the context: the app has a dropdown menu to give users access to various levels based on scenes in the build.
Currently, I have serialized an asset with 2 arrays: 1 for all scenes names in the build (scenesName) and 1 for the ones enabled in the build (scenesEnabled). So I can add them as dropdown menu options if they're enabled.
It works fine inside Unity, I can populate the dropdown menu with the scenes checked in the build window. Of course, once on iOS, it needs to be in an assetbundle. So I used the "AssetBundles Browser" from Unity to create it.
On my iPhone, it seems I can access to the asset inside the bundle through my code, but I don't know how to load objects inside the asset to be able to use them. I mean the problem is "how to access object inside bundle, not use the object itself"
So, if someone would help me, it would be very nice !
Here's my code:
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using System.Text.RegularExpressions;
public class RetrieveBuiltScenes : MonoBehaviour
{
private string sceneName;
TMP_Dropdown DropDownHome;
// Name of my assetbundle
string nameOfAssetBundle = "buildscenesassetbundle";
// Name of my asset
string nameOfObjectToLoad = "ScenesList";
private void Start()
{
// Dropdown menu definition and Regex to keep only needed string from scenes name
DropDownHome = GetComponent<TMP_Dropdown>();
DropDownHome.ClearOptions();
Regex regex = new Regex(@"([^/]*/)*([\w\d\-]*)\.unity");
// Loading my assetbundle
var myLoadedAssetBundle = AssetBundle.LoadFromFileAsync(Application.dataPath +"/Raw/" + nameOfAssetBundle);
if (myLoadedAssetBundle.assetBundle == null)
{
Debug.Log("Failed to load AssetBundle!");
return;
}
else
{
// Loading my asset
var assetLoadRequest = myLoadedAssetBundle.assetBundle.LoadAssetAsync<ScenesList>(nameOfObjectToLoad);
Debug.Log("AssetLoadRequest : " + assetLoadRequest);
// I don't know what to do here !
myLoadedAssetBundle.assetBundle.Unload(false);
}}
Your answer
Follow this Question
Related Questions
AssetBundle.LoadFromFile cause Inflate Error: (file zip crc32 : 00000000) (result: fffffffb) 1 Answer
Loading contents of a folder as AssetBundle 1 Answer
How to upload with on demand resources in the app store connect? 0 Answers
Please Help !!!!!! Baked lightmaps does not work with asset bundle on Ios and Android builds 1 Answer
Loading content at runtime with HoloLens and IL2CPP 1 Answer