private void HintRecyle(AssetBundleHint hint) { hint.mainAsset = null; hint.bundle.Unload(true); Object.Destroy(hint.bundle); hint.bundle = null; }
private void HintInit() { hintMap = new Dictionary <string, AssetBundleHint>(); loadedAssetHintMap = new Dictionary <long, AssetBundleHint>(); foreach (var pair in AssetBundleConfig.map) { var name = pair.Key; var node = pair.Value; hintMap[name] = new AssetBundleHint() { bundlePath = BundleTool.GetBundleFilePath(node.assetName), assetName = node.assetName }; } foreach (var pair in AssetBundleConfig.map) { var name = pair.Key; var node = pair.Value; var hint = hintMap[name]; foreach (var depName in node.depenceList) { hint.dependenceList.Add(hintMap[depName]); } } }
private void HintLoadAssetBundle(AssetBundleHint hint) { foreach (var depHint in hint.dependenceList) { HintLoadAssetBundle(depHint); } hint.bundle = hint.bundle ?? AssetBundle.LoadFromFile(hint.bundlePath); }
private void HintIncreaseRefCount(AssetBundleHint hint) { foreach (var depHint in hint.dependenceList) { HintIncreaseRefCount(depHint); } hint.refCount++; }
private void HintLoadAssetBundleAsync(AssetBundleHint hint, ResourceAsyncCallBack callback) { var mainRequest = new AsyncBundleCreateMainRequest(); var createRequest = HintCreateBundleAsync(hint); mainRequest.callback = callback; mainRequest.mainRequest = createRequest; AddAsyncCallback(mainRequest, OnAssetBundleLoadComplete); }
private void HintInvokeCallback(AssetBundleHint hint, ResourceAsyncCallBack callback) { var resourceRequest = new AsyncResourceRequest(); var asset = hint.mainAsset; loadedAssetHintMap.Add(asset.GetInstanceID(), hint); resourceRequest.isDone = true; resourceRequest.asset = hint.mainAsset; callback(resourceRequest); }
private void HintLoadMainAssetAsync(AssetBundleHint hint, ResourceAsyncCallBack callBack) { //预定 HintIncreaseRefCount(hint); if (hint.bundle == null) { HintLoadAssetBundleAsync(hint, callBack); return; } DoHintLoadMainAssetAsync(hint, callBack); }
private void HintReduceRefCount(AssetBundleHint hint) { foreach (var depHint in hint.dependenceList) { HintReduceRefCount(depHint); } hint.refCount--; if (hint.refCount == 0) { HintRecyle(hint); } }
protected void DoLoadAsync(string path, ResourceAsyncCallBack callback) { AssetBundleHint hint = HintGet(path); if (hint != null) { HintLoadMainAssetAsync(hint, callback); } else { Debug.LogError("没有Asset资源"); callback(new AsyncResourceRequest()); } }
protected override Object DoLoad(string path, Type type, bool instantiate) { AssetBundleHint hint = HintGet(path); if (hint != null) { return(HintLoadMainAsset(hint, instantiate)); } else { Debug.LogError("没有Asset资源"); return(null); } }
private Object HintLoadMainAsset(AssetBundleHint hint, bool instantiate = false) { if (hint.bundle == null) { HintLoadAssetBundle(hint); } if (hint.mainAsset == null) { hint.mainAsset = hint.bundle.LoadAsset(hint.assetName); } HintIncreaseRefCount(hint); var asset = instantiate ? Object.Instantiate(hint.mainAsset) : hint.mainAsset; loadedAssetHintMap.Add(asset.GetInstanceID(), hint); return(asset); }
private void DoHintLoadMainAssetAsync(AssetBundleHint hint, ResourceAsyncCallBack callBack) { if (hint.mainAsset != null) { HintInvokeCallback(hint, callBack); return; } var request = hint.bundle.LoadAssetAsync(hint.assetName); var assetRequest = new AsyncAssetRequest(); assetRequest.request = request; assetRequest.callback = callBack; assetRequest.hint = hint; AddAsyncCallback(assetRequest, OnAssetLoadComplete); }
private AsyncBundleCreateRequest HintCreateBundleAsync(AssetBundleHint hint) { var request = AssetBundle.LoadFromFileAsync(hint.bundlePath); var bundleRequest = new AsyncBundleCreateRequest(); bundleRequest.createRequest = request; bundleRequest.hint = hint; for (int i = 0, count = hint.dependenceList.Count; i < count; i++) { var depHint = hint.dependenceList[i]; if (depHint.bundle == null) { bundleRequest.dependenceRequestList.Add(HintCreateBundleAsync(depHint)); } } return(bundleRequest); }