IEnumerator WaitLoadLevel(AssetBundleLoadLevelOperation operation, UnityAction <float> onProgressChanged) { while (!operation.IsDone()) { if (operation.m_Request != null) { operation.m_Request.allowSceneActivation = false; if (operation.m_Request.progress >= 0.9f) { operation.m_Request.allowSceneActivation = true; if (onProgressChanged != null) { onProgressChanged(1); } break; } else { if (onProgressChanged != null) { onProgressChanged(operation.m_Request.progress); } } } yield return(null); } }
static public int IsDone(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif AssetBundleLoadLevelOperation self = (AssetBundleLoadLevelOperation)checkSelf(l); var ret = self.IsDone(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
IEnumerator WaitLoadLevel(AssetBundleLoadLevelOperation operation, UnityAction <float> onProgressChanged) { var retio = 0.7f; while (!operation.IsDone()) { if (operation.m_Request != null) { Debug.Log("operation.m_Request.progress:" + operation.m_Request.progress); operation.m_Request.allowSceneActivation = false; if (operation.m_Request.progress >= 0.9f) { operation.m_Request.allowSceneActivation = true; if (onProgressChanged != null) { onProgressChanged(1); } break; } else { if (onProgressChanged != null) { onProgressChanged(operation.m_Request.progress * (1 - retio) + retio); } } } else { Debug.Log("operation.progress:" + operation.progress); onProgressChanged(operation.progress * retio); } yield return(null); } //activeLoader.UnloadAssetBundle(operation.AssetBundleName); System.GC.Collect(); }
protected override void OnUpdate(float delta) { base.OnUpdate(delta); if (!IsInited) { // 等AssetBundleManifest初始化完成,再继续更新其他Operation #if UNITY_EDITOR if (AssetBundleManager.SimulateAssetBundleInEditor) { IsInited = true; Callback(Utility.GetPlatformName()); } else { #endif if (m_AssetBundleLoadManifestOperation != null && m_AssetBundleLoadManifestOperation.IsDone()) { IsInited = true; Callback(Utility.GetPlatformName(), m_AssetBundleLoadManifestOperation.GetAsset <AssetBundleManifest>(), m_AssetBundleLoadManifestOperation.Error); m_AssetBundleLoadManifestOperation = null; } #if UNITY_EDITOR } #endif } else { //bundle UpdateLoadAssets(); //场景 if (m_LoadSceneOpration != null) { IsLoadingScene = true; LoadingSceneProgress = m_LoadSceneOpration.Progress(); if (m_LoadSceneOpration.IsDone() && !string.IsNullOrEmpty(m_LoadSceneOpration.Error)) { IsLoadingScene = false; Callback(m_LoadSceneOpration.LevelName, null, m_LoadSceneOpration.Error); m_LoadSceneOpration = null; } } } #if UNITY_EDITOR if (isDirty) { isDirty = false; InspectorShower.Clear(); InspectorShower.AddRange(m_AssetCaches.Values); InspectorShower.Sort( (a, b) => { if (a.hold != b.hold) { return(a.hold - b.hold); } else if (a.refCount != b.refCount) { return(b.refCount - a.refCount); } else { return(string.Compare(a.assetName, b.assetName)); } }); } #endif }