/// <summary> /// 判断给定的路径是否是个有效的扩展包(每个扩展组是一个独立的扩展包) /// </summary> /// <param name="package_path"></param> /// <returns></returns> public static bool IsValidExtensionPackage(string package_path) { if (!Directory.Exists(package_path)) { return(false); } //检查,扩展包的根目录下会有的几个东西 //FileHash string hash_path = Path.Combine(package_path, VFSConst.AssetBundleFilesHash_FileName); if (!File.Exists(hash_path)) { return(false); } //group_option if (!File.Exists(VFSUtil.Get_GroupOptions_InExtensionPackage(package_path))) { return(false); } //groupInfo if (!File.Exists(VFSUtil.GetExtensionGroup_GroupInfo_Path_InGroupPath(package_path))) { return(false); } //manifest if (!File.Exists(Path.Combine(package_path, VFSConst.AssetBundleManifestFileName))) { return(false); } return(true); }
/// <summary> /// 获取给定的根目录中(Packages root path),某个AssetBundle的位置 /// </summary> /// <param name="isExtensionGroup"></param> /// <param name="packages_root_path"></param> /// <param name="assetBundleName"></param> /// <param name="group_name"></param> /// <returns></returns> public static string GetAssetBundlePathFromPackages(bool isExtensionGroup, string packages_root_path, string assetBundleName, string group_name = null) { if (isExtensionGroup) { return(GetAssetBundlePathFromExtensionGroup_InExtensionPackagesRootFolder(GetExtensionPackageRootFolderInPackages(packages_root_path), group_name, assetBundleName)); } else { return(Path.Combine(VFSUtil.GetMainPackageFolderInPackages(packages_root_path), assetBundleName)); } }
/// <summary> /// 在给定的目录下,寻找有效可用的扩展组信息,返回组数组 /// </summary> /// <param name="extensions_root_path">存放扩展组的根目录,该方法只会搜寻它的直接子目录</param> /// <param name="main_package_version">如果提供Main Package版本信息,将只会返回满足扩展组对MainPackage最低版本限制的扩展组列表</param> /// <returns>组名 数组</returns> public static string[] GetValidExtensionGroupNames(string extensions_root_path, long?main_package_version = null) { if (!Directory.Exists(extensions_root_path)) { return(Array.Empty <string>()); } List <string> groups = new List <string>(); string[] folders = Directory.GetDirectories(extensions_root_path, "*", SearchOption.TopDirectoryOnly); foreach (var folder in folders) { if (VFSUtil.IsValidExtensionPackage(folder)) { //读取groupName try { string group_info_path = Path.Combine(folder, VFSConst.VFS_ExtensionGroupInfo_FileName); string group_info_json = File.ReadAllText(group_info_path); var group_info_obj = JsonUtility.FromJson <ExtensionGroupInfo>(group_info_json); if (main_package_version != null) { //判断版本 if (main_package_version.Value >= group_info_obj.MainPackageVersionLimit) { groups.Add(group_info_obj.GroupName); } } else { groups.Add(group_info_obj.GroupName); } } catch (Exception e) { Debug.LogError("[TinaX.VFS] Exception while load extension package info : " + folder + "\n" + e.Message); } } } return(groups.ToArray()); }
/// <summary> /// 在给定的根目录中,获取到某个扩展组的根目录 /// </summary> /// <param name="packages_root_path"></param> /// <param name="groupName"></param> /// <returns></returns> public static string GetExtensionGroupFolder(string packages_root_path, string groupName) { return(Path.Combine(VFSUtil.GetExtensionPackageRootFolderInPackages(packages_root_path), GetExtensionGroupFolderName(groupName))); }