/// <summary> /// 3.5的生成 /// </summary> /// <param name="name"></param> /// <param name="productName"></param> /// <param name="type"></param> /// <param name="lang"></param> /// <param name="manifestXMLPath"></param> /// <param name="bundleVersion"></param> /// <param name="version"></param> /// <param name="noBuildSceneName"></param> /// <returns></returns> public static PerPlatform c(string name, string productName, PluginUtils.PLATFORM_TYPE type, PluginUtils.LANG_TYPE lang, string manifestXMLPath, string bundleVersion, int version, string[] noBuildSceneName = null, BuildCopyAction[] copy2StreamAssets = null) { PerPlatform d = new PerPlatform(); d.语言 = lang; d.艺名 = name; d.产品名称 = productName; d.平台 = type; d.数字版本号 = version; d.版本号 = bundleVersion; d.ManifestXmlPath = manifestXMLPath; d.发布的场景名字 = noBuildSceneName; if (copy2StreamAssets != null) { for (int i = 0; i < copy2StreamAssets.Length; i++) { var o = AssetDatabase.LoadAssetAtPath(Application.dataPath + copy2StreamAssets[i].filePath, typeof(Object)) as Object; if (o != null) { copy2StreamAssets[i].文件 = o; } } d.制文件 = copy2StreamAssets; } return(d); }
/// <summary> /// 复制pllugin-x到对应的目录 /// </summary> /// <param name="enName"></param> /// <param name="d"></param> static private void CopyPlugin(string enName, PerPlatform d, string xml) { string chName = d.艺名; List <string> paths = new List <string>(); List <string> files = new List <string>(); files.Clear(); paths.Clear(); String pluginPath = "Assets/Plugins-" + enName + "/"; Recursive(pluginPath, ref files, ref paths); AssetDatabase.DeleteAsset("Assets/Plugins/Android"); AssetDatabase.CreateFolder("Assets/Plugins", "Android"); paths.Clear(); for (int i = 0; i < files.Count; i++) { string file = files[i]; string newpath = file.Replace("Plugins-" + enName, "Plugins/Android"); CreateFolder(newpath, ref paths); AssetDatabase.CopyAsset(file, newpath); } AssetDatabase.Refresh(); pluginPath = Application.dataPath + "/plugins/android/"; SaveFile(xml, pluginPath + "AndroidManifest.xml"); Debug.Log("操作完成,已切换为" + chName + "平台"); }
public static void GetPackName(PerPlatform d, out string packName, out string xml) { packName = null; xml = null; if (d.ManifestXml != null) { xml = d.ManifestXml.text; } else if (d.ManifestXmlPath != null) { string path = Application.dataPath + d.ManifestXmlPath; if ((string)d.ManifestXmlPath == "") { Debug.Log("请设置ManifestXmlPath,否则无法生成!"); return; } FileStream aFile = new FileStream(path, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(aFile, System.Text.Encoding.UTF8); xml = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(sr.ReadToEnd()));; } if (xml == null) { Debug.LogError("请设置" + d.艺名 + "的ManifestXml属性为目标XML:" + d.ManifestXml.text); return; } try { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); packName = doc.SelectSingleNode("manifest").Attributes["package"].Value.ToString(); } catch { Debug.LogError("manifest文件有误,无法取得包名,请使用文本编辑器打开xml修改编码为unicode并保存."); return; } }
void OnGUI() { if (platformDatas == null) { return; } if (sexyShow.firstTime) { sexyShow.GetSexy(); } sexyShow.Update(); if (sexyShow.errorString != null) { window.ShowNotification(new GUIContent(sexyShow.errorString)); sexyShow.errorString = null; } scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.MaxWidth(width), GUILayout.Width(width), GUILayout.Height(height), GUILayout.ExpandWidth(false)); GUILayout.Label("@By James Zhan 2015.5.13 如未编辑发包参数,请点击以下按钮设置。设置完后即可发包", style1); if (!building) { if (GUILayout.Button("编辑发布参数")) { AssetDatabase.OpenAsset(platformDatas.GetInstanceID()); } openBat1 = GUILayout.Toggle(openBat1, "是否WIFI运行(需要先连接到服务器)"); if (openBat1 != openBat) { openBat = openBat1; PlayerPrefs.SetInt("RUN_BAT", openBat1 ? 1 : 0); PlayerPrefs.Save(); } float btnWidth = 150; float max = Mathf.Floor(width / btnWidth); int i = 0; for (i = 0; i < platformDatas.平台列表.Length; i++) { if (i == 0 || (i % max) == 0) { GUILayout.BeginHorizontal(); } PerPlatform p = platformDatas.平台列表[i]; if (GUILayout.Button(platformDatas.平台列表[i].艺名, GUILayout.Width(btnWidth), GUILayout.Height(30))) { if (platformDatas.平台列表[i].ManifestXml == null || platformDatas.平台列表[i].ManifestXml.ToString() == "") { AssetDatabase.OpenAsset(platformDatas.GetInstanceID()); } else { cur = p; building = true; EditorApplication.delayCall += DoCurrentCreate; window.ShowNotification(new GUIContent("请骚等,正在生成....")); } } if (platformDatas.平台列表[i].ManifestXml == null || platformDatas.平台列表[i].ManifestXml.ToString() == "") { GUILayout.EndHorizontal(); EditorGUILayout.HelpBox("Hi, SX, you cant publish " + platformDatas.平台列表[i].艺名 + " if you dont assign a MANIFEST xml =.=!!!", MessageType.Error); GUILayout.BeginHorizontal(); } if ((i % max) + 1 == max) { GUILayout.EndHorizontal(); } } if ((i % max) != 0) { GUILayout.EndHorizontal(); } if (sexyTexture != null) { GUILayout.Label(sexyShow.nowState + "," + "还有" + sexyShow.GetCount() + "张图片...."); if (GUILayout.Button(sexyTexture)) { sexyShow.GetSexy(); } } else { GUILayout.Label(sexyShow.nowState); } } else { GUILayout.Label("生成中,喝杯茶/咖啡?", style1); GUILayout.Space(10); if (GUILayout.Button("返回", GUILayout.Height(80))) { building = false; } } GUILayout.Space(10); GUILayout.EndScrollView(); }
public static void DoStuffs(PerPlatform d, string apkName, bool openBat = false) { PLATFORM_TYPE type = d.平台; if (type == PLATFORM_TYPE.None) { Debug.Log("发布平台未定义!"); return; } string packName = null; string xml = null; GetPackName(d, out packName, out xml); if (packName == null || xml == null) { return; } PlayerSettings.Android.bundleVersionCode = d.数字版本号; PlayerSettings.applicationIdentifier = packName; PlayerSettings.bundleVersion = d.版本号; PlayerSettings.productName = d.产品名称; PlayerSettings.companyName = "ZHJiaShiJie"; CreateVersion(d, packName); CopyPlugin(type.ToString().ToLower(), d, xml); if (apkName == "" || apkName == null) { apkName = packName + "_" + d.艺名; } else { apkName = apkName + "_" + d.艺名; } string[] nobuildSceneName = null; if (d.发布的场景名 != null && d.发布的场景名.Length > 0) { nobuildSceneName = new string[d.发布的场景名.Length]; for (int i = 0; i < d.发布的场景名.Length; i++) { if (d.发布的场景名[i] == null) { continue; } nobuildSceneName[i] = d.发布的场景名[i].name; } } else if (d.发布的场景名字 != null) { nobuildSceneName = d.发布的场景名字; } #if UNITY_4_5 || UNITY_4_2 SetScriptingDefine(d.平台); #endif Copy2StreamingAsset(d.制文件); BuildForAndroid(apkName, GetBuildScenes(nobuildSceneName), !openBat); CreateBat(apkName, packName, openBat); Copy2StreamingAsset(d.制文件, false); }
static public void CreateVersion(PerPlatform per, string packName) { PLATFORM_TYPE type = per.平台; LANG_TYPE curLang = per.语言; string gameName = per.产品名称; string v = "using System.Collections.Generic;\r\npublic class Version{ \r\n"; foreach (PLATFORM_TYPE item in Enum.GetValues(typeof(PLATFORM_TYPE))) { v += "static public bool Is" + item.ToString() + "(){ return " + (type == item ? "true" : "false") + "; }\r\n"; } foreach (LANG_TYPE item in Enum.GetValues(typeof(LANG_TYPE))) { v += "static public bool Is" + item.ToString() + "(){ return " + (curLang == item ? "true" : "false") + "; }\r\n"; } v += "public const bool SHOW_BUY_TIPS = " + (per.是否显示购买图 ? "true" : "false") + ";\r\n"; v += "public const string packName = \"" + packName + "\";\r\n"; v += "public const string gameName=\"" + gameName + "\";\r\n"; v += "public enum PLAFTFORM_ENUM{"; PerPlatform[] platforms = null; #if UNITY_3_5 platforms = GameInfo.data.平台列表; #else if (platformDatas == null) { platformDatas = AssetDatabase.LoadAssetAtPath(ASSETS_PATH, typeof(PlatformData)) as PlatformData; } platforms = platformDatas.平台列表; #endif for (int i = 0; i < platforms.Length; i++) { v += platforms[i].艺名.ToString(); if (i != (platforms.Length - 1)) { v += ","; } } v += "};\r\n"; v += "public static PLAFTFORM_ENUM currentPlatform= PLAFTFORM_ENUM." + per.艺名.ToString() + ";\r\n"; v += "public static Dictionary<string, string> customData = new Dictionary<string, string>(){"; Dictionary <string, string> customData = new Dictionary <string, string>(); if (per.自定义数据 != null) { for (int i = 0; i < per.自定义数据.Count; i++) { if (String.IsNullOrEmpty(per.自定义数据[i].name) == false) { if (customData.ContainsKey(per.自定义数据[i].name) == false) { try { customData.Add(per.自定义数据[i].name, per.自定义数据[i].value); v += "{\"" + per.自定义数据[i].name + "\",\"" + per.自定义数据[i].value + "\"}"; } catch { Debug.LogWarning("自定义数据" + per.自定义数据[i].name + ", " + per.自定义数据[i].value + " 创建失败,请注意不能使用特殊符号"); } } else { Debug.LogWarning("自定义数据" + per.自定义数据[i].name + " 重复的KEY"); } } } } v += "};"; v += "}"; SaveFile(v, Application.dataPath + "/plugins/Version.cs"); //save for cs. v = "#pragma strict \r\n"; foreach (PLATFORM_TYPE item in Enum.GetValues(typeof(PLATFORM_TYPE))) { v += "static public function Is" + item.ToString() + "(){ return " + (type == item ? "true" : "false") + "; }\r\n"; } foreach (LANG_TYPE item in Enum.GetValues(typeof(LANG_TYPE))) { v += "static public function Is" + item.ToString() + "(){ return " + (curLang == item ? "true" : "false") + "; }\r\n"; } v += "static public var packName:String = \"" + packName + "\";\r\n"; v += "public static var SHOW_BUY_TIPS:boolean = " + (per.是否显示购买图 ? "true" : "false") + ";\r\n"; v += "static public var gameName:String=\"" + gameName + "\";\r\n"; v += "public enum PLAFTFORM_ENUM{"; for (int i = 0; i < platforms.Length; i++) { v += platforms[i].艺名.ToString(); if (i != (platforms.Length - 1)) { v += ","; } } v += "};\r\n"; v += "public static var currentPlatform:PLAFTFORM_ENUM= PLAFTFORM_ENUM." + per.艺名.ToString() + ";\r\n"; SaveFile(v, Application.dataPath + "/plugins/VersionJS.js"); }