コード例 #1
0
ファイル: BundleLoader.cs プロジェクト: cnscj/THSTG
        protected override void OnUnLoad(string path)
        {
            if (!string.IsNullOrEmpty(path))
            {
                string assetPath = path;
                AssetPathUtil.SpliteBundlePath(path, out assetPath, out _);

                if (m_bundlesMap.TryGetValue(assetPath, out var bundleObj))
                {
                    UnloadBundleObject(bundleObj);
                }
            }
        }
コード例 #2
0
ファイル: BundleLoader.cs プロジェクト: cnscj/THSTG
        protected override LoadMethod OnLoadMethod(AssetLoadHandler handler)
        {
            //如果缓冲池有,则下一帧回调,否则协程回调
            string assetPath = handler.path;

            AssetPathUtil.SpliteBundlePath(handler.path, out assetPath, out _);

            if (GetBundleObject(assetPath) != null)
            {
                return(LoadMethod.Nextframe);
            }
            return(LoadMethod.Coroutine);
        }
コード例 #3
0
ファイル: BundleLoader.cs プロジェクト: cnscj/THSTG
        protected override void OnStartLoad(AssetLoadHandler handler)
        {
            var    mainHandler = handler;
            string assetPath   = mainHandler.path;

            AssetPathUtil.SpliteBundlePath(handler.path, out assetPath, out _);


            //加载顺序决定是否能完全卸载,如果先加载依赖,在加载自己,就能够完全释放(这个与释放顺序无关
            var mainDependencies = GetBundleDependencies(assetPath, false);

            if (mainDependencies != null && mainDependencies.Length > 0)
            {
                foreach (var subDependence in mainDependencies)
                {
                    var subHandler = GetOrCreateHandler(subDependence);
                    mainHandler.AddChild(subHandler);

                    StartLoadWithHandler(subHandler);
                }
            }

            base.OnStartLoad(mainHandler);
        }
コード例 #4
0
ファイル: BundleLoader.cs プロジェクト: cnscj/THSTG
        private void LoadAssetPrimitiveSync(AssetLoadHandler handler)
        {
            //同步的方法
            if (string.IsNullOrEmpty(handler.path))
            {
                LoadAssetPrimitiveCallback(handler, AssetLoadResult.EMPTY_RESULT);
                return;
            }

            string assetPath = handler.path;
            string assetName = null;

            AssetPathUtil.SpliteBundlePath(handler.path, out assetPath, out assetName);

            Object asset  = null;
            bool   isDone = false;

            //是否已经在加载池中,如果是就直接返回,引用数加1
            var bundleObject = GetBundleObject(assetPath);

            if (bundleObject != null)
            {
                asset  = bundleObject.assetBundle;
                isDone = true;
            }
            else
            {
                //不支持同步的网络下载
                if (AssetPathUtil.IsUrl(assetPath))
                {
                    asset  = null;
                    isDone = false;
                }
                else
                {
                    handler.timeoutChecker.stayTime = HANDLER_BUNDLE_LOCAL_STAY_TIME;    //本地Handler超时时间
                    var assetObj = AssetBundle.LoadFromFile(assetPath);

                    asset  = assetObj;
                    isDone = true;
                }

                LoadAssetBundleCallback(handler, asset as AssetBundle);
            }

            ////////////////////////////////
            var assetBundle = asset as AssetBundle;

            if (assetBundle != null)
            {
                if (!string.IsNullOrEmpty(assetName))
                {
                    asset  = assetBundle.LoadAsset(assetName);
                    isDone = true;
                }
            }

            var result = new AssetLoadResult(asset, isDone);

            LoadAssetPrimitiveCallback(handler, result);
        }
コード例 #5
0
ファイル: BundleLoader.cs プロジェクト: cnscj/THSTG
        //加载元操作
        private IEnumerator LoadAssetPrimitiveAsync(AssetLoadHandler handler)
        {
            if (string.IsNullOrEmpty(handler.path))
            {
                LoadAssetPrimitiveCallback(handler, AssetLoadResult.EMPTY_RESULT);
                yield break;
            }

            string assetPath = handler.path;
            string assetName = null;

            AssetPathUtil.SpliteBundlePath(handler.path, out assetPath, out assetName);

            Object asset  = null;
            bool   isDone = false;

            //是否已经在加载池中,如果是就直接返回,引用数加1
            var bundleObject = GetBundleObject(assetPath);

            if (bundleObject != null)
            {
                asset  = bundleObject.assetBundle;
                isDone = true;
            }
            else
            {
                if (AssetPathUtil.IsUrl(assetPath))                                     //是否为网络路径
                {
                    handler.timeoutChecker.stayTime = HANDLER_BUNDLE_NETWORK_STAY_TIME; //网络Handler超时时间
                    var request = UnityWebRequestAssetBundle.GetAssetBundle(assetPath);
                    request.timeout = (int)handler.timeoutChecker.stayTime;
                    m_handlerWithRequestMap[handler.id] = new RequestObj()
                    {
                        id         = handler.id,
                        webRequest = request,
                    };
                    yield return(request.SendWebRequest());

                    asset  = DownloadHandlerAssetBundle.GetContent(request);
                    isDone = request.isDone;
                }
                else
                {
                    handler.timeoutChecker.stayTime = HANDLER_BUNDLE_LOCAL_STAY_TIME;    //本地Handler超时时间
                    var request = AssetBundle.LoadFromFileAsync(assetPath);
                    m_handlerWithRequestMap[handler.id] = new RequestObj()
                    {
                        id        = handler.id,
                        abRequest = request,
                    };
                    yield return(request);

                    asset  = request.assetBundle;
                    isDone = request.isDone;
                }

                //先把加载到的AssetBundle加入记录缓存,并且标记引用次数+1
                //不记录Bundle为空的项
                LoadAssetBundleCallback(handler, asset as AssetBundle);
            }

            ////////////////////////////////
            var assetBundle = asset as AssetBundle;

            if (assetBundle != null)
            {
                if (!string.IsNullOrEmpty(assetName))
                {
                    var loadRequest = assetBundle.LoadAssetAsync(assetName);
                    yield return(loadRequest);

                    asset  = loadRequest.asset;
                    isDone = loadRequest.isDone;
                }
            }

            var result = new AssetLoadResult(asset, isDone);

            LoadAssetPrimitiveCallback(handler, result);
        }