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);
        }