Beispiel #1
0
            private List <string> dependentBundleNamesLoading;           //当前正在加载的依赖包名列表

            public KTBundleLoader CreateBundleLoader(string bundleName, Action <KTBundleLoader> callback)
            {
                var loader = new KTBundleLoader()
                {
                    requestBundleName  = bundleName,
                    cacheType          = bundleName == requestBundleName?cacheType: BundleCacheType.TimeoutCache,
                    cacheTimeout       = bundleName == requestBundleName ? cacheTimeout:0,
                    callbackForManager = callback
                };

                loader.Subscribe(this);

                if (dependentBundleNamesLoading == null)
                {
                    dependentBundleNamesLoading = new List <string>()
                    {
                        bundleName
                    }
                }
                ;
                else
                {
                    dependentBundleNamesLoading.Add(bundleName);
                }

                return(loader);
            }
Beispiel #2
0
        /// <summary>
        /// 此种方式只能加载需要预加载的依赖包
        /// </summary>
        /// <param name="bundleName"></param>
        /// <param name="completeCallback"></param>
        /// <param name="cacheTimeout"></param>
        public void LoadBundle(string bundleName, Action <string> completeCallback = null)
        {
            if (!CheckInited())
            {
                completeCallback?.Invoke("");
                return;
            }

            IncreaseRef(bundleName);

            var bundleLoader = new KTBundleLoader()
            {
                requestBundleName  = bundleName,
                cacheType          = BundleCacheType.Share,
                request            = AssetBundle.LoadFromFileAsync(bundleName),
                callbackForManager = BundleCompleteCallback
            };

            Action <KTBundleLoader> callback = null;

            callback = (loader) =>
            {
                completeCallback?.Invoke(bundleName);
                bundleLoader.UnSubscribe(callback);
            };

            bundleLoader.Subscribe(callback);
            m_bundleLoading.Add(bundleName, bundleLoader);
            bundleLoader.BeginLoad();
        }
Beispiel #3
0
        private void BundleCompleteCallback(KTBundleLoader loader)
        {
            var bundleInfo = new KTBundleInfo()
            {
                name         = loader.requestBundleName,
                bundle       = loader.request.assetBundle,
                cacheType    = loader.cacheType,
                cacheTimeout = loader.cacheTimeout,
                startTime    = 0
            };

            m_bundleLoaded.Add(loader.requestBundleName, bundleInfo);
            loader.Release();
            m_bundleLoading.Remove(loader.requestBundleName);
        }
Beispiel #4
0
            public void BundleLoadedCallback(KTBundleLoader bundleLoader)
            {
                bundleLoader.UnSubscribe(this);
                dependentBundleNamesLoading.Remove(bundleLoader.requestBundleName);

                if (dependentBundleNamesLoading.Count > 0)
                {
                    return;
                }

                if (loaderType == LoaderType.Asset)
                {
                    assetRequest            = bundleLoader.request.assetBundle.LoadAssetAsync(requestAssetName);
                    assetRequest.completed += AssetLoadedCallback;
                }
                else if (loaderType == LoaderType.Scene)
                {
                    sceneRequest            = SceneManager.LoadSceneAsync(requestAssetName, loadMode);
                    sceneRequest.completed += SceneLoadedCallback;
                }
            }