Esempio n. 1
0
        /// <summary>
        /// 加载资源的总接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">相对于Asset/Export的目录资源</param>
        /// <returns></returns>
        protected T actualLoadResource <T>(string name) where T : UObject
        {
            if (!_init)
            {
                throw new Exception("Res has not initialised,It can be used after initialised in GameController !");
            }
            T            t            = null;
            CachedObject cachedObject = null;

            if (AssetBundleConfig.Instance.UseAssetBundle)
            {
                AssetBundleInfo bundleInfo = AssetBundleManager.Instance.GuessBundleByAssetName(name);

                if (bundleInfo.isEmpty())
                {
                    DebugUtil.LogError("Res.LoadResource(),AssetBundleManager.GueessBundleByAssetName can't find the AssetBundle container the asset :__ {0} __", name);
                }
                else
                {
                    CachedAssetBundle cab = _cachedAssetBundleContainer.LoadCachedAssetBundle(bundleInfo);
                    if (cab != null)
                    {
                        string assetPureName = ParseAssetName(name);
                        if (!string.IsNullOrEmpty(assetPureName))
                        {
                            cachedObject = cab.LoadCachedObject <T>(assetPureName);
                            //return cab.LoadAsset<T>(assetPureName);
                            if (cachedObject != null)
                            {
                                t = cachedObject.GetAsset <T>();
                            }
                        }
                    }
                }
            }
            else
            {
                cachedObject = _cachedEditorObjectContainer.LoadCachedObject <T>(name);
                if (cachedObject != null)
                {
                    t = cachedObject.GetAsset <T>();
                }
            }
            RegisterAsset(t, cachedObject);
            return(t);
        }
Esempio n. 2
0
        /// <summary>
        /// 所有缓存全部卸载,只能被父类调用
        /// </summary>
        public void Unload(bool unloadallLoadedObjects = false)
        {
            Release();
            if (unloadallLoadedObjects)
            {
                while (activeCopies.Count > 0)
                {
                    GameObject.Destroy(activeCopies[0]);
#if UNITY_EDITOR
                    RemoveDestroyNotify(activeCopies[0] as GameObject);
#endif
                    activeCopies.RemoveAt(0);
                }
                RefCount = 0;
            }
            //GameObject.Destroy(source);
            source = null;
            parent = null;
        }
Esempio n. 3
0
 /// <summary>
 /// 加载Bundle,会加载该Bundle的依赖
 /// </summary>
 /// <param name="assetBundleName"></param>
 private void LoadBundle(AssetBundleInfo bundleInfo)
 {
     //加载自己
     if (!this.CachedAssetBundleDictionary.ContainsKey(bundleInfo.AssetBundleName) || this.CachedAssetBundleDictionary[bundleInfo.AssetBundleName] == null)
     {
         string      url = FilePathTools.persistentDataPath_Platform + "/" + bundleInfo.AssetBundleName;
         AssetBundle ab  = AssetUtils.LoadLocalAssetBundle(url);
         if (ab != null)
         {
             CachedAssetBundle cab = new CachedAssetBundle(ab, bundleInfo, this);
             this.CachedAssetBundleDictionary[bundleInfo.AssetBundleName] = cab;
         }
         else
         {
             return;
         }
     }
     //加载依赖
     string[] dependencies = bundleInfo.DependenciesBundleNames;
     foreach (string fileName in dependencies)
     {
         LoadBundle(fileName);
     }
 }
Esempio n. 4
0
 public CachedObject(UObject source, CachedAssetBundle _parent)
 {
     this.parent = _parent;
     this.source = source;
 }