Exemple #1
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <returns></returns>
        public static T Load <T>(string name, LoadPathType pathType = LoadPathType.RuntimePath) where T : UnityEngine.Object
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            return(ResLoader.Load <T>(name, pathType));
        }
Exemple #2
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <param name="assetLoadPath">资源路径</param>
        /// <param name="pathType">加载类型:路径名还是GUID</param>
        /// <param name="groupName">加载组,用以对资源加载分组</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Load <T>(string assetLoadPath, LoadPathType pathType = LoadPathType.RuntimePath, string groupName = null) where T : UnityEngine.Object
        {
            if (string.IsNullOrEmpty(assetLoadPath))
            {
                return(null);
            }

            //添加到资源组
            AddAssetsPathToGroup(groupName, assetLoadPath);
            //加载
            return(ResLoader.Load <T>(assetLoadPath, pathType));
        }
Exemple #3
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="pathType"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T Load <T>(string path, LoadPathType pathType = LoadPathType.RuntimePath) where T : UnityEngine.Object
        {
            //guid转短路径

            if (pathType == LoadPathType.GUID)
            {
                path = AssetDatabase.GUIDToAssetPath(path);
            }


            return(Load(typeof(T), path) as T);
        }
Exemple #4
0
        /// <summary>
        /// 同步加载
        /// 返回更安全的包装类型,防止接口滥用.
        /// 也更好进行资源管理
        /// </summary>
        /// <param name="assetPath">资源路径</param>
        /// <param name="pathType">加载类型:路径名还是GUID</param>
        /// <param name="groupName">加载组,用以对资源加载分组</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static GameObjectWrapper Load(string assetPath, LoadPathType pathType = LoadPathType.RuntimePath, string groupName = null)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                throw new Exception("路径错误!");
            }


            // //添加到资源组
            // AddAssetsPathToGroup(groupName, assetPath);
            // //加载
            // return ResLoader.Load<GameObject>(assetPath, pathType);
            return(new GameObjectWrapper(null));
        }
Exemple #5
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="pathType"></param>
        /// <param name="fullPath"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T Load <T>(string path, LoadPathType pathType = LoadPathType.RuntimePath) where T : UnityEngine.Object
        {
            //这里首次会耗时,主要是需要关联查询依赖文件
            if (pathType == LoadPathType.GUID)
            {
                var abi = AssetConfigLoder.GetAssetBundleDataByGUID(path);
                if (abi != null)
                {
                    path = abi.LoadPath;
                }
            }

            var obj = Load(typeof(T), path);

            if (obj)
            {
                return(obj as T);
            }

            return(null);
        }