예제 #1
0
        /// <summary>
        /// 加载(异步).
        /// </summary>
        /// <param name="iPath">路径.</param>
        /// <param name="iLoadCompleted">加载完毕回调函数.</param>
        /// <param name="iRetryLoad">加载重试.</param>
        public static IEnumerator LoadAsync <T>(string iPath,
                                                System.Action <bool, string, AssetBundleType, T> iLoadCompleted,
                                                System.Func <string, System.Action <bool, string, AssetBundleType, T>, IEnumerator> iRetryLoad)
            where T : Object
        {
            var path = CheckPath(iPath);

            // 加载资源
            var res = Resources.LoadAsync <T>(path);

            yield return(res);

            var bundleType = AssetFileHelper.GetAssetTypeByFilePath(iPath);
            var obj        = res.asset as T;

            if (default(T) != obj)
            {
                iLoadCompleted?.Invoke(true, iPath, bundleType, obj);
            }
            else
            {
                if (null != iRetryLoad)
                {
                    yield return(iRetryLoad(iPath, iLoadCompleted));
                }
                else
                {
                    iLoadCompleted(false, iPath, bundleType, obj);
                }
            }
        }
예제 #2
0
        public static string CheckPath(string iPath)
        {
            var path = iPath;

            // Debug.Log(path);
            if (path.StartsWith(ResourcesPath))
            {
                path = path.Substring(AssetsPath.Length);
            }

            if (path.StartsWith(AssetsPath))
            {
                path = path.Substring(ResourcesPath.Length);
            }

            // 根据文件后缀名处理
            path = AssetFileHelper.RemoveFileSunffix(path);

            return(path);
        }