Example #1
0
        void OnAssetBundleLoaded(AssetBundleLoader loader)
        {
            AssetBundleReference abr = loader.result;

            if (abr != null)
            {
                m_AssetBundles[abr.name] = abr;

                if (loader.standalone)
                {
                    abr.Chain();
                }
                else
                {
                    abr.inChain = false;
                }

                if (m_LoadingAssetBundleLoaders.ContainsKey(abr.name))
                {
                    if (loader.autoRelease)
                    {
                        if (loader is AssetBundleAsyncLoader)
                        {
                            LoaderPool.AssetBundleAsyncLoader.Release(loader as AssetBundleAsyncLoader);
                        }
                        else
                        {
                            loader.Clean();
                        }
                    }
                    m_LoadingAssetBundleLoaders.Remove(abr.name);
                }

                abr.onDispose += OnAssetBundleDispose;
            }
        }
Example #2
0
        public AssetBundleLoader CreateAssetBundleAsyncLoader(string path)
        {
            AssetBundleLoader loader = null;
            AssetBundleInfo   info   = null;

#if !UNITY_EDITOR || ASSET_BUNDLE_LOADER
            loader = LoaderPool.AssetBundleAsyncLoader.Get();//new AssetBundleAsyncLoader();

            info = m_AssetManager.infoManager.FindAssetBundleInfo(path);
            if (info == null)
            {
                Debug.LogErrorFormat("Can't find asset bundle info {0}", path);
            }
#else
            loader = new AssetBundleEmptyLoader();
            //just for message
            info          = new AssetBundleInfo();
            info.fullName = path;
#endif

            loader.info         = info;
            loader.assetManager = m_AssetManager;
            return(loader);
        }
Example #3
0
        public AssetBundleLoader LoadAssetBundle(string path, string tag, bool standalone, Action <AssetBundleReference> completeHandle = null)
        {
            AssetBundleLoader loader = null;

            if (string.IsNullOrEmpty(path))
            {
                return(loader);
            }

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

                //refresh
                abr.AddTag(tag);

                if (standalone)
                {
                    abr.Chain();
                }

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

                //call complete callback
                if (completeHandle != null)
                {
                    completeHandle(abr);
                }
            }
            else
            {
                if (m_LoadingAssetBundleLoaders.ContainsKey(path))
                {
                    #if ASSETMANAGER_LOG
                    Debug.Log("LoadAssetBundle using loading loader " + path + "," + Time.frameCount);
                    #endif
                    loader = m_LoadingAssetBundleLoaders[path];
                }
                else
                {
                    #if ASSETMANAGER_LOG
                    Debug.Log("LoadAssetBundle create new loader " + path + "," + Time.frameCount);
                    #endif
                    loader = m_LoaderManager.CreateAssetBundleAsyncLoader(path);
                    m_LoadingAssetBundleLoaders[path] = loader;
                }

                loader.AddParamTag(tag);

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

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

                if (loader.state == Loader.State.Idle)
                {
                    loader.onAfterComplete += OnAssetBundleLoaded;
                    loader.state            = Loader.State.Inited;
                    m_LoaderManager.ActiveLoader(loader);
                }
            }

            return(loader);
        }