Search Unity

Question How do you load an AssetBundle scene with Meta Quest2?

Discussion in 'Asset Bundles' started by dauedragon3, Jan 30, 2023.

  1. dauedragon3

    dauedragon3

    Joined:
    Oct 2, 2021
    Posts:
    2
    【What I want to do】
    I want to load an AssetBundle scene and see it with Meta Quest2. On Unity Editor, I could do that and I see gameobjects in the AssetBundle scene. However, I don't see anything after loading with Meta Quest2.

    【Development Environment】
    Unity Version 2021.3.5f1
    Loading the AssetBundle from Web server(X-server)
    The AssetBundle Scene includes just a cube and a texture.
     
  2. dauedragon3

    dauedragon3

    Joined:
    Oct 2, 2021
    Posts:
    2
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using UnityEngine;
    4. using System.IO;
    5. using UnityEngine.SceneManagement;
    6. using UnityEngine.UI;
    7.  
    8. public class LoadAssetBundleSceneSample : MonoBehaviour
    9. {
    10.     public static LoadAssetBundleSceneSample pgs;
    11.     public string[] url, sceneNames;
    12.     static AssetBundle assetBundle;
    13.     WWW www;
    14.     [NonSerialized] Text percent, percent2;
    15.     [NonSerialized] Image fg, fg2;
    16.     [SerializeField] int _sceneNum;
    17.  
    18.     bool loadingStart = false;
    19.  
    20.     private void Awake()
    21.     {
    22.         if (pgs == null)
    23.         {
    24.             pgs = this;
    25.         }
    26.     }
    27.  
    28.     void Start()
    29.     {
    30.         playGamePressed(_sceneNum);
    31.     }
    32.  
    33.     void Update()
    34.     {
    35.         if (loadingStart)
    36.         {
    37.             double v = www.progress;
    38.  
    39.             v = System.Math.Round(v, 2);
    40.  
    41.             v *= 100;
    42.         }
    43.     }
    44.  
    45.     public void playGamePressed(int i)
    46.     {
    47.         StartCoroutine(s(i));
    48.     }
    49.  
    50.     IEnumerator s(int i)
    51.     {
    52.         if (!assetBundle)
    53.         {
    54.             using (www = new WWW(url[i]))
    55.             {
    56.                 loadingStart = true;
    57.                 yield return www;
    58.                 if (!string.IsNullOrEmpty(www.error))
    59.                 {
    60.                     print(www.error);
    61.                     yield break;
    62.                 }
    63.  
    64.                 assetBundle = www.assetBundle;
    65.             }
    66.         }
    67.  
    68.         loadingStart = false;
    69.         string[] scenes = assetBundle.GetAllScenePaths();
    70.  
    71.         foreach (string s in scenes)
    72.         {
    73.             loadScene(Path.GetFileNameWithoutExtension(s));
    74.             if (Path.GetFileNameWithoutExtension(s) == sceneNames[i])
    75.             {
    76.                 loadScene(Path.GetFileNameWithoutExtension(s));
    77.             }
    78.         }
    79.     }
    80.  
    81.     public void loadScene(string name)
    82.     {
    83.         SceneManager.LoadScene(name);
    84.     }
    85.