/// <summary></summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="LoadInfo"></param>
        /// <param name="OnLoad"></param>
        /// <param name="OnFail"></param>
        /// <returns></returns>
        public T LoadAsset <T>(RecsLoadInfo LoadInfo, Action <object> OnLoad = null, Action <object> OnFail = null) where T : UnityEngine.Object
        {
            string strError = null;

            if (LoadInfo == null)
            {
                strError = "Null:加载信息为空";
            }

            if (LoadInfo.RecsFromType != RecsFromType.Recsources)
            {
                strError = "加载信息错误 不合适的加载方式";
            }

            if (string.IsNullOrEmpty(LoadInfo.strPath))
            {
                strError = "Null:path is null";
            }

            //路径类型检查
            if (LoadInfo.RecsPathType != RecsPathType.ResourcesPath)
            {
                LoadInfo.strPath = FileTool.ToRecsourcesPath(LoadInfo.strPath);
            }

            T recs = null;

            try
            {
                recs = Resources.Load <T>(LoadInfo.strPath);
            }
            catch (Exception ex)
            {
                if (OnFail != null)
                {
                    OnFail(ex.Message);
                    return(null);
                }
            }

            if (!string.IsNullOrEmpty(strError))
            {
                if (OnFail != null)
                {
                    OnFail(strError);
                }
            }
            else if (OnLoad != null)
            {
                OnLoad(recs);
            }

            return(recs);
        }
        /// <summary></summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="LoadInfo"></param>
        /// <param name="OnLoad"></param>
        /// <param name="OnFail"></param>
        /// <returns></returns>
        public T LoadAsset <T>(RecsLoadInfo LoadInfo, Action <object> OnLoad = null, Action <object> OnFail = null) where T : UnityEngine.Object
        {
            T asset = null;

            StartCoroutine(ILoadRecsFromBundlePath(LoadInfo, (o) =>
            {
                asset = o as T;
                if (OnLoad != null)
                {
                    OnLoad(o);
                }
            },
                                                   OnFail));

            return(asset);
        }
예제 #3
0
        /// <summary>加载指定的资源</summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="LoadInfo">加载信息</param>
        /// <param name="OnSuccess">加载成功的回调</param>
        /// <param name="OnFail">加载失败的回调</param>
        /// <returns></returns>
        public static T LoadRecs <T>(RecsLoadInfo LoadInfo, Action <object> OnSuccess = null, Action <object> OnFail = null) where T : UnityEngine.Object
        {
            switch (LoadInfo.RecsFromType)
            {
            case RecsFromType.UnKnown:
                break;

            case RecsFromType.Recsources:
                return(RecsourcesHelper.GetIns().LoadAsset <T>(LoadInfo, OnSuccess, OnFail));

            case RecsFromType.AssetBundle:
                return(AssetBundleHelper.GetIns().LoadAsset <T>(LoadInfo, OnSuccess, OnFail));

            case RecsFromType.File:
                break;

            default:
                break;
            }

            return(null);
        }
        IEnumerator ILoadRecsFromBundlePath(RecsLoadInfo LoadInfo, Action <object> OnLoad = null, Action <object> OnFail = null)
        {
            if (LoadInfo == null || LoadInfo.RecsFromType != RecsFromType.AssetBundle || string.IsNullOrEmpty(LoadInfo.strPath) /*|| !FileTool.FileExist(LoadInfo.strPath, LoadInfo.RecsPathType)*/)
            {
                if (OnFail != null)
                {
                    OnFail("资源不存在或路径错误");
                }
                yield break;
            }
            RecsLoadInfoAssetBundle rb = LoadInfo as RecsLoadInfoAssetBundle;


            yield return(StartCoroutine(ILoadAssetBundle <AssetBundle>(rb.strPath,
                                                                       (ab) =>
            {
                //Test
                Debug.Log(string.Format("加载AssetBundle[{0}]成功", ab.ToString()));
                if (ab != null && ab is AssetBundle)
                {
                    StartCoroutine(ILoadRecsFromBundle <Object>(ab as AssetBundle, rb.strRecsPath, rb.isAsync, OnLoad, OnFail));
                }
            }, OnFail)));
        }