private static void DoLoadLevelCheck() { if (configHolder == null || configHolder.config == null || configHolder.config.loadLevelBinds == null) { return; } Dictionary <string, BTLevelConfigEntry> levelBinds = configHolder.config.loadLevelBinds; foreach (KeyValuePair <string, BTLevelConfigEntry> kvp in levelBinds) { if (kvp.Value.hotkey == null) { continue; } if (!AreKeysJustDown(kvp.Value.hotkey)) { continue; } configHolder.LogMessage(LogType.Log, "loading level: " + kvp.Key); if (kvp.Value.isLocalFile) { LoadLocalLevel(kvp.Key); } else { RsResourceManager.LoadLevel(kvp.Key); } //can only load one level at a time, so might as well stop here. break; } }
private static void LoadLocalLevel(string bundlePath) { AssetBundle bundle = null; try{ bundle = AssetBundle.LoadFromFile(bundlePath); if (bundle == null) { configHolder.LogMessage(LogType.Error, "failed to load bundleFile at path: " + bundlePath); return; } if (!bundle.isStreamedSceneAssetBundle) { configHolder.LogMessage(LogType.Error, "failed to load bundleFile-Scene, incompatible format!"); return; } string[] scenePaths = bundle.GetAllScenePaths(); if (scenePaths.Length <= 0) { configHolder.LogMessage(LogType.Error, "failed to load bundleFile-Scene, no scenes found in bundle!"); return; } configHolder.LogMessage(LogType.Log, "bundle loaded, available scenes: " + string.Join(", ", scenePaths)); RsResourceManager.LoadLevel(Path.GetFileNameWithoutExtension(scenePaths[0])); //SceneManager.LoadScene(Path.GetFileNameWithoutExtension(scenePaths[0])); }catch (Exception e) { configHolder.LogMessage(LogType.Error, "caught exception while loading bundleFile-Level: " + e.ToString()); }finally{ if (bundle != null) { bundle.Unload(false); } } }