コード例 #1
0
 private void HintRecyle(AssetBundleHint hint)
 {
     hint.mainAsset = null;
     hint.bundle.Unload(true);
     Object.Destroy(hint.bundle);
     hint.bundle = null;
 }
コード例 #2
0
        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]);
                }
            }
        }
コード例 #3
0
 private void HintLoadAssetBundle(AssetBundleHint hint)
 {
     foreach (var depHint in hint.dependenceList)
     {
         HintLoadAssetBundle(depHint);
     }
     hint.bundle = hint.bundle ?? AssetBundle.LoadFromFile(hint.bundlePath);
 }
コード例 #4
0
        private void HintIncreaseRefCount(AssetBundleHint hint)
        {
            foreach (var depHint in hint.dependenceList)
            {
                HintIncreaseRefCount(depHint);
            }

            hint.refCount++;
        }
コード例 #5
0
        private void HintLoadAssetBundleAsync(AssetBundleHint hint, ResourceAsyncCallBack callback)
        {
            var mainRequest   = new AsyncBundleCreateMainRequest();
            var createRequest = HintCreateBundleAsync(hint);

            mainRequest.callback    = callback;
            mainRequest.mainRequest = createRequest;

            AddAsyncCallback(mainRequest, OnAssetBundleLoadComplete);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 private void HintLoadMainAssetAsync(AssetBundleHint hint, ResourceAsyncCallBack callBack)
 {
     //预定
     HintIncreaseRefCount(hint);
     if (hint.bundle == null)
     {
         HintLoadAssetBundleAsync(hint, callBack);
         return;
     }
     DoHintLoadMainAssetAsync(hint, callBack);
 }
コード例 #8
0
        private void HintReduceRefCount(AssetBundleHint hint)
        {
            foreach (var depHint in hint.dependenceList)
            {
                HintReduceRefCount(depHint);
            }

            hint.refCount--;
            if (hint.refCount == 0)
            {
                HintRecyle(hint);
            }
        }
コード例 #9
0
        protected void DoLoadAsync(string path, ResourceAsyncCallBack callback)
        {
            AssetBundleHint hint = HintGet(path);

            if (hint != null)
            {
                HintLoadMainAssetAsync(hint, callback);
            }
            else
            {
                Debug.LogError("没有Asset资源");
                callback(new AsyncResourceRequest());
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }