public void AddDependency(AssetBundleReference dependency)
 {
     if (dependency != null && m_Dependencies.Add(dependency))
     {
         dependency.Retain();
     }
 }
Esempio n. 2
0
 protected void AddDependency(AssetBundleReference abr)
 {
     if (abr != null)
     {
         abr.Retain();
         m_Dependencies.Add(abr);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// load asset bundle from file
        /// </summary>
        /// <param name="path"></param>
        /// <param name="tag"></param>
        /// <param name="cacheLoadedAsset"></param>
        /// <returns>AssetBundleReference retainted.ref count add one after load.</returns>
        public AssetBundleReference LoadAssetBundleSync(string path, int tag, bool cacheLoadedAsset = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            AssetBundleReference abr = null;

            if (m_AssetBundles.ContainsKey(path))
            {
#if ASSETMANAGER_LOG_ON
                Debug.LogFormat("[AssetManage]LoadAssetBundleSync bundle is loaded {0},{1}", path, Time.frameCount);
#endif
                abr = m_AssetBundles[path];
                //refresh
                abr.AddTag(tag);

                if (cacheLoadedAsset)
                {
                    abr.Cache();
                }
            }
            else
            {
                if (m_LoadingAssetBundleLoaders.ContainsKey(path))
                {
                    Debug.LogErrorFormat("[AssetManage]LoadAssetBundleSync async loader is active {0},{1}", path, Time.frameCount);
                    //TODO Stop async
                    return(null);
                }
                else
                {
#if ASSETMANAGER_LOG_ON
                    Debug.LogFormat("[AssetManage]LoadAssetBundleSync create new loader {0},{1}", path, Time.frameCount);
#endif
                    AssetBundleSyncLoader loader = m_LoaderManager.CreateAssetBundleSyncLoader(path);
                    if (loader != null)
                    {
                        loader.state = Loader.State.Inited;
                        if (loader.cacheLoadedAsset == false && cacheLoadedAsset)
                        {
                            loader.cacheLoadedAsset = true;
                        }

                        loader.Start();
                        abr = loader.result;
                        //must retain . will be destory by loader clean
                        abr.Retain();
                        OnAssetBundleBeforeLoaded(loader);
                        OnAssetBundleAfterLoaded(loader);
                    }
                }
            }

            return(abr);
        }