Forum Discussion
erfan.khakpour
4 years agoExplorer
How create one app in unity and multiple scenes inside
Our application is for VR oculus in the field of medical education
We want to create a main application and add different medical scenarios to it
We have 2 scenarios at the moment and these scenarios will increase in the future,
Now we want to load the scenarios dynamically in the server and display them in the main application and the user can enter the game by clicking on each scenario I searched the internet and the asset bundle could be a good option to implement this method, but the code does not load in the asset bundle Can you suggest a better solution?
2 Replies
Replies have been turned off for this discussion
- foxvalleysoccerProtege
Share your code to load asset bundle and the link to where you got those directions please.
- erfan.khakpourExplorer
I used these tutorials:
AssetBundleSceneLoader:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; using System; using UnityEngine.SceneManagement; public static class ButtonExtension { public static void AddEventListener <T>(this Button button,T param, Action<T> OnClick) { button.onClick.AddListener(delegate { OnClick(param); }); } } public class AssetBundleSceneLoader : MonoBehaviour { public string[] urls; [Header("UI Stuff")] public Transform rootContainer; public Button prefab; public Text labelText; static List<AssetBundle> assetBundles = new List<AssetBundle>(); static List<string> sceneNames = new List<string>(); // Start is called before the first frame update IEnumerator Start() { if(assetBundles.Count == 0) { int i = 0; while(i < urls.Length) { using (WWW web = new WWW(urls[i])) { yield return web; if (!string.IsNullOrEmpty(web.error)) { Debug.LogError(web.error); yield break; } assetBundles.Add(web.assetBundle); sceneNames.AddRange(web.assetBundle.GetAllScenePaths()); } i++; } } foreach (string sceneName in sceneNames) { labelText.text = Path.GetFileNameWithoutExtension(sceneName); var clone = Instantiate(prefab.gameObject) as GameObject; clone.GetComponent<Button>().AddEventListener(sceneName, LoadAssetBundleScene); clone.SetActive(true); clone.transform.SetParent(rootContainer); } } public void LoadAssetBundleScene(string sceneName) { SceneManager.LoadScene(sceneName); } }CreateAssetBundle:
using UnityEngine; using UnityEditor; using System.IO; public class CreateAssetBundles { [MenuItem("Assets/Build AssetBundles")] static void BuildAllAssetBundles() { string assetBundleDirectory = "Assets/StreamingAssets"; if (!Directory.Exists(Application.streamingAssetsPath)) { Directory.CreateDirectory(assetBundleDirectory); } BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); } }I output two scenes as an assetbundle for testing:
In one of the scenes, I assigned a script to an object,
But I get mising script error
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 1 year ago
- 2 years ago
- 7 months ago