protected void OnEnable() { string path = Application.dataPath + "/Editor/config.xml"; if (File.Exists(path) == false) { ShowNotification(new GUIContent(path + "不存在")); return; } XmlDocument doc = EditorConfigUtils.doc; XmlNode node = doc.SelectSingleNode("config/prefabExport"); XmlAttribute nodeAttribute = node.Attributes["to"]; if (nodeAttribute == null) { FileInfo fileInfo = new FileInfo(Application.dataPath); exportPrefabToPrefix = Path.Combine(fileInfo.Directory.FullName, "ReleaseResource/"); } else { bool has = false; string[] paths = nodeAttribute.InnerText.Split(','); foreach (string s in paths) { if (Directory.Exists(s)) { has = true; exportPrefabToPrefix = s; break; } else { string[] sections = s.Split('/'); if (sections.Length > 1 && sections[0] == "~") { string subfix = sections.As3Join("/", 1, sections.Length); FileInfo fileInfo = new FileInfo(Application.dataPath); string fullPath = Path.Combine(fileInfo.Directory.Parent.FullName, subfix); if (Directory.Exists(fullPath)) { has = true; exportPrefabToPrefix = fullPath; break; } } } } if (has == false) { FileInfo fileInfo = new FileInfo(Application.dataPath); exportPrefabToPrefix = Path.Combine(fileInfo.Directory.FullName, "ReleaseResource/"); } } XmlAttribute attribute = node.Attributes["hasSVN"]; hasSVN = true; if (attribute != null && attribute.InnerText == "0") { hasSVN = false; } rootFolderName = node.Attributes["zipName"].InnerText; if (node.Attributes["lz4"].InnerText == "1") { lz4Compress = true; } mapList.Clear(); foreach (XmlNode itemNode in node.ChildNodes) { ExportRootVO itemVo = new ExportRootVO(); string name = itemNode.Attributes["name"].InnerText; if (mapList.ContainsKey(name)) { continue; } itemVo.bindXML(itemNode); mapList.Add(name, itemVo); } selectedIndex = EditorPrefs.GetInt(EditorPrefs_Key); this.titleContent = new GUIContent("发布资源设置"); if (SystemInfo.operatingSystem.IndexOf("Mac") != -1) { buildTarget = BuildTarget.iOS; } else { buildTarget = EditorUserBuildSettings.activeBuildTarget; } if (hasSVN) { startSVNUpdates(buildTarget); } }
public static void BuildAssetbundle() { autoInit(); BuildTarget buildTarget = BuildTarget.Android; BuildTargetGroup targetGroup = BuildTargetGroup.Android; string[] args = Environment.GetCommandLineArgs(); //int len = args.Length; if (args.Length < 0) { return; } int index = Array.IndexOf(args, "-buildTarget"); if (index != -1) { string buildTargetKey = args[index + 1].ToLower(); Debug.Log("buildTarget:" + buildTargetKey); buildTarget = platfromDictionary[buildTargetKey]; targetGroup = platfromGroupDictionary[buildTargetKey]; } bool isForceRebuild = false; index = Array.IndexOf(args, "-isForceRebuild"); if (index != -1) { isForceRebuild = true; } bool lz4Compress = false; index = Array.IndexOf(args, "-lz4"); if (index != -1) { lz4Compress = true; } string exportPrefabToPrefix = ""; switchToPlatform(targetGroup, buildTarget); XmlDocument doc = EditorConfigUtils.doc; XmlNode node = doc.SelectSingleNode("config/prefabExport"); XmlAttribute nodeAttribute = node.Attributes["to"]; if (nodeAttribute == null) { FileInfo fileInfo = new FileInfo(Application.dataPath); exportPrefabToPrefix = Path.Combine(fileInfo.Directory.FullName, "ReleaseResource/"); } else { string[] paths = nodeAttribute.InnerText.Split(','); foreach (string s in paths) { if (Directory.Exists(s)) { exportPrefabToPrefix = s; break; } } } index = Array.IndexOf(args, "-exportTo"); if (index != -1) { string value = args[index + 1]; if (string.IsNullOrEmpty(value) == false) { exportPrefabToPrefix = value; } } Dictionary <string, ExportRootVO> mapList = new Dictionary <string, ExportRootVO>(); foreach (XmlNode itemNode in node.ChildNodes) { ExportRootVO itemVo = new ExportRootVO(); string name = itemNode.Attributes["name"].InnerText; if (mapList.ContainsKey(name)) { continue; } itemVo.bindXML(itemNode); mapList.Add(name, itemVo); } string rootFolderName = node.Attributes["zipName"].InnerText; PrefabExport prefabExport = new PrefabExport(buildTarget, exportPrefabToPrefix, rootFolderName); prefabExport.isForceRebuild = isForceRebuild; if (node.Attributes["lz4"].InnerText == "1" || lz4Compress) { prefabExport.lz4Compress = true; } prefabExport.exportAllPrefab(mapList.Values.ToList()); }