Exemplo n.º 1
0
        public AssetBundleLoader CreateAssetBundleAsyncLoader(string path)
        {
            AssetBundleLoader loader = null;
            AssetBundleInfo   info   = null;

#if !UNITY_EDITOR || ASSET_BUNDLE_LOADER
            info = m_AssetManager.infoManager.FindAssetBundleInfo(path);
            if (info == null)
            {
                Debug.LogErrorFormat("[AssetManage]Can't find asset bundle info {0}", path);
                return(null);
            }
            loader = LoaderPool.AssetBundleAsyncLoaderPool.Get();
#else
            loader = new AssetBundleEmptyLoader();
            //just for message
            info          = new AssetBundleInfo();
            info.fullName = path;
#endif

            loader.info         = info;
            loader.assetManager = m_AssetManager;
            return(loader);
        }
Exemplo n.º 2
0
 public override void Clean()
 {
     base.Clean();
     m_AssetBundleLoader = null;
     m_Request           = null;
 }
Exemplo n.º 3
0
        /// <summary>
        /// async load asset bundle
        /// 同一个资源只有一个正在加载的loader
        /// </summary>
        /// <param name="path"></param>
        /// <param name="tag"></param>
        /// <param name="cacheLoadedAsset"></param>
        /// <param name="completeHandle"></param>
        /// <returns></returns>
        public AssetBundleLoader LoadAssetBundle(string path, int tag, bool cacheLoadedAsset, Action <AssetBundleReference> completeHandle = null, bool autoStart = true)
        {
            AssetBundleLoader loader = null;

            if (string.IsNullOrEmpty(path))
            {
                if (completeHandle != null)
                {
                    completeHandle(null);
                }
                return(loader);
            }

            if (m_AssetBundles.ContainsKey(path))
            {
#if ASSETMANAGER_LOG_ON
                Debug.Log("[AssetManage]LoadAssetBundle asset bundle is loaded " + path + "," + Time.frameCount);
#endif
                //asset bundle is loaded
                AssetBundleReference abr = m_AssetBundles[path];

                //refresh
                abr.AddTag(tag);

                if (cacheLoadedAsset)
                {
                    abr.Cache();
                }

                loader           = m_LoaderManager.CreateAssetBundleAsyncLoader(path);
                loader.forceDone = true;
                loader.result    = abr;

                //call complete callback
                if (completeHandle != null)
                {
                    loader.onComplete += completeHandle;
                }

                loader.IncreaseLoadingRequest();

                loader.onAfterComplete += OnAssetBundleAfterLoaded;
                loader.state            = Loader.State.Completed;
                if (autoStart)
                {
                    m_LoaderManager.ActiveLoader(loader);
                }
            }
            else
            {
                if (m_LoadingAssetBundleLoaders.ContainsKey(path))
                {
#if ASSETMANAGER_LOG_ON
                    Debug.Log("[AssetManage]LoadAssetBundle using loading loader " + path + "," + Time.frameCount);
#endif
                    loader = m_LoadingAssetBundleLoaders[path];
                }
                else
                {
#if ASSETMANAGER_LOG_ON
                    Debug.Log("[AssetManage]LoadAssetBundle create new loader " + path + "," + Time.frameCount);
#endif
                    loader = m_LoaderManager.CreateAssetBundleAsyncLoader(path);
                    if (loader != null)
                    {
                        m_LoadingAssetBundleLoaders[path] = loader;
                    }
                    else
                    {
                        if (completeHandle != null)
                        {
                            completeHandle(null);
                        }
                        return(null);
                    }
                }

                loader.AddParamTag(tag);

                if (loader.cacheLoadedAsset == false && cacheLoadedAsset)
                {
                    loader.cacheLoadedAsset = true;
                }

                if (completeHandle != null)
                {
                    loader.onComplete += completeHandle;
                }

                if (loader.state == Loader.State.Idle)
                {
                    loader.onBeforeComplete += OnAssetBundleBeforeLoaded;
                    loader.onAfterComplete  += OnAssetBundleAfterLoaded;
                    loader.state             = Loader.State.Inited;
                    if (autoStart)
                    {
                        m_LoaderManager.ActiveLoader(loader);
                    }
                }
            }
            return(loader);
        }
Exemplo n.º 4
0
 void OnAssetBundleAfterLoaded(AssetBundleLoader loader)
 {
     m_LoaderManager.ReleaseLoader(loader);
 }