private void UnpackScene(AssetBundle bundle) { if (bundle.isStreamedSceneAssetBundle) { _unpackedScene = System.IO.Path.GetFileNameWithoutExtension(bundle.GetAllScenePaths()[0]); Debug.Log(System.IO.Path.GetFileNameWithoutExtension(bundle.GetAllScenePaths()[0])); } }
IEnumerator AssetBundleTest() { using (WWW www = new WWW("http://127.0.0.1:8000/levels.1_10")) { yield return(www); AssetBundle assetBundle = www.assetBundle; Debug.LogError(assetBundle.Contains("Assets/Scenes/Level_1.unity")); Debug.LogError(assetBundle.GetAllScenePaths()[0]); assetBundle.LoadAllAssets(); Application.LoadLevel(assetBundle.GetAllScenePaths()[0]); //Instantiate(gameObject); assetBundle.Unload(false); } }
private void LoadPlatformMainfest(string rootBundlePath, string folerPath, EnciphererKey keyAsset) { //从内存中加载&解密 byte[] datas = Encipherer.AESDecrypt(File.ReadAllBytes(rootBundlePath), keyAsset); AssetBundle mainfestAssetBundle = AssetBundle.LoadFromMemory(datas); _mainfest = mainfestAssetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); // string[] assetBundleNames = _mainfest.GetAllAssetBundles(); foreach (var item in assetBundleNames) { datas = Encipherer.AESDecrypt(File.ReadAllBytes(folerPath + "/" + item), keyAsset); AssetBundle assetBundle = AssetBundle.LoadFromMemory(datas); string[] assetNames = assetBundle.GetAllAssetNames(); if (assetBundle.isStreamedSceneAssetBundle) { assetNames = assetBundle.GetAllScenePaths(); } foreach (var name in assetNames) { if (!_allAssets.ContainsKey(name)) { _allAssets.Add(name, assetBundle); } } } mainfestAssetBundle.Unload(false); }
//TODO: This is all test garbage. Don't use this. IEnumerator AssetBundleRequest(string url) { using (UnityWebRequest uwr = UnityWebRequest.GetAssetBundle(url)) { yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log($"Failed to download bundle. Error: {uwr.error}"); } else { // Get downloaded asset bundle AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); string[] paths = bundle.GetAllScenePaths(); foreach (string p in paths) { Debug.Log($"Found Scene in Bundle: {p}"); } Debug.Log("Loading first found scene."); SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(paths.First())).allowSceneActivation = true; } } }
IEnumerator LoadGameSceneAsync(AssetBundle assetBundle, bool isAdditive = false) { scenePaths = assetBundle.GetAllScenePaths(); async = SceneManager.LoadSceneAsync(scenePaths[0], isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); async.allowSceneActivation = false; yield return(async); }
private static AsyncOperation GetAsyncOperation(AssetBundle assetBundle, ref string sceneName, LoadSceneMode loadMode) { if (assetBundle.isStreamedSceneAssetBundle) { if (string.IsNullOrEmpty(sceneName)) { var scenePaths = assetBundle.GetAllScenePaths(); if (scenePaths != null && scenePaths.Length > 0 && !string.IsNullOrEmpty(scenePaths[0])) { sceneName = Path.GetFileNameWithoutExtension(scenePaths[0]); } } if (string.IsNullOrEmpty(sceneName)) { throw new AssetLoadException("The asset bundle does not contain scenes.", null, typeof(Scene)); } else { return(SceneManager.LoadSceneAsync(sceneName, loadMode)); } } else { throw new AssetLoadException("The asset bundle does not contain scenes.", null, typeof(Scene)); } }
private void HandleAssetBundle(RPCSerializer rpcData) { int index = (int)rpcData.args[0]; if (index == -1) { sceneBundle = AssetBundle.LoadFromMemory(data); sceneBundle.LoadAllAssets(); string[] scenes = sceneBundle.GetAllScenePaths(); string mySceneName = scenes[0]; mySceneName = mySceneName.Substring(0, mySceneName.Length - 6); //remove .unity mySceneName = mySceneName.Substring(mySceneName.LastIndexOf("/") + 1); //remove path SceneManager.LoadScene(mySceneName); } else if (index == 0) { data = new byte[(int)rpcData.args[1]]; if (sceneBundle != null) { SceneManager.LoadScene(1); sceneBundle.Unload(true); } } else { int start = (int)rpcData.args [1]; byte[] bData = (byte[] )rpcData.args [2]; for (int i = 0; i < bData.Length; i++) { data [i + start] = bData [i]; } } }
// Use this for initialization void Start() { timerIsActive = true; timerText = GetComponent <Text>(); myLoadedAssetBundle = AssetBundle.LoadFromFile("Assets/AssetBundles/scenes"); scenePaths = myLoadedAssetBundle.GetAllScenePaths(); }
IEnumerator GetAssetBundle() { UnityWebRequest www = UnityWebRequest.GetAssetBundle("https://s3-us-west-2.amazonaws.com/vrithm-scenes/problem2"); www.Send(); Debug.Log("Done"); while (!www.isDone) { Debug.Log("Inside waiting loop, updating progress"); Debug.Log(www.downloadProgress); Debug.Log(www.isDone); yield return(new WaitForEndOfFrame()); } if (www.isNetworkError) { Debug.Log(www.error); } else { Debug.Log("Success"); AssetBundle bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle; string[] scenePath = bundle.GetAllScenePaths(); Debug.Log(scenePath[0]); // -> "Assets/scene.unity" Application.LoadLevel(scenePath[0]); } }
public static void Load(string sdkSceneName) { try { // This bundle contains assets that the scenes in 'skillz-scenes' depend on, // so this must be loaded first for the all the dependencies to be available. if (ancillaryAssetBundle == null) { ancillaryAssetBundle = AssetBundle.LoadFromFile(Path.Combine("Assets", "Skillz", "Internal", "AssetBundles", "skillz-assets")); } if (scenesAssetBundle == null) { scenesAssetBundle = AssetBundle.LoadFromFile(Path.Combine("Assets", "Skillz", "Internal", "AssetBundles", "skillz-scenes")); } var sdkScenePath = scenesAssetBundle.GetAllScenePaths().FirstOrDefault(scenePath => string.Equals(Path.GetFileNameWithoutExtension(scenePath), sdkSceneName, StringComparison.InvariantCulture)); if (string.IsNullOrEmpty(sdkScenePath)) { Debug.LogWarning(string.Format(LogFormat, sdkSceneName)); } SceneManager.LoadScene(sdkScenePath); } catch (Exception e) { Debug.LogErrorFormat(string.Format(LogFormat, e)); } }
// Start is called before the first frame update void Start() { AssetBundle fighterBundle = AssetBundle.LoadFromFile($"Assets/AssetBundles/{bundleToLoad}"); string[] fighterScenes = fighterBundle.GetAllScenePaths(); SceneManager.LoadScene(fighterScenes[0], LoadSceneMode.Additive); }
void SelectMaps() { maps.Clear(); mapIndex = 0; if (!bundle) { bundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "racelevels")); } string[] scenes = bundle.GetAllScenePaths(); //print("Scene Length: " + int[] indices = new int[scenes.Length]; for (int i = 0; i < indices.Length; i++) { indices[i] = i; } //Randomize the index list and add the maps to the map list //print("Indices: " + indices.Length); for (int i = 0; i < Mathf.Min(levelsPerRace, indices.Length); i++) { int temp = indices[i]; int otherIndex = Random.Range(i, indices.Length); indices[i] = indices[otherIndex]; indices[otherIndex] = temp; maps.Add(System.IO.Path.GetFileNameWithoutExtension(scenes[indices[i]])); } }
IEnumerator Start() { if (!assetBundel) { using (WWW www = new WWW(url)) { yield return(www); if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); yield break; } assetBundel = www.assetBundle; } } string[] scenes = assetBundel.GetAllScenePaths(); foreach (var item in scenes) { laelText.text = Path.GetFileNameWithoutExtension(item); var clone = Instantiate(prefab.gameObject) as GameObject; clone.GetComponent <Button>().AddEventListener(laelText.text, LoadAssetBundelScens); clone.SetActive(true); clone.transform.SetParent(rootContainer); //Debug.Log(item); //Debug.Log(Path.GetFileNameWithoutExtension(item)); } }
private IEnumerator Start() { WWW www = new WWW(AssetURL); while (!www.isDone) { yield return(null); } AssetBundle bundle = www.assetBundle; if (AssetURL.EndsWith(".vrca") || AssetURL.StartsWith("http")) { foreach (string asset in bundle.GetAllAssetNames()) { if (asset.EndsWith(".prefab")) { GameObject avatar = (GameObject)bundle.LoadAsset(asset); Instantiate(avatar); break; } } } else if (AssetURL.EndsWith(".vrcw")) { string[] scenePaths = bundle.GetAllScenePaths(); string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePaths[0]); SceneManager.LoadScene(sceneName); } }
private IEnumerator Start() { var loadingScreenConfigJsonTextAsset = Resources.Load <TextAsset>( Path.GetFileNameWithoutExtension(LoadingScreenConfig.EngineConfigurationFileName)); if (loadingScreenConfigJsonTextAsset == null) { throw new FileNotFoundException(string.Format("{0} missing in Resources folder.", LoadingScreenConfig.EngineConfigurationFileName)); } var loadingScreenConfigJson = loadingScreenConfigJsonTextAsset.ToString(); var loadingScreenConfig = JsonUtility.FromJson <LoadingScreenConfig.EngineConfiguration>(loadingScreenConfigJson); yield return(GetAssetBundle(loadingScreenConfig.assetBundleUrl)); if (_bundle == null) { Debug.LogError("AssetBundle failed to be downloaded."); } else { var sceneLoadOperation = SceneManager.LoadSceneAsync(_bundle.GetAllScenePaths()[0]); yield return(LoadingBar.Update(sceneLoadOperation, LoadingBar.SceneLoadingMaxWidthPercentage)); } }
IEnumerator s(int i) { if (!assetBundle) { using (www = new WWW(url[i])) { loadingStart = true; yield return(www); if (!string.IsNullOrEmpty(www.error)) { print(www.error); yield break; } assetBundle = www.assetBundle; } } loadingStart = false; string[] scenes = assetBundle.GetAllScenePaths(); foreach (string s in scenes) { print(Path.GetFileNameWithoutExtension(s)); //print(Path.GetFileNameWithoutExtension(s)); //loadScene(Path.GetFileNameWithoutExtension(s)); if (Path.GetFileNameWithoutExtension(s) == objName[i]) { loadScene(Path.GetFileNameWithoutExtension(s)); } } }
private IEnumerator ReloadBundleCoroutine() { SignalManager.BeginReset(); if (workshopLevel != null) { MenuCameraEffects.instance.RemoveOverride(); workshopLevel.Reload(); } Time.timeScale = 0f; SceneManager.LoadScene("Empty"); yield return(null); yield return(null); yield return(null); bundle = FileTools.LoadBundle(workshopLevel.dataPath); string[] scenePath = bundle.GetAllScenePaths(); SceneManager.LoadScene(Path.GetFileNameWithoutExtension(scenePath[0])); yield return(null); SubtitleManager.instance.SetProgress(ScriptLocalization.TUTORIAL.LOADING, 1f, 1f); yield return(null); FixupLoadedBundle(SceneManager.GetActiveScene()); bundle.Unload(unloadAllLoadedObjects: false); currentLevel.BeginLevel(); ResetAllPLayers(); Time.timeScale = 1f; SignalManager.EndReset(); FixAssetBundleImport(); }
IEnumerator LoadScene(AssetBundle bundle, string url) { yield return(StartCoroutine(AssetBundleManager.downloadAssetBundle(url, 1))); bundle = AssetBundleManager.getAssetBundle(url, 1); string[] scenes = bundle.GetAllScenePaths(); }
public string GetScenePath(int index) { CheckIfLoaded(); var allPaths = assetBundle.GetAllScenePaths(); return(allPaths[index]); }
//加载引用的assetbundle --引用的assetbundle不卸载 private void LoadDependenciesAssetBundel(string assetBundleName) { //加载相关依赖 依赖暂时不异步加载了 string[] dependencies = _mainfest.GetAllDependencies(assetBundleName); foreach (var item in dependencies) { if (_allAssetBundles.ContainsKey(item)) { continue; } string dependenciesBundlePath = Path.Combine(_readPath, item); AssetBundle assetBundle = LoadAssetBundle(dependenciesBundlePath); //存储资源名称 string[] assetNames = assetBundle.GetAllAssetNames(); if (assetBundle.isStreamedSceneAssetBundle) { assetNames = assetBundle.GetAllScenePaths(); } foreach (var name in assetNames) { if (!_allAssets.ContainsKey(name)) { _allAssets.Add(name, assetBundle); } } //存储assetbundle _allAssetBundles[item] = new KeyValuePair <AssetBundle, string[]>(assetBundle, assetNames); } }
/// <summary> /// Load additive scene /// </summary> /// <param name="assetBundle">AssetBundle</param> /// <returns>IEnumerator</returns> // ------------------------------------------------------------------------------------------------------- protected IEnumerator loadAdditiveSceneIfNeeded(AssetBundle assetBundle) { if (!assetBundle) { yield break; } // ---------------- int progressId = 0; foreach (string str in assetBundle.GetAllScenePaths()) { var aoForAdditive = SceneManager.LoadSceneAsync(Path.GetFileNameWithoutExtension(str), LoadSceneMode.Additive); progressId = this.m_additiveSceneProgressDict.Count; if (!this.m_additiveSceneProgressDict.ContainsKey(progressId)) { this.m_additiveSceneProgressDict.Add(progressId, 0.0f); } if (aoForAdditive != null) { while (!aoForAdditive.isDone) { this.m_additiveSceneProgressDict[progressId] = aoForAdditive.progress; yield return(null); } this.m_additiveSceneProgressDict[progressId] = 1.0f; } } }
/*Corountines * By using this, the function will simply stop in that point until the WWW object is done downloading, * but it will not block the execution of the rest of the code, it yields until it is done.*/ protected IEnumerator LoadTheScene() { if (!Caching.IsVersionCached(url + "/" + AssetBundleName, version)) { WWW www = WWW.LoadFromCacheOrDownload(url + "/" + AssetBundleName, version); yeild return(www); assetBundle = www.assetBundle; www.Dispose(); if (assetBundle != null) { string[] path = assetBundle.GetAllScenePaths(); //below code is for finding the "scene name" from the bundle foreach (string temp in path) { Debug.Log(temp); string[] name = temp.Split('/'); string[] sceneName = name[name.Length - 1].Split('.'); string result = sceneName[0]; if (result == levelName) { yield return(SceneManager.LoadSceneAsync(result)); } } } } else { Debug.Log("Asset Already Cached..."); yield return(Caching.CleanCache()); //After using an asset bundle you should unload it otherwise an exception will be thrown saying asset bundle is already loaded.. if you use WWW.LoadFromCacheOrDownload again. } }
//this function loads the assets from the server onto the device IEnumerator LoadAssets() { //create unnity web request to download content from server var uwr = UnityWebRequestAssetBundle.GetAssetBundle("http://urbansittertt.com/bundles/testarea"); //this sends the web request yield return(uwr.SendWebRequest()); //this gets the content downloaded from the server AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); //this gets all the scenes from the bundle scenePath = bundle.GetAllScenePaths(); if (scenePath.Equals(" ")) { ErrorCount++; message += "\nAssets not downloaded, error encountered. Please contact administration for assistance"; } else { message = "\nLocation assets downloaded!"; } /* * There is a weird behaviour with this. The assets downloaded are accessible via this script and the assets themselves do not exist in app. * But, ideally you should have to access the content using the scenePath variable, instead unity loads the right scene based on code references. * * I don't completely understand it myself, but the scenes don't exist in the project and exist after this stuff downloads, Unity just handles it by itself. */ }
/// <summary> /// 加载mainfest -- LoadFromFile /// </summary> private void LoadPlatformMainfest(string rootBundlePath, string folderPath) { //string assetBundlePath = _readPath + "/AssetBundles"; AssetBundle mainfestAssetBundle = AssetBundle.LoadFromFile(rootBundlePath); _mainfest = mainfestAssetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); // string[] assetBundleNames = _mainfest.GetAllAssetBundles(); foreach (var item in assetBundleNames) { AssetBundle assetBundle = AssetBundle.LoadFromFile(folderPath + "/" + item); string[] assetNames = assetBundle.GetAllAssetNames(); if (assetBundle.isStreamedSceneAssetBundle) { assetNames = assetBundle.GetAllScenePaths(); } foreach (var name in assetNames) { if (!_allAssets.ContainsKey(name)) { _allAssets.Add(name, assetBundle); } } } mainfestAssetBundle.Unload(false); }
IEnumerator DownloadScene() { string url = DataProvider.init.scene.link; using (var request = UnityWebRequestAssetBundle.GetAssetBundle(url)) { Debug.LogFormat("{0}: Download scene asset bundle by url: {1}", GetType().Name, url); yield return(request.SendWebRequest()); if (request.isHttpError || request.isNetworkError) { Debug.LogErrorFormat("error request [{0}, {1}]", url, request.error); yield break; } sceneAssetBundle = DownloadHandlerAssetBundle.GetContent(request); Debug.LogFormat("{0}: Scene asset bundle downloaded", GetType().Name); sceneName = sceneAssetBundle.GetAllScenePaths()[0]; Debug.LogFormat("{0}: Start connecting to scene", GetType().Name); PhotonNetwork.GameVersion = gameVersion; PhotonNetwork.ConnectUsingSettings(); //SceneManager.LoadScene(sceneName); } }
IEnumerator Start() { NewsButton.SetActive(false); slider.SetActive(true); ClearCacheExample(); if (downloaded == 0) { using (www = WWW.LoadFromCacheOrDownload(url, 0)) { yield return(www); if (www.error != null) { throw new Exception("WWW download had an error:" + www.error); } if (www.error == null) { bundle = www.assetBundle; } } if (progress == 1) // if (Caching.ready == true) { downloaded = 1; string[] scenePath = bundle.GetAllScenePaths(); Debug.Log(scenePath[0]); SceneManager.LoadScene(scenePath[0], LoadSceneMode.Single); } } }
private IEnumerator AttemptAssetBundleDownloadsCo(int numberOfAttempts) { _downloading = true; for (var i = 0; i < numberOfAttempts; i++) { _assetBundleRetrievalAttemptCount++; Debug.LogFormat("Attempt #{0} at downloading AssetBundle...", _assetBundleRetrievalAttemptCount); yield return(GetAssetBundle(AssetBundleUrl)); if (_bundle != null) { break; } yield return(new WaitForSeconds(0.5f)); } if (_bundle == null) { ShowRetryButton(); _downloading = false; yield break; } var sceneLoadOperation = SceneManager.LoadSceneAsync(_bundle.GetAllScenePaths()[0]); var installStartFill = Mathf.Max(LoadingBar.AssetBundleDownloadToInstallRatio, _maxLoadingBarProgress); yield return(LoadingBar.FillUntilDone(sceneLoadOperation, installStartFill, 1f, false)); _downloading = false; }
public void LoadSceneAsync(string sceneName, System.Action <float> updateProgross, System.Action <string> afterCallback) { if (Resource.ResourceManager.Instance.editorMode) { StartCoroutine(LoadScene(sceneName, updateProgross, afterCallback)); return; } AssetBundle sceneBundle = Resource.ResourceManager.Instance.GetAssetBundle(string.Format("scenes/{0}.unity3d", sceneName), sceneName); if (sceneBundle != null) { string[] paths = sceneBundle.GetAllScenePaths(); string path = string.Empty; for (int i = 0; i < paths.Length; ++i) { if (paths[i].ToLower().Contains(sceneName.ToLower())) { path = paths[i]; break; } } if (string.IsNullOrEmpty(path)) { StartCoroutine(LoadScene(sceneName, updateProgross, afterCallback)); } else { StartCoroutine(LoadScene(path, updateProgross, afterCallback)); } } }
public IEnumerator InstantiateSceneFromMemoryAsync(RequestLoadSceneFromMemory requestScene) { string assetName = requestScene.AssetName; byte[] bytes = requestScene.Bytes; int version = 1; yield return(StartCoroutine(LoadAssetBundleFromMemory(bytes, assetName, version))); AssetBundle bundle = GetAssetBundle(assetName, version); if (bundle != null) { string path = bundle.GetAllScenePaths()[0]; var response = new ResponseAsset { Asset = bundle, Path = path, UserData = requestScene.UserData }; ((IRequest)requestScene).OnResponseDone(response); } else { string message = "Can not load asset " + requestScene.AssetName; ((IRequest)requestScene).OnResponseError(message); } }
private IEnumerator LoadSceneFromBundle(DLCBundle bundle, Action <string> errorCallback) { if (!LoadDLL(bundle)) { errorCallback("error: couldn't load assembly"); yield break; } AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(bundle.path); yield return(request); if (request.assetBundle == null) { errorCallback("error: could't read assetbundle"); yield break; } loadedBundle = request.assetBundle; string[] scenePaths = loadedBundle.GetAllScenePaths(); if (scenePaths.Length == 0) { errorCallback("error: no scenes in assetbundle"); loadedBundle.Unload(true); yield break; } AnalyticsService.Instance.LogEvent("scene_load", new Dictionary <string, object> { { "scene_name", scenePaths[0] } }); AsyncOperation async = SceneManager.LoadSceneAsync(scenePaths[0], LoadSceneMode.Single); SceneManager.sceneLoaded += OnExternalSceneLoaded; }
private void HandleAssetBundle(RPCSerializer rpcData) { int index = (int) rpcData.args[0]; if (index == -1) { sceneBundle = AssetBundle.LoadFromMemory (data); sceneBundle.LoadAllAssets (); string[] scenes = sceneBundle.GetAllScenePaths (); string mySceneName = scenes[0]; mySceneName = mySceneName.Substring(0, mySceneName.Length - 6); //remove .unity mySceneName = mySceneName.Substring(mySceneName.LastIndexOf("/") + 1); //remove path SceneManager.LoadScene (mySceneName); } else if (index == 0) { data = new byte[ (int) rpcData.args[1] ] ; if (sceneBundle != null) { SceneManager.LoadScene (1); sceneBundle.Unload (true); } } else { int start = (int)rpcData.args [1]; byte[] bData = (byte[] )rpcData.args [2]; for (int i = 0; i < bData.Length; i++) { data [i + start] = bData [i]; } } }