private static void _UnloadAssetBundle(WWWItem wItem, bool clearMemory) { if (wItem.isCreated) { try { if (wItem.canAccessAssetBundle) { wItem.UnloadSafeBundle(clearMemory); } else if (Option.EnableTrace) { TsLog.Log("[TsBundle] www unload (<<No-AssetBundle>> AssetPath=\"{0}\", Stack=\"{1}\", Type={2})", new object[] { wItem.assetPath, wItem.stackName, wItem.itemType }); } wItem.Dispose(); } catch (Exception obj) { TsLog.LogWarning(obj); } } wItem._InternalOnly_ChangeStateCancel(); }
public static void REQ_ASSETBUNDLE(string resPath, PostProcPerItem callback, object obj) { WWWItem wWWItem = Holder.TryGetOrCreateBundle(resPath, null); wWWItem.SetItemType(ItemType.USER_ASSETB); wWWItem.SetCallback(callback, obj); TsImmortal.bundleService.RequestDownloadCoroutine(wWWItem, DownGroup.RUNTIME, false); }
private static void _AddTo(string stackName, WWWItem value) { Dictionary <string, WWWItem> dictionary = Holder._FindStack(stackName); if (dictionary.ContainsKey(value.assetPath)) { TsPlatform.FileLog("already added key = " + value.assetPath + ", Name = " + value.assetName); return; } dictionary.Add(value.assetPath, value); }
public static void LoadLevelAdditive(WWWItem wItem, object obj) { try { Application.LoadLevelAdditive(wItem.assetName); } catch (Exception obj2) { TsLog.LogWarning(obj2); } }
private static WWWItem TryGetBundle(string key) { if (0 > Holder.m_stackIP) { Holder._CreateDefaultStack(); } key = key.ToLower(); WWWItem result = null; Holder._TryGetBundle(key, out result); return(result); }
public static void LoadComponent(WWWItem wItem, object obj) { switch (wItem.itemType) { case ItemType.AUDIO: PostProcess.LoadComponentAudioClip(wItem, obj); break; case ItemType.MATERIAL: PostProcess.LoadComponentMaterial(wItem, obj); break; } }
public static void LoadComponentMaterial(WWWItem wItem, object obj) { if (!wItem.canAccessAssetBundle) { TsLog.LogError("TsBundle[{0}] LoadComponentMaterial download fail! {1}", new object[] { Time.frameCount, wItem.assetPath }); return; } GameObject gameObject = obj as GameObject; if (null == gameObject) { TsLog.LogError("TsBundle[{0}] LoadComponentMaterial 2nd parameter is not GameObject!", new object[] { Time.frameCount }); return; } try { MeshRenderer component = gameObject.GetComponent <MeshRenderer>(); Material material = wItem.GetSafeBundle().mainAsset as Material; if (null == component || null == material) { TsLog.LogError("TsBundle[{0}] Fail cast to Material. {1}", new object[] { Time.frameCount, wItem.assetPath }); } else { int num = component.sharedMaterials.Length; Material[] sharedMaterials = component.sharedMaterials; Material[] array = new Material[num + 1]; for (int i = 0; i < num; i++) { array[i] = sharedMaterials[i]; } array[num] = material; component.sharedMaterials = array; } } catch (Exception obj2) { TsLog.LogWarning(obj2); } }
private static void _TryGetBundle(string keyLowerString, out WWWItem wItem) { wItem = null; for (int i = Holder.m_stackIP; i >= 0; i--) { Dictionary <string, WWWItem> dictionary = Holder.m_bundleGroupStack[i]; dictionary.TryGetValue(keyLowerString, out wItem); if (wItem != null) { wItem.refCnt++; break; } } }
internal bool _RequestPreDownload(string listFileName, PreDownloader.DownlaodToComplete callback) { if (!Option.EnablePreDownload) { TsLog.LogWarning("[PreDownload] Request( \"{0}\" ) => Disalbe Pre-Download.", new object[] { listFileName }); return(false); } BackgroundInstall.Progress progress; if (BackgroundInstall.ms_ProgressCollection.TryGetValue(listFileName, out progress) && progress.downloading) { TsLog.LogWarning("[PreDownload] Request( \"{0}\" ) => alreay request pre-download.", new object[] { listFileName }); return(false); } if (Path.HasExtension(listFileName)) { WWWItem wWWItem = Holder.TryGetOrCreateBundle(listFileName, Option.undefinedStackName); if (wWWItem == null) { TsLog.LogWarning("[PreDownload] Request( \"{0}\" ) => cannot read file from AssetBundle.", new object[] { listFileName }); return(false); } wWWItem.SetCallback(new PostProcPerItem(this._DownloadComplete_ListFile), callback); wWWItem.SetItemType(ItemType.USER_STRING); TsImmortal.bundleService.RequestDownloadCoroutine(wWWItem, DownGroup.RUNTIME, true); } else { TextAsset textAsset = ResourceCache.LoadFromResourcesImmediate(string.Format("PreDownload/{0}", listFileName)) as TextAsset; if (!textAsset) { TsLog.LogWarning("[PreDownload] Request( \"{0}\" ) => cannot read file from resources.", new object[] { listFileName }); return(false); } this._DownloadAssets(listFileName, textAsset.text, callback); } return(true); }
private static void DisposeDownloadedWWW(IDownloadedItem obj, object param) { IDonwloadProgress donwloadProgress = param as IDonwloadProgress; if (donwloadProgress != null) { donwloadProgress.IncProgress(); } WWWItem wWWItem = obj as WWWItem; if (wWWItem != null) { wWWItem.Dispose(); } }
public static bool RequestDownloadWebFile(string url, bool unloadAfterPostProcess, PostProcPerItem downlaodCompleteCallbak, object callbackParam) { if (!Helper._CheckUrl(url)) { return(false); } WWWItem wWWItem = Holder.TryGetOrCreateBundle(url, Helper.WebFileBundleStackName, true); if (wWWItem == null) { return(false); } wWWItem.SetItemType(ItemType.USER_BYTESA); wWWItem.SetCallback(downlaodCompleteCallbak, callbackParam); TsImmortal.bundleService.RequestDownloadCoroutine(wWWItem, DownGroup.RUNTIME, unloadAfterPostProcess); return(true); }
public static string DbgPrint_BundleList(string stackName) { int num = 0; Holder.m_DebugMessage.Length = 0; if (stackName == null) { Holder.m_DebugMessage.AppendLine("=======================================>"); Holder.m_DebugMessage.AppendFormat("Bundle Stack Total Count({0}) CurIdx({1}) UseCache({2})\r\n", Holder._GetBundleGroupCount(), Holder.m_stackIP, Option.useCache); } else { Holder.m_DebugMessage.AppendLine("<< AssetBundles in stack >>"); } foreach (KeyValuePair <string, Dictionary <string, WWWItem> > current in Holder._EnumBundleGroupList()) { string key = current.Key; Dictionary <string, WWWItem> value = current.Value; if (stackName == null || stackName == key.ToLower()) { Holder.m_DebugMessage.AppendLine("----------------------------------------"); Holder.m_DebugMessage.AppendFormat("Holder = {0}, Cnt({1})\r\n", key, value.Count); int num2 = 0; foreach (KeyValuePair <string, WWWItem> current2 in value) { num2++; string key2 = current2.Key; WWWItem value2 = current2.Value; int safeSize = value2.safeSize; Holder.m_DebugMessage.AppendFormat("- {0}: Cache(Use:{1}, Hit:{2}, refCnt:{3}, Size:{4}) : {5}\r\n", new object[] { value2.stateString, value2.useLoadFromCacheOrDownload, value2.isCacheHit, value2.refCnt, (safeSize != 0) ? safeSize.ToString("###,###,###,###") : "0", key2 }); num += safeSize; } } } Holder.m_DebugMessage.AppendLine("----------------------------------------"); Holder.m_DebugMessage.AppendFormat("Total size = {0} bytes\r\n", num.ToString("###,###,###,###")); return(Holder.m_DebugMessage.ToString()); }
public static void LoadComponentAudioClip(WWWItem wItem, object obj) { if (!wItem.canAccessAssetBundle) { return; } GameObject gameObject = obj as GameObject; if (null == gameObject) { TsLog.LogError("LoadComponentAudioClip 2nd parameter is not GameObject!", new object[0]); return; } try { AudioClip audioClip = wItem.GetSafeBundle().mainAsset as AudioClip; if (null == gameObject.audio) { TsLog.LogError("TsBundle[{0}] Fail find AudioSource. {1}", new object[] { Time.frameCount, wItem.assetPath }); } else if (null == audioClip) { TsLog.LogError("TsBundle[{0}] Fail cast to AudioClip. {1}", new object[] { Time.frameCount, wItem.assetPath }); } else { gameObject.audio.clip = audioClip; gameObject.audio.Play(); } } catch (Exception obj2) { TsLog.LogWarning(obj2); } }
internal static WWW CancelPreDownload(string lowerCaseUrl) { WWWItem wWWItem = null; if (Holder.ms_UndefinedStack.TryGetValue(lowerCaseUrl, out wWWItem)) { if (Option.EnableTrace) { TsLog.Log("[TsBundle] Cancel to download (AssetPath=\"{0}\", Stack=\"{1}\", Type={2})", new object[] { lowerCaseUrl, wWWItem.stackName, wWWItem.itemType }); } return(wWWItem.DeliveryWWW()); } return(null); }
internal bool _IsCached(string listFileName, bool fullLog, StringBuilder targetLog, PreDownloader.CachingReport callback) { if (Path.HasExtension(listFileName)) { WWWItem wWWItem = Holder.TryGetOrCreateBundle(listFileName, Option.undefinedStackName); if (wWWItem != null) { wWWItem.SetCallback(new PostProcPerItem(this._DownloadComplete_ListFile_ForReporting), new BackgroundInstall.CachingReportPack(listFileName, fullLog, targetLog, callback)); wWWItem.SetItemType(ItemType.USER_STRING); TsImmortal.bundleService.RequestDownloadCoroutine(wWWItem, DownGroup.RUNTIME, true); return(true); } TsLog.LogWarning("[PreDownload] Request( \"{0}\" ) => cannot read file from AssetBundle.", new object[] { listFileName }); return(false); } else { TextAsset textAsset = ResourceCache.LoadFromResourcesImmediate(string.Format("{0}{1}", "PreDownload/", listFileName)) as TextAsset; if (textAsset) { float cachedRate = this._CachingReport(listFileName, textAsset.text, fullLog, targetLog); if (callback != null) { callback(listFileName, cachedRate, targetLog); } return(true); } if (targetLog != null) { targetLog.AppendFormat("{0} => error (refresh asset database, please.)", listFileName); targetLog.AppendLine(); } TsLog.LogWarning("[PreDownload] IsCached( \"{0}\" ) => cannot read file from resources.", new object[] { listFileName }); return(false); } }
public static void RemoveWWWItem(WWWItem wItem, bool clearMemory) { if (wItem.inUndefinedStack) { string key = wItem.assetPath.ToLower(); if (Holder.ms_UndefinedStack.ContainsKey(key)) { wItem.refCnt--; if (clearMemory || 0 >= wItem.refCnt) { Holder._UnloadAssetBundle(wItem, clearMemory); Holder.ms_UndefinedStack.Remove(key); } } } else { Holder.RemoveWWWItem(wItem.assetPath, clearMemory); } }
public static void RemoveWWWItem(string key, bool clearMemory) { key = key.ToLower(); WWWItem wWWItem = null; for (int i = Holder.m_stackIP; i >= 0; i--) { Dictionary <string, WWWItem> dictionary = Holder.m_bundleGroupStack[i]; dictionary.TryGetValue(key, out wWWItem); if (wWWItem != null) { wWWItem.refCnt--; if (clearMemory || 0 >= wWWItem.refCnt) { Holder._UnloadAssetBundle(wWWItem, clearMemory); dictionary.Remove(key); } } } }
public static void InstantiatePrefab(WWWItem wItem, object obj) { if (wItem.isCanceled) { return; } GameObject gameObject = obj as GameObject; if (null == gameObject) { TsLog.LogError("InstantiatePrefab 2nd parameter is not GameObject! - {0}", new object[] { wItem.assetName }); return; } if (!wItem.canAccessAssetBundle) { TsLog.LogError("Can't access assetbundle! - {0}", new object[] { wItem.assetName }); return; } UnityEngine.Object mainAsset = wItem.GetSafeBundle().mainAsset; if (null != mainAsset) { GameObject gameObject2 = mainAsset as GameObject; GameObject gameObject3 = UnityEngine.Object.Instantiate(gameObject2) as GameObject; gameObject3.transform.parent = gameObject.transform; gameObject3.transform.localPosition = gameObject2.transform.localPosition; gameObject3.transform.localRotation = gameObject2.transform.localRotation; } else { TsLog.LogError("OnCompleteAsyncLoadGameObject(). assetBundle.mainAsset is not GameObjcet! - {0}", new object[] { wItem.assetName }); } }
public static WWWItem TryGetOrCreateBundle(string key, string stackName, bool immediatelyUrl) { if (0 > Holder.m_stackIP) { Holder._CreateDefaultStack(); } if (!key.Contains("?notlow")) { key = key.ToLower(); } WWWItem wWWItem = null; Holder._TryGetBundle(key, out wWWItem); if (wWWItem == null) { Dictionary <string, WWWItem> dictionary = Holder._FindStack(stackName); dictionary.TryGetValue(key, out wWWItem); if (wWWItem == null) { int index = Holder.m_bundleGroupStack.IndexOf(dictionary); stackName = Holder.m_bundleNameStack[index]; wWWItem = new WWWItem(stackName); if (immediatelyUrl) { wWWItem.SetAnotherUrl(key); } else { wWWItem.SetAssetPath(key); } Holder._AddTo(stackName, wWWItem); } } wWWItem.refCnt++; return(wWWItem); }
private static void _WriteToHistory(WWWItem item) { if (!Application.isEditor) { TsLog.LogWarning("[PreDownload] Pre-Download history => WebPlayer is not supported", new object[0]); return; } string path = string.Format("{0}/../PreDownload_History.txt", Application.dataPath); try { using (StreamWriter streamWriter = new StreamWriter(path, true, Encoding.UTF8)) { DateTime utcNow = DateTime.UtcNow; streamWriter.WriteLine("({6}-{7}-{8}) [{3}:{4}:{5}] Type={0}, Stack=\"{1}\", Path=\"{2}\"", new object[] { item.itemType, item.stackName, item.assetPath, utcNow.Hour, utcNow.Minute, utcNow.Second, utcNow.Year, utcNow.Month, utcNow.Day }); } } catch (Exception ex) { TsLog.LogWarning("[PreDownlaod] ", new object[] { ex }); } }
internal static WWWItem GetPreDownloadBundle(string assetPath, ItemType type) { WWWItem wWWItem = null; string text = assetPath.ToLower(); foreach (Dictionary <string, WWWItem> current in Holder.m_bundleGroupStack) { if (current.ContainsKey(text)) { WWWItem result = null; return(result); } } if (Holder.ms_UndefinedStack.TryGetValue(text, out wWWItem)) { return(null); } wWWItem = new WWWItem(Option.undefinedStackName); wWWItem.SetAssetPath(text); Holder.ms_UndefinedStack.Add(text, wWWItem); wWWItem.SetItemType(type); wWWItem.refCnt++; return(wWWItem); }
public void _InternalOnly_ChangeStateRequest() { if (this.wiState != WWWItem.StateWI.UNLOADED) { if (this.wiState != WWWItem.StateWI.DESTROIED) { this.retryRequested = false; this.wiState = WWWItem.StateWI.REQUESTED; string text; if (string.IsNullOrEmpty(this.anotherURL)) { if (Option.usePatchDir && this.m_protocol == Protocol.HTTP && this.m_kItem != null) { string protocolRootPath = Option.GetProtocolRootPath(this.m_protocol); string format = string.Empty; if (protocolRootPath[protocolRootPath.Length - 1] == '/') { if (this.assetPath[0] == '/') { format = "{0}{1}{2}"; } else { format = "{0}{1}/{2}"; } } else if (this.assetPath[0] == '/') { format = "{0}/{1}{2}"; } else { format = "{0}/{1}/{2}"; } text = string.Format(format, protocolRootPath, this.m_kItem.VersionDir, this.assetPath); } else { text = Option.GetProtocolRootPath(this.m_protocol) + this.assetPath; } } else { text = this.anotherURL; } if (this.m_protocol == Protocol.HTTP && 0 < this.retryCnt) { if (text.Contains("?r=")) { text = string.Format("{0}{1}", text, this.retryCnt); } else { text = string.Format("{0}?r={1}{2}", text, (int)(UnityEngine.Random.value * 1000000f), this.retryCnt); } TsLog.Log("[TsBundle] TsBundle:Retry = \"{0}\"", new object[] { text }); } if (Option.EnableTrace) { TsLog.Log("[TsBundle] www loading (AssetPath=\"{0}\", Stack=\"{1}\", Type={2}, Size={3:#,###,###,###}, UnloadReserved={4}, RefCount={5} ) {6}", new object[] { this.assetPath, this.stackName, this.itemType, (this.m_kItem != null) ? this.m_kItem.nFileSize : 0, this.DebugUnloadReserved, this.refCnt, (this.m_kItem != null) ? ((!TsCaching.IsVersionCached(text, this.m_kItem.nVersion, this.m_kItem.bUseCustomCache)) ? "<<will download>>" : "<<Cached>>") : "<<not listed>>" }); } if (string.IsNullOrEmpty(this.anotherURL)) { UsingAssetRecorder.RecordFile(this.assetPath); } this._ReleaseLoadedAsset(); if (this.useLoadFromCacheOrDownload) { if (!this.inUndefinedStack) { this.m_www = Holder.CancelPreDownload(this.assetPath); } if (this.m_www == null) { this.m_www = TsCaching.LoadFromCacheOrDownload(text, this.m_kItem.nVersion, (long)this.m_kItem.nFileSize, this.m_kItem.bUseCustomCache, this); } if (!this.isCacheHit) { Holder.DbgAddWWWItemStat(this.assetPath, this.m_kItem.nFileSize); if (0 < this.m_kItem.nFileSize && WWWItem.OnIncreaseSizeOfDownload != null) { WWWItem.OnIncreaseSizeOfDownload(this.m_kItem.nFileSize); } } } else { Holder.DbgAddWWWItemStat(this.assetPath, 0); this.m_www = new WWW(text); } this.retryCnt++; return; } } try { if (Option.EnableTrace) { TsLog.Log("[TsBundle] cannot request download, already unloaded bundle (AssetPath=\"{0}\", Stack=\"{1}\", Type={2}, SIze={3:#,###,###,###})\n\rCallStack={4}", new object[] { this.assetPath, this.stackName, this.itemType, (this.m_kItem != null) ? this.m_kItem.nFileSize : 0, this.RequestCallStack }); } } catch (Exception arg) { TsLog.Log("[TsBundle] " + arg, new object[0]); } }
public void _InternalOnly_ChangeStateSuccess() { this.wiState = WWWItem.StateWI.SUCCESS; this.safeBundle = null; this.safeBytes = null; this.safeString = null; this.safeAudioClip = null; if (this.useLoadFromCacheOrDownload) { this.safeSize = ((this.m_kItem == null) ? 0 : this.m_kItem.nFileSize); } else { this.safeSize = ((this.m_www == null) ? 0 : this.m_www.size); } bool flag = !this.isCacheHit && this.itemType == ItemType.UNDEFINED && this.UseCustomCache; if (flag) { if (Option.EnableTrace) { TsLog.LogWarning("[TsBundle] set RawBytes => Cache Hit[{0}], Use[{1}] (AssetPath=\"{2}\", Stack=\"{3}\", Type={4})", new object[] { this.isCacheHit, this.useLoadFromCacheOrDownload, this.assetPath, this.stackName, this.itemType }); } this.rawBytes = this.m_www.bytes; } try { if (this.itemType == ItemType.USER_STRING) { this.safeString = this.m_www.text; if (this.safeString == null) { this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.text."); } } else if (this.itemType == ItemType.USER_BYTESA) { this.safeBytes = ((this.rawBytes == null) ? this.m_www.bytes : this.rawBytes); if (this.safeBytes == null) { this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.bytes."); } } else if (this.itemType == ItemType.USER_AUDIO) { this.safeAudioClip = this.m_www.GetAudioClip(false, true); if (null == this.safeAudioClip) { this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.AudioClip."); } } else if (this.itemType == ItemType.UNDEFINED) { if (this.refCnt == 1) { this.Dispose(); } if (this.m_kItem != null) { TsCaching.MarkAsUsed(this.assetPath, this.m_kItem.nVersion, this.m_kItem.bUseCustomCache); } } else { this.safeBundle = this.m_www.assetBundle; if (null == this.safeBundle) { this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.assetBundle."); throw new NullReferenceException(); } this.mainAsset = this.safeBundle.mainAsset; TsFix.AudioSourceWarning(this.mainAsset as GameObject); if (this.loadAll) { this.subBundles = this.safeBundle.LoadAll(); UnityEngine.Object[] subBundles = this.subBundles; for (int i = 0; i < subBundles.Length; i++) { UnityEngine.Object @object = subBundles[i]; TsFix.AudioSourceWarning(@object as GameObject); } } } if (Option.EnableTrace) { bool flag2 = false; int num = -1; if (this.m_kItem != null) { string url = Helper.FullURL(this.assetPath); num = this.m_kItem.nVersion; flag2 = TsCaching.IsVersionCached(url, num, this.m_kItem.bUseCustomCache); } TsLog.Log("[TsBundle] download => success (AssetPath=\"{0}\", Stack=\"{1}\", Type={2}, Version={3}, RefCnt={4}, LoadFromCacheOrDownload={5}, Disposed={6}), Cached => {7}\r\nCallStack={8}", new object[] { this.assetPath, this.stackName, this.itemType, num, this.refCnt, this.useLoadFromCacheOrDownload, this.m_www == null, (string.IsNullOrEmpty(this.anotherURL) || this.useLoadFromCacheOrDownload) ? flag2.ToString() : "(ignore)" }); } } catch (Exception ex) { TsLog.LogError("[TsBundle] Unity Assetbundle access exception! (Protocol=\"{0}\", AssetPath=\"{1}\", Stack=\"{2}\", Type={3}) => {4}\r\nCallStack={5}", new object[] { Option.GetProtocolRootPath(this.m_protocol), this.assetPath, this.stackName, this.itemType, ex.ToString(), this.RequestCallStack }); this._InternalOnly_ChangeStateErrorOrRetry("Exception! Unity Assetbundle access violation!"); } if (!this.useLoadFromCacheOrDownload && !this.isCacheHit && 0 < this.safeSize) { Holder.DbgAddWWWItemStat(this.assetPath, this.safeSize); if (WWWItem.OnIncreaseSizeOfDownload != null) { WWWItem.OnIncreaseSizeOfDownload(this.safeSize); } } }
public void _InternalOnly_ChangeStateErrorOrRetry(string error) { string text = string.Format("{5}\t[TsBundle] {0} (AssetPath=\"{1}\", Stack=\"{2}\", Type={3})\r\nRequestCallStack=\"{4}\"", new object[] { error, this.assetPath, this.stackName, this.itemType, this.RequestCallStack, Scene.CurScene.ToString() }); if (TsPlatform.IsMobile) { TsPlatform.FileLog(text); } if (error.Contains("404 Not Found")) { TsLog.LogWarning(text, new object[0]); this.wiState = WWWItem.StateWI.ERROR; this.isFileNotFound = true; } else if (error.Contains("Exception!")) { this.wiState = WWWItem.StateWI.ERROR; } else { int num = 2; if (string.IsNullOrEmpty(this.anotherURL)) { if (TsPlatform.IsMobile) { num = 5; } } else { TsLog.LogWarning(text, new object[0]); } if (!this.retryRequested) { if (!Option.isPause && this.retryCnt >= num) { if (string.IsNullOrEmpty(this.anotherURL)) { string text2 = string.Format("{6}\t[TsBundle] Retry: {5} - {0} (AssetPath=\"{1}\", Stack=\"{2}\", Type={3})\r\nRequestCallStack=\"{4}\"", new object[] { error, this.assetPath, this.stackName, this.itemType, this.RequestCallStack, this.retryCnt, Scene.CurScene.ToString() }); TsLog.Assert(false, text2, new object[0]); if (WWWItem._errorCallback != null) { WWWItem._errorCallback(text2); } if (TsPlatform.IsMobile) { TsPlatform.FileLog(text2); } } this.wiState = WWWItem.StateWI.ERROR; } else { this.wiState = WWWItem.StateWI.CREATED; } } } }