private void _CleanRequest() { for (int i = 0; i < m_loadRequest.Count; ++i) { AssetLoadRequest request = m_loadRequest[i]; request.OnRelease(); } m_loadRequest.Clear(); }
public void OnUpdate() { { //time ctrl float nowTime = Time.time; if (nowTime - lastTime > 0.080f) { lastTime = nowTime; return; } bool idle = true; //load asset if (m_loadRequest.Count > 0) { for (int i = 0; i < m_loadRequest.Count; ++i) { AssetLoadRequest request = m_loadRequest[i]; if (request.GetStatus() == AssetLoadStatus.Wait) { AssetCache asset = null; if (m_assetsCache.TryGetValue(request.name, out asset)) { idle = false; request.OnAssetLoaded(asset); break;//continue; } if (request.info == null || request.info.dependBundle == null) { UnityEngine.Object obj = LoadAsset(request.name); if (obj != null) { idle = false; AssetCache cache = new AssetCache(request.name, request.info, obj); AddAssetCache(request.name, cache); request.OnAssetLoaded(cache); break; //continue; } else { request.OnAssetLoaded(null); continue; } } BundleCache bundle = m_bundleMgr.GetBundleCached(request.info.dependBundle); request.SetLoading(); if (bundle != null) { idle = false; request.OnAssetBundleLoaded(request.info.dependBundle, bundle); break; //continue; } m_bundleMgr.LoadAssetBundleAsync(request.info.dependBundle, request.OnAssetBundleLoaded); } } } //update for (int i = 0; i < m_loadRequest.Count; ++i) { AssetLoadRequest request = m_loadRequest[i]; bool handled = request.UpdateState(); if (handled) { idle = false; break; } } //__end: //clean request for (int i = 0; i < m_loadRequest.Count;) { AssetLoadRequest request = m_loadRequest[i]; if (request.GetStatus() == AssetLoadStatus.Finished) { request.OnRelease(); m_loadRequest.RemoveAt(i); } else { ++i; } } //load bundle if (idle) { //clean asset _CleanAsset(false); //load bundle m_bundleMgr.OnTick(); } lastTime = nowTime; } }