private IEnumerator Get() { byte[] file = { }; bool done = false; bool found = false; string error = String.Empty; string uriFile = Settings.Instance().TempFolder + Uri.Replace('\\', '/'); if (File.Exists(uriFile)) { found = true; } new Thread(() => { try { file = File.ReadAllBytes(uriFile); done = true; } catch (Exception e) { error = e.Message; done = true; } }).Start(); while (!done) { yield return(null); } if (!found) { error = "file not found"; } if (file.Length == 0 || error != String.Empty) { ((IRequest)this).OnResponseError($"Load file {Uri} from tar error! {error}"); } else { ResponseTar response = new ResponseTar { ByteData = file, UserData = UserData }; ((IRequest)this).OnResponseDone(response); } yield return(true); #endregion }
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 static void LoadCustomAssetTar(AssetInfo assetInfo, PrefabObject o, ref GameEntity loadCounter, Dictionary <string, Type> typesInDll) { string assetName = assetInfo.AssetName; string assetBundleUri = o.Resources.Bundle; RequestTar requestAssetData = new RequestTar(assetBundleUri); GameEntity entity = loadCounter; requestAssetData.OnFinish += responseData => { ResponseTar responseTar = (ResponseTar)responseData; var bundleData = responseTar.ByteData; RequestLoadAssetFromMemory requestAsset = new RequestLoadAssetFromMemory(assetName, bundleData, new object[] { o, assetInfo }); GameEntity counter = entity; requestAsset.OnFinish += response => { CreatePrefabEntity(response, ref counter, o); }; }; }