Exemple #1
0
        public override IEnumerator DoLoadAsync(Action <uint> finishCallback)
        {
            if (mResPath.IsNullOrEmpty())
            {
                AFLogger.e("加载路径不能为空");
                yield break;
            }
            mResState = ResState.Loading;
            uint      crc       = Crc32.GetCrc32(mResPath);
            ABResItem ABResitem = ResManager.Instance.LoadAssetBundle(crc);

            if (ABResitem.assetBundle == null)
            {
                AFLogger.e("加载的AssetBundle为空:" + ResPath);
                yield break;
            }
            resItem.Copy(ABResitem);
            if (isSprite)
            {
                ABRequest = ABResitem.assetBundle.LoadAssetAsync <Sprite>(ResPath);
            }
            else
            {
                ABRequest = ABResitem.assetBundle.LoadAssetAsync <Object>(ResPath);
            }
            yield return(ABRequest);

            if (!ABRequest.isDone)
            {
                AFLogger.e("Failed to Load Resources:" + mResPath);
                OnResLoadFaild();
                mListener.InvokeGracefully(false, this);
                finishCallback(mCRC);
                yield break;
            }

            mAsset    = ABRequest.asset;
            mResState = ResState.Ready;
            mListener.InvokeGracefully(true, this);
            finishCallback(mCRC);
        }
Exemple #2
0
        /// <summary>
        /// 加载AB包
        /// </summary>
        /// <param name="crc"></param>
        /// <returns></returns>
        public ABResItem LoadAssetBundle(uint crc)
        {
            ABResItem ABResitem = new ABResItem();
            ResItem   resItem   = null;

            if (!mResConfigItem.TryGetValue(crc, out resItem) || resItem == null)
            {
                AFLogger.e(string.Format("LoadResourceAssetBundle error: can not find crc {0} in AssetBundleConfig", crc.ToString()));
                return(null);
            }
            ABResitem.assetBundle = LoadAssetBundle(resItem.ABName);
            if (resItem.DependAssetBundle != null)
            {
                for (int i = 0; i < resItem.DependAssetBundle.Count; i++)
                {
                    LoadAssetBundle(resItem.DependAssetBundle[i]);
                }
            }
            ABResitem.mResItem = resItem;
            return(ABResitem);
        }
Exemple #3
0
        public override bool LoadSync()
        {
            if (mResPath.IsNullOrEmpty())
            {
                AFLogger.e("加载路径不能为空");
                return(false);
            }
            mResState = ResState.Loading;
            uint      crc       = Crc32.GetCrc32(mResPath);
            ABResItem ABResitem = ResManager.Instance.LoadAssetBundle(crc);

            if (ABResitem.assetBundle == null)
            {
                AFLogger.e("加载的AssetBundle为空:" + ResPath);
                return(false);
            }
            resItem.Copy(ABResitem);
            if (isSprite)
            {
                mAsset = ABResitem.assetBundle.LoadAsset <Sprite>(ResPath);
            }
            else
            {
                mAsset = ABResitem.assetBundle.LoadAsset <Object>(ResPath);
            }
            if (mAsset.IsNull())
            {
                AFLogger.e("加载AB包资源为null,请检查路径:" + mResPath);
                mResState = ResState.Waiting;
            }
            else
            {
                mResState = ResState.Ready;
            }
            return(mAsset != null);
        }
Exemple #4
0
 public void Copy(ABResItem ABResitem)
 {
     ABName            = ABResitem.mResItem.ABName;
     DependAssetBundle = ABResitem.mResItem.DependAssetBundle;
 }