/// 解析Asset配置节点 bool ParseAsset(XmlNode node, BundlePackInfo packInfo) { // source path if (node.Attributes["SrcPath"] == null || string.IsNullOrEmpty(node.Attributes["SrcPath"].Value)) { JW.Common.Log.LogE("There is no SrcPath in Asset node."); return(false); } string srcPath = node.Attributes["SrcPath"].Value; string fullPath = JW.Res.FileUtil.CombinePaths(Application.dataPath, "Resources", srcPath); string[] files = null; try { if (File.Exists(fullPath)) { //单个文件 if (node.Attributes["pattern"] != null) { Regex regex = new Regex(node.Attributes["pattern"].Value, RegexOptions.IgnoreCase); if (regex.IsMatch(fullPath)) { files = new string[1]; files[0] = fullPath; } } else { files = new string[1]; files[0] = fullPath; } } else if (Directory.Exists(JW.Res.FileUtil.GetFullDirectory(fullPath))) { //目录 SearchOption option = SearchOption.TopDirectoryOnly; if (node.Attributes["recursive"] != null && node.Attributes["recursive"].Value.ToLower() == "true") { option = SearchOption.AllDirectories; } files = Directory.GetFiles(JW.Res.FileUtil.GetFullDirectory(fullPath), JW.Res.FileUtil.GetFullName(fullPath), option).Where(name => !name.EndsWith(".meta", true, null)).ToArray(); if (node.Attributes["pattern"] != null) { Regex regex = new Regex(node.Attributes["pattern"].Value, RegexOptions.IgnoreCase); files = files.Where(f => !string.IsNullOrEmpty(f) && regex.IsMatch(f)).ToArray(); } } } catch (System.Exception e) { JW.Common.Log.LogE(string.Format("ParseAsset(), path:{0}, exception:{1}", packInfo.Path, e.Message)); return(false); } // 创建资源信息 resource info for (int j = 0; files != null && j < files.Length; j++) { string filePathInResources = GetPathInResources(files[j]); string duplicatedFile = null; if (packInfo.IsDuplicated(filePathInResources, out duplicatedFile)) { JW.Common.Log.LogE(string.Format("Duplicated resource [{0}] and [{1}] in bundle [{2}]", filePathInResources, duplicatedFile, packInfo.Path)); return(false); } ResInfo ResInfo = new ResInfo(); if (packInfo.HasFlag(EBundleFlag.UnityScene)) { ResInfo.Path = Path.GetFileNameWithoutExtension(filePathInResources); } else { ResInfo.Path = JW.Res.FileUtil.EraseExtension(filePathInResources); } int artPos = filePathInResources.IndexOf("ArtWork"); if (artPos != -1) { ResInfo.Path = ResInfo.Path.Substring(artPos + "ArtWork/".Length); ResInfo.RelativePath = JW.Res.FileUtil.CombinePath("Assets", filePathInResources.Substring(artPos)); } else { ResInfo.RelativePath = JW.Res.FileUtil.CombinePath("Assets/Resources", filePathInResources); } //扩展名 ResInfo.Ext = JW.Res.FileUtil.GetExtension(filePathInResources); //是否保持 if (node.Attributes["keep"] != null && node.Attributes["keep"].Value.Equals("true", StringComparison.OrdinalIgnoreCase)) { ResInfo.Keep = true; } else { ResInfo.Keep = false; } packInfo.Add(ref ResInfo); } return(true); }