예제 #1
0
        /// <summary>
        /// 加载函数(单个:异步).
        /// </summary>
        /// <param name="iPath">路径.</param>
        /// <param name="iLoadCompleted">加载成功回调函数</param>
        public static IEnumerator LoadAsync <T>(string iPath,
                                                System.Action <bool, string, AssetBundleType, T> iLoadCompleted) where T : Object
        {
#if BUILD_DEBUG
            yield return(ResourcesLoad.LoadAsync <T>(
                             iPath, iLoadCompleted, RetryLoadAssetBundles <T>));
#else
            yield return(AssetBundlesManager.Instance.LoadFromAssetBundleAsync <T>(
                             iPath, iLoadCompleted, RetryLoadAssetBundles <T>));
#endif
            yield return(new WaitForEndOfFrame());
        }
예제 #2
0
        /// <summary>
        /// 加载重试.
        /// </summary>
        /// <param name="iPath">路径.</param>
        /// <param name="iLoadCompleted">加载成功回调函数.</param>
        private static IEnumerator RetryLoadAssetBundles <T>(
            string iPath,
            System.Action <bool, string, AssetBundleType, T> iLoadCompleted) where T : Object
        {
#if BUILD_DEBUG
            // 切换路径 Default -> Develop
            string _assetPath = Const.SwitchPathToDevelop(iPath);
            yield return(AssetBundlesManager.Instance.LoadFromAssetBundleAsync <T>(
                             _assetPath, iLoadCompleted, null));
#else
            // 切换路径 Develop -> Default
            var path = Const.SwitchPathToDefault(iPath);
            yield return(ResourcesLoad.LoadAsync <T>(path, iLoadCompleted, null));

            yield return(new WaitForEndOfFrame());
#endif
        }
예제 #3
0
        /// <summary>
        /// 加载函数(单个:同步).
        /// </summary>
        /// <returns>加载对象</returns>
        /// <param name="iPath">路径.</param>
        public static T Load <T>(string iPath)
            where T : UnityEngine.Object
        {
            if (string.IsNullOrEmpty(iPath))
            {
                return(default(T));
            }

            Object objRet;

#if BUILD_DEBUG
            objRet = ResourcesLoad.Load <T>(iPath);
            if (null != objRet)
            {
                return((T)objRet);
            }
#endif

            var fileName = AssetBundlesManager.GetKeyOfMapByFilePath(iPath, typeof(T));
            if (string.IsNullOrEmpty(fileName))
            {
                Loger.Error($"DataLoader::Load(T):File not exist in bundles maps!!(path:{iPath})");
                return(null);
            }

            objRet = AssetBundlesManager.Instance.LoadFromAssetBundle <T>(fileName);
            if (null != objRet)
            {
                return((T)objRet);
            }
            var path = ResourcesLoad.ToDefaultPath(iPath);
            objRet = ResourcesLoad.Load <T>(path);
            // if(null == objRet) {
            //     UtilsLog.Error("DataLoader",
            //         "Load(T):Failed!!(path:{0})", iPath);
            // }
            return((T)objRet);
        }