IEnumerator LoadAsset(string assetName) { var loadRequest = Resources.LoadAsync(assetName); if (m_CurrentLoadTask.HasProgressCallback) { while (!loadRequest.isDone) { m_CurrentLoadTask.SafeInvokeAllProgressCallback(loadRequest.progress); yield return(null); } } else { yield return(loadRequest); } m_AssetLoadDoneEvent.Invoke(assetName, loadRequest.asset); m_CurrentLoadTask.SafeInvokeAllCallback(loadRequest.asset); AssetLoadTask.ReleaseAssetLoadTask(m_CurrentLoadTask); m_CurrentLoadTask = PopAssetLoadTask(); while (m_CurrentLoadTask != null) { var asset = AssetManager.Instance.ContainAsset(m_CurrentLoadTask.AssetName); if (asset == null) { break; } m_CurrentLoadTask.SafeInvokeAllCallback(asset); m_CurrentLoadTask = PopAssetLoadTask(); } if (m_CurrentLoadTask != null) { StartLoadAsset(); } }
IEnumerator LoadAsset(string assetName) { GetAssetDependencesForAysnc(assetName); Object asset = null; var progress = 0f; var count = m_AssetAsyncLoadOrder.Count; for (int i = 0; i < count; ++i) { var loadAssetName = m_AssetAsyncLoadOrder[i]; asset = AssetManager.Instance.ContainAsset(loadAssetName); if (asset != null) { continue; } var assetBundlePath = m_AssetDependences[loadAssetName].AssetBundlePath; var assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath); AssetBundleRequest assetbundleRequest = null; if (assetBundle != null) { if (m_CurrentLoadTask.HasProgressCallback) { var deltaProgress = 1f / count; assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object)); while (!assetbundleRequest.isDone) { var tempProgress = progress + deltaProgress * assetbundleRequest.progress; m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress); yield return(null); } progress += deltaProgress; m_CurrentLoadTask.SafeInvokeAllProgressCallback(progress); } else { assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object)); yield return(assetbundleRequest); } asset = assetbundleRequest.asset; m_AssetLoadDoneEvent(loadAssetName, asset); m_AssetBundleCollector.AddAssetBundleReference(loadAssetName, assetBundlePath); continue; } WWW www = null; if (m_CurrentLoadTask.HasProgressCallback) { var deltaProgress = 1f / count; www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath)); while (!www.isDone) { var tempProgress = progress + deltaProgress * 0.5f * www.progress; m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress); yield return(null); } assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath); if (assetBundle == null) { assetBundle = www.assetBundle; } assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object)); while (!assetbundleRequest.isDone) { var tempProgress = progress + deltaProgress * 0.5f * (1 + assetbundleRequest.progress); m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress); yield return(null); } progress += deltaProgress; m_CurrentLoadTask.SafeInvokeAllProgressCallback(progress); } else { www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath)); yield return(www); assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath); if (assetBundle == null) { assetBundle = www.assetBundle; } assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object)); yield return(assetbundleRequest); } asset = assetbundleRequest.asset; m_AssetLoadDoneEvent(loadAssetName, asset); m_AssetBundleCollector.AddAssetBundle(assetBundlePath, assetBundle); m_AssetBundleCollector.AddAssetBundleReference(loadAssetName, assetBundlePath); } m_AssetLoadDoneEvent.Invoke(assetName, asset); m_CurrentLoadTask.SafeInvokeAllCallback(asset); AssetLoadTask.ReleaseAssetLoadTask(m_CurrentLoadTask); m_CurrentLoadTask = PopAssetLoadTask(); while (m_CurrentLoadTask != null) { asset = AssetManager.Instance.ContainAsset(m_CurrentLoadTask.AssetName); if (asset == null) { break; } m_CurrentLoadTask.SafeInvokeAllCallback(asset); m_CurrentLoadTask = PopAssetLoadTask(); } if (m_CurrentLoadTask != null) { StartLoadAsset(); } }