private static void LoadSceneFromStorage(LocationPrefub locationPrefub, string environmentDirectory) { string sceneName = locationPrefub.Name; LogManager.GetCurrentClassLogger().Info($"Loading location \"{sceneName}\" from storage: " + Time.time); byte[] bytes = null; RequestTread requestTread = new RequestTread(delegate { bytes = File.ReadAllBytes(Path.Combine(environmentDirectory, "bundle")); }); requestTread.OnFinish += responseTread => { RequestLoadSceneFromMemory request = new RequestLoadSceneFromMemory(sceneName, bytes); request.OnFinish += response1 => { ResponseAsset response = (ResponseAsset)response1; string scenePath = Path.GetFileNameWithoutExtension(response.Path); WorldDataListener.Instance.LoadScene(scenePath); }; request.OnError += s => { string message = ErrorHelper.GetErrorDescByCode(TM.Errors.ErrorCode.EnvironmentNotFoundError); LogManager.GetCurrentClassLogger().Fatal("Location is not loaded from storage! " + s); LauncherErrorManager.Instance.Show(message, null); }; }; }
public static void LoadScene(int locationId) { _startLoadingTime = DateTime.Now; LocationPrefub location = WorldData.WorldStructure.Locations.GetLocation(locationId); if (location == null) { return; } string sceneName = location.Name; LogManager.GetCurrentClassLogger().Info($"Loading location \"{sceneName}\" from tar file"); RequestTar requestConfig = new RequestTar(location.Resources.Config); requestConfig.OnFinish += responseConfig => { SceneData sceneData = ((ResponseTar)responseConfig).TextData.JsonDeserialize <SceneData>(); RequestTar requestTar = new RequestTar(location.Resources.Bundle); requestTar.OnFinish += response => { ResponseTar responseTar = (ResponseTar)response; byte[] bundle = responseTar.ByteData; RequestLoadSceneFromMemory request = new RequestLoadSceneFromMemory(sceneData.AssetBundleLabel, bundle); request.OnFinish += response1 => { ResponseAsset responseAsset = (ResponseAsset)response1; string scenePath = Path.GetFileNameWithoutExtension(responseAsset.Path); WorldDataListener.Instance.LoadScene(scenePath); }; Resources.UnloadUnusedAssets(); request.OnError += s => { Helper.ShowErrorLoadScene(); }; }; requestTar.OnError += s => { Helper.ShowErrorLoadScene(); }; }; }
public override void LoadLocation(int locationId) { LocationPrefab location = ProjectData.ProjectStructure.Locations.GetProjectScene(locationId); Logger.Info($"Loading location \"{location.Name}\" from tar file"); RequestFileRead requestConfig = new RequestFileRead(location.ConfigResource); requestConfig.OnFinish += responseConfig => { SceneData sceneData = ((ResponseFileRead)responseConfig).TextData.JsonDeserialize <SceneData>(); RequestFileRead requestFileRead = new RequestFileRead(ProjectData.ProjectStructure.IsMobile ? location.AndroidBundleResource : location.BundleResource); requestFileRead.OnFinish += response => { ResponseFileRead responseFileRead = (ResponseFileRead)response; byte[] bundle = responseFileRead.ByteData; RequestLoadSceneFromMemory request = new RequestLoadSceneFromMemory(sceneData.AssetBundleLabel, bundle); request.OnFinish += response1 => { ResponseAsset responseAsset = (ResponseAsset)response1; string scenePath = Path.GetFileNameWithoutExtension(responseAsset.Path); ProjectDataListener.Instance.LoadScene(scenePath); }; Resources.UnloadUnusedAssets(); request.OnError += s => { Helper.ShowErrorLoadScene(); }; }; requestFileRead.OnError += s => { Helper.ShowErrorLoadScene(); }; }; }
private void LoadLocationFromWeb(LocationPrefab locationPrefab, string environmentDirectory) { DateTime startLoadingTime = DateTime.Now; Logger.Info($"Loading location \"{locationPrefab.Name}\" from web"); RequestUri sceneDataRequest = new RequestUri(locationPrefab.ConfigResource); sceneDataRequest.OnFinish += response => { string json = ((ResponseUri)response).TextData; SceneData sceneData = json.JsonDeserialize <SceneData>(); List <string> environmentFiles = new List <string>(3) { ProjectData.IsMobileVr() ? locationPrefab.AndroidBundleResource : locationPrefab.BundleResource, locationPrefab.IconResource, ProjectData.IsMobileVr() ? locationPrefab.AndroidManifestResource : locationPrefab.ManifestResource, }; RequestDownLoad requestDownloads = new RequestDownLoad(environmentFiles, environmentDirectory, LoaderAdapter.OnLoadingUpdate, this, LanguageManager.Instance.GetTextValue("LOADING_FILE")); requestDownloads.OnFinish += response1 => { TimeSpan span = DateTime.Now - startLoadingTime; Logger.Info($"Location \"{locationPrefab.Name}\" is loaded. Time = {span.Seconds} sec."); ResponseDownLoad responseDownLoad = (ResponseDownLoad)response1; string sceneName = sceneData.Name; string assetName = ProjectData.IsMobileVr() ? "android_" + sceneData.AssetBundleLabel : sceneData.AssetBundleLabel; foreach (var key in responseDownLoad.DownLoadedData.Keys) { Logger.Info("Downloaded for scene" + sceneName + ": " + key); } byte[] bytes = responseDownLoad.DownLoadedData[assetName].ToArray(); Logger.Info($"Loading location \"{sceneName}\"..."); RequestLoadSceneFromMemory request = new RequestLoadSceneFromMemory(sceneName, bytes); request.OnFinish += response2 => { ResponseAsset responseAsset = (ResponseAsset)response2; string scenePath = Path.GetFileNameWithoutExtension(responseAsset.Path); ProjectDataListener.Instance.LoadScene(scenePath); }; request.OnError += s => { ShowErrorLoadScene(); }; }; requestDownloads.OnError += s => { ShowErrorLoadScene(); }; }; sceneDataRequest.OnError += s => { ShowErrorLoadScene(); }; }