void DeleteProject() { BuildTools.DeleteProject(project); InitProjects(); add = false; project = null; selected = projects.Count - 1; }
private static bool SaveConfig(ProjectBuildData data, bool encrypt) { try { string path = Application.streamingAssetsPath + "/" + GameHelper.GetBuildTargetName(data.Target) + "/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileName = path + GlobalConst.Res.AppConfigFileName; string text = LitJson.JsonMapper.ToJson(data.Options); if (File.Exists(fileName)) { File.Delete(fileName); } //* // if (encrypt) // { // text = DESEncryption.Encrypt(text, GlobalConst.Res.EncryptPassword); // } File.WriteAllText(fileName, text); fileName = path + GlobalConst.Res.GameConfigFileName; if (data.Games.Count > 0) { var ids = new List <int>(); foreach (var game in data.Games) { ids.Add(game.Key); } var games = GameWindow.ScanGames(data.Target, ids); foreach (var game in data.Games) { var item = games.Find((config) => config.ID == game.Key); item.Packed = game.Value; } text = LitJson.JsonMapper.ToJson(games); } if (File.Exists(fileName)) { File.Delete(fileName); } File.WriteAllText(fileName, text); } catch (Exception ex) { Debug.LogException(ex); return(false); } return(true); }
public static ProjectBuildData CreateProject() { ProjectBuildData data = new ProjectBuildData(); data.Options = new GameOptions(); data.Name = ""; data.Target = EditorUserBuildSettings.activeBuildTarget; data.Scenes = new List <string>(); data.Settings = new Dictionary <string, string>(); data.Games = new Dictionary <int, bool>(); return(data); }
public static void PreformBuild() { string commandLine = Environment.CommandLine; string[] commandLineArgs = Environment.GetCommandLineArgs(); ProjectBuildData buildData = new ProjectBuildData(); for (int i = 0; i < commandLineArgs.Length; ++i) { if (commandLineArgs[i].Contains("=")) { string[] argument = commandLineArgs[i].Split('='); string argumentName = argument[0]; string argumentValue = argument[1]; if (argumentName.Contains("version")) { buildData.IdentityVersion = argumentValue; } if (argumentName.Contains("build")) { buildData.IdentityBuild = argumentValue; } if (argumentName.Contains("channel")) { buildData.Channel = PackageChannelStrToEnum(argumentValue); } if (argumentName.Contains("architecture")) { buildData.Architecture = ArchitectureStrToEnum(argumentValue); } if (argumentName.Contains("scripting_implementation")) { buildData.ScriptingImpl = ScriptingImplementationStrToEnum(argumentValue); } } } if (buildData.Integrity()) { ProjectBuilder.BuildForiOS(buildData); } }
private void SelectChanged(int index) { add = false; selected = index; if (projects != null && index != -1 && projects.Count > index) { project = projects[index]; if (project.Games == null) { project.Games = new Dictionary <int, bool>(); } games = GameWindow.ScanGames(project.Target); games.Sort((x, y) => { return(x.ID - y.ID); }); } if (gameWindow != null) { gameWindow.EndWindows(); } }
/// <summary> /// 拷贝自定义文件 /// </summary> /// <returns></returns> private static bool CopyCustomAssets(ProjectBuildData data) { try { var srcDirs = new[] { "Streaming", "Audio", "Res" }; var destDirs = new[] { "StreamingAssets", "Audio", "Resources" }; for (int i = 0; i < srcDirs.Length; i++) { string srcDir = srcDirs[i]; string destDir = destDirs[i]; string src = Application.dataPath + "/Projects/" + PlayerSettings.companyName + "/" + srcDir; string defaultSrc = Application.dataPath + "/Projects/default/" + srcDir; string dest = Application.dataPath + "/" + destDir; Debug.Log("copy file from:" + src + " to:" + dest); if (!Directory.Exists(src)) { src = defaultSrc; if (!Directory.Exists(src)) { Debug.Log(src + " dir is not exists"); continue; } } CFile.CopyDirectory(src, dest); } AssetDatabase.Refresh(); } catch (Exception ex) { Debug.LogException(ex); return(false); } return(true); }
public static void DeleteProject(ProjectBuildData data) { DataRow drProject = null; DataTable dt = LoadAndCreateProjects(PROJECTS_CONFIG_FILE); foreach (DataRow dr in dt.Rows) { string name = dr["ProjectName"].ToString(); if (name == data.Name) { drProject = dr; break; } } if (drProject == null) { return; } dt.Rows.Remove(drProject); SaveToDB(dt, PROJECTS_CONFIG_FILE); }
public static bool SaveProject(bool add, ProjectBuildData data) { DataRow drProject = null; DataTable dt = LoadAndCreateProjects(PROJECTS_CONFIG_FILE); foreach (DataRow dr in dt.Rows) { string name = dr["ProjectName"].ToString(); if (name == data.Name) { drProject = dr; break; } } if (add && drProject != null) { Debug.LogError("exist same project name already " + data.Name); return(false); } else if (!add && drProject == null) { Debug.LogError("project not exist " + data.Name); return(false); } else if (add) { drProject = dt.NewRow(); dt.Rows.Add(drProject); } drProject["ProjectName"] = data.Name; drProject["Version"] = data.Version; List <string> sceneList = new List <string>(); foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { if (!scene.enabled) { continue; } sceneList.Add(scene.path); } string scenes = string.Join(";", sceneList.ToArray()); drProject["Scenes"] = scenes; drProject["Target"] = EditorUserBuildSettings.activeBuildTarget; drProject["SymbolDefine"] = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); drProject["DebugBuild"] = EditorUserBuildSettings.development.ToString(); FieldInfo[] optionFields = typeof(GameOptions).GetFields(); foreach (var field in optionFields) { if (!field.IsPublic || field.IsStatic) { continue; } if (!dt.Columns.Contains(field.Name)) { dt.Columns.Add(field.Name); } var obj = field.GetValue(data.Options); if (obj != null) { if (field.FieldType == typeof(string) || field.FieldType == typeof(bool) || field.FieldType == typeof(int) || field.FieldType.IsEnum) { drProject[field.Name] = obj.ToString(); } else if (field.FieldType.IsGenericType) { drProject[field.Name] = LitJson.JsonMapper.ToJson(obj); } } } PropertyInfo[] fields = typeof(PlayerSettings).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var field in fields) { if (!field.CanWrite) { continue; } var obj = field.GetValue(null, null); if (obj != null) { drProject[field.Name] = obj.ToString(); if (field.PropertyType == typeof(Texture2D)) { var texture = obj as Texture2D; drProject[field.Name] = texture.name; } } } var types = typeof(PlayerSettings).GetNestedTypes(); foreach (var type in types) { var sb = new StringBuilder(); var writer = new LitJson.JsonWriter(sb); writer.WriteObjectStart(); var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var property in properties) { if (!property.CanWrite) { continue; } writer.WritePropertyName(property.Name); var obj = property.GetValue(null, null); writer.Write(obj != null ? obj.ToString() : ""); } writer.WriteObjectEnd(); if (!drProject.Table.Columns.Contains(type.Name)) { drProject.Table.Columns.Add(type.Name); } drProject[type.Name] = sb.ToString(); } var iconList = new List <string>(); var group = GetBuildGroupByTarget(data.Target); var icons = PlayerSettings.GetIconsForTargetGroup(group); foreach (var texture2D in icons) { if (texture2D != null) { var path = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); iconList.Add(path); } } var iconsStr = string.Join(",", iconList.ToArray()); drProject["Icons"] = iconsStr; if (data.Games != null) { var str = LitJson.JsonMapper.ToJson(data.Games); drProject["Games"] = str; } SaveToDB(dt, PROJECTS_CONFIG_FILE); //SaveConfig(data); return(true); }
public static List <ProjectBuildData> LoadProjectList() { /* try * {*/ DataTable dt = LoadAndCreateProjects(PROJECTS_CONFIG_FILE); List <ProjectBuildData> projects = new List <ProjectBuildData>(); PropertyInfo[] settingsFields = typeof(PlayerSettings).GetProperties(BindingFlags.Public | BindingFlags.Static); FieldInfo[] optionFields = typeof(GameOptions).GetFields(); foreach (DataRow dr in dt.Rows) { ProjectBuildData data = new ProjectBuildData(); data.Name = dr["ProjectName"].ToString(); data.Target = (BuildTarget)Enum.Parse(typeof(BuildTarget), dr["Target"].ToString()); data.Scenes = new List <string>(dr["Scenes"].ToString().Split(';')); data.Version = dr["Version"].ToString(); data.SymbolDefine = dr["SymbolDefine"].ToString(); data.DebugBuild = bool.Parse(dr["DebugBuild"].ToString()); data.Options = new GameOptions(); foreach (var field in optionFields) { if (!field.IsPublic || field.IsStatic || !dt.Columns.Contains(field.Name)) { continue; } if (field.FieldType == typeof(string)) { field.SetValue(data.Options, dr[field.Name].ToString()); } else if (field.FieldType == typeof(bool)) { bool value = false; if (bool.TryParse(dr[field.Name].ToString(), out value)) { field.SetValue(data.Options, value); } } else if (field.FieldType == typeof(int)) { field.SetValue(data.Options, int.Parse(dr[field.Name].ToString())); } else if (field.FieldType.IsEnum) { field.SetValue(data.Options, Enum.Parse(field.FieldType, dr[field.Name].ToString())); } else if (field.FieldType.IsGenericType) { var json = dr[field.Name].ToString(); var type = typeof(LitJson.JsonMapper); MethodInfo method = null; var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static); foreach (var methodInfo in methods) { var paramters = methodInfo.GetParameters(); if (methodInfo.Name == "ToObject" && methodInfo.IsGenericMethod && paramters[0].ParameterType == typeof(string)) { method = methodInfo; break; } } method = method.MakeGenericMethod(new Type[] { field.FieldType }); var obj = method.Invoke(null, new object[] { json }); field.SetValue(data.Options, obj); } } data.Settings = new Dictionary <string, string>(); foreach (var field in settingsFields) { if (field.CanWrite) { data.Settings.Add(field.Name, dr[field.Name].ToString()); } } var types = typeof(PlayerSettings).GetNestedTypes(); foreach (var type in types) { if (!dr.Table.Columns.Contains(type.Name)) { continue; } data.Settings[type.Name] = dr[type.Name].ToString(); /*var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static); * foreach (var property in properties) * { * Debug.Log("property:" + property.Name + " type:" + type.Name); * * }*/ } try { string str = dr["Games"].ToString(); if (!string.IsNullOrEmpty(str)) { var games = LitJson.JsonMapper.ToObject <Dictionary <string, bool> >(str); data.Games = new Dictionary <int, bool>(); foreach (var g in games) { data.Games.Add(int.Parse(g.Key), g.Value); } } str = dr["Icons"].ToString(); if (!string.IsNullOrEmpty(str)) { data.Settings["Icons"] = str; } } catch (Exception ex) { //Debug.LogException(ex); } projects.Add(data); } /* } * catch (System.Exception ex) * { * Debug.LogError(ex.Message); * return null; * }*/ return(projects); }
/*private static bool BuildAssetBundle(ProjectBuildData data) * { * try * { * string path = ABTools.outputPath + GetBuildTargetName(data.Target) + "/"; * if (!Directory.Exists(path)) * { * Directory.CreateDirectory(path); * } * * var abList = new List<AssetBundleInfo>(); * string fileName = path + GlobalConst.Res.ResVersionFileName; * if (File.Exists(fileName)) * { * string text = File.ReadAllText(fileName); * abList = LitJson.JsonMapper.ToObject<List<AssetBundleInfo>>(text); * } * * if (!BuildAssetBundle(path, data.Target, data.Games, ref abList)) * { * return false; * } * * string configFileName = path + GlobalConst.Res.ResVersionFileName; * string configText = LitJson.JsonMapper.ToJson(abList); * if (File.Exists(configFileName)) * { * File.Delete(configFileName); * } * File.WriteAllText(configFileName, configText); * } * catch (Exception e) * { * Debug.LogException(e); * return false; * } * * return true; * }*/ private static bool CopyAssetbundles(ProjectBuildData data) { try { string path = ABTools.outputPath + GameHelper.GetBuildTargetName(data.Target); string destPath = Application.streamingAssetsPath + "/" + GameHelper.GetBuildTargetName(data.Target); Debug.Log("copy ab from:" + path + " to:" + destPath); if (Directory.Exists(TEMP_PATH)) { Directory.Delete(TEMP_PATH, true); } if (Directory.Exists(Application.streamingAssetsPath)) { Debug.Log("move directory from:" + Application.streamingAssetsPath + " to:" + TEMP_PATH); Directory.Move(Application.streamingAssetsPath, TEMP_PATH); } if (!Directory.Exists(destPath)) { Debug.Log("create dir:" + destPath); Directory.CreateDirectory(destPath); } if (!Directory.Exists(path)) { Debug.LogError("src dir is not exists"); return(true); } string[] files = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); foreach (var file in files) { string fileName = new FileInfo(file).Name; string dest = destPath + "/" + fileName; Debug.Log("copy file:" + file + " to:" + dest); File.Copy(file, dest, true); } string srcDir = path + "/games"; if (!Directory.Exists(srcDir)) { Directory.CreateDirectory(srcDir); } /*string destDir = destPath + "/games"; * if (!Directory.Exists(destDir)) * { * Directory.CreateDirectory(destDir); * }*/ if (data.Games != null && data.Games.Count > 0) { var ids = new List <int>(); foreach (var game in data.Games) { ids.Add(game.Key); } var games = GameWindow.ScanGames(data.Target, ids); foreach (var item in games) { if (data.Games[item.ID]) { /* string srcGamesPath = srcDir + "/" + item.SceneName; * if (!Directory.Exists(srcGamesPath)) * { * Debug.LogError("src game dir is not exists! Dir:" + srcGamesPath); * return true; * } * * string destGamesPath = destDir + "/" + item.SceneName; * if (!Directory.Exists(destGamesPath)) * { * Directory.CreateDirectory(destGamesPath); * }*/ Debug.Log("ready copy pack game. Name:" + item.ID); foreach (var assetBundle in item.AssetBundles) { string file = path + "/" + assetBundle; if (!File.Exists(file)) { Debug.LogError("game file is not exists:" + file); return(false); } string destFile = destPath + "/" + assetBundle; Debug.Log(destFile); string destFilePath = Path.GetDirectoryName(destFile); if (!Directory.Exists(destFilePath)) { Directory.CreateDirectory(destFilePath); } Debug.Log("copy game file:" + file + " to:" + destFile); File.Copy(file, destFile); } } } } return(true); } catch (Exception e) { Debug.LogException(e); return(false); } }
public static void ApplyPlayerSettings(ProjectBuildData data) { Type type = typeof(PlayerSettings); var types = typeof(PlayerSettings).GetNestedTypes(); foreach (var nested in types) { if (!data.Settings.ContainsKey(nested.Name)) { continue; } string val = data.Settings[nested.Name]; var reader = new LitJson.JsonReader(val); while (reader.Read()) { switch (reader.Token) { case LitJson.JsonToken.PropertyName: { string key = reader.Value.ToString(); reader.Read(); var info = nested.GetProperty(key); if (info == null || !info.CanWrite) { Debug.LogWarning("ingore property:" + key); continue; } if (info.PropertyType == typeof(string)) { info.SetValue(null, reader.Value, null); } else if (info.PropertyType == typeof(bool)) { info.SetValue(null, bool.Parse(reader.Value.ToString()), null); } else if (info.PropertyType == typeof(int)) { info.SetValue(null, int.Parse(reader.Value.ToString()), null); } else if (info.PropertyType.IsEnum) { info.SetValue(null, Enum.Parse(info.PropertyType, reader.Value.ToString()), null); } else { Debug.LogWarning("unidentifiable property named:" + key + " type:" + info.PropertyType.Name); } break; } } } } foreach (var col in data.Settings) { PropertyInfo info = type.GetProperty(col.Key); if (info == null || !info.CanWrite) { Debug.LogWarning("ignore property:" + col.Key); continue; } Debug.LogWarning("set property:" + col.Key); if (info.PropertyType == typeof(string)) { info.SetValue(null, col.Value, null); } else if (info.PropertyType == typeof(bool)) { info.SetValue(null, bool.Parse(col.Value), null); } else if (info.PropertyType == typeof(int)) { info.SetValue(null, int.Parse(col.Value), null); } else if (info.PropertyType.IsEnum) { info.SetValue(null, Enum.Parse(info.PropertyType, col.Value), null); } else { Debug.LogWarning("unidentifiable field named:" + col.Key + " type:" + info.PropertyType.Name); } } if (data.Settings.ContainsKey("Icons")) { string icons = data.Settings["Icons"]; var iconsList = icons.Split(','); var iconsTextureList = new List <Texture2D>(); foreach (var str in iconsList) { var texture = AssetDatabase.LoadAssetAtPath <Texture2D>(str); iconsTextureList.Add(texture); } var group = GetBuildGroupByTarget(data.Target); var iconSizes = PlayerSettings.GetIconSizesForTargetGroup(group); if (iconSizes.Length > iconsTextureList.Count) { int count = iconSizes.Length - iconsTextureList.Count; for (int i = 0; i < count; i++) { iconsTextureList.Add(null); } } PlayerSettings.SetIconsForTargetGroup(group, iconsTextureList.ToArray()); } ApplySelectedScene(data.Scenes); if (data.DebugBuild) { EditorUserBuildSettings.development = data.DebugBuild; EditorUserBuildSettings.connectProfiler = true; EditorUserBuildSettings.allowDebugging = true; } else { EditorUserBuildSettings.development = false; EditorUserBuildSettings.connectProfiler = false; EditorUserBuildSettings.allowDebugging = false; } PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, data.SymbolDefine); PlayerSettings.bundleVersion = data.Version; AssetDatabase.Refresh(); }
public static bool BuildPlatform(ProjectBuildData data, bool compress, bool saveAs, bool encrypt, bool buildAsSetup) { Debug.Log(">------------------ start build : " + data.Name + " target:" + data.Target.ToString()); EditorUserBuildSettings.SwitchActiveBuildTarget(data.Target); string symDefine = data.SymbolDefine; if (!encrypt) { if (!symDefine.Contains("DISABLE_ENCRYPT_FILES")) { symDefine += ";DISABLE_ENCRYPT_FILES"; } } ApplyPlayerSettings(data); PlayerSettings.SetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup, symDefine ); AssetDatabase.Refresh(); //获取SDK目录 //string sdkDirPath = GetSDKDir(); //设置放置apk文件目录 BuildOptions options = BuildOptions.None; string dir = RELEASE_PATH + PlayerSettings.companyName + "/" + EditorUserBuildSettings.activeBuildTarget + "/"; if (saveAs) { dir = EditorUtility.OpenFolderPanel("Please select the target directory", dir, "") + "/"; } string fileName = ""; string destFileName = ""; string saveAsFileName = ""; bool compressNeeds = compress; //string apkPath = SettingAPKDir(); if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) { fileName = CFile.GetUnusedFileName(dir, PlayerSettings.companyName, ".apk"); fileName += "_V" + data.Version; if (!encrypt) { fileName += ".apk"; } destFileName += fileName; saveAsFileName = destFileName; } else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows) { if (compressNeeds || buildAsSetup) { saveAsFileName = PlayerSettings.companyName + "_V" + data.Version; fileName = CFile.GetUnusedFileName(dir, saveAsFileName, ".exe"); saveAsFileName = fileName; destFileName = PlayerSettings.companyName + ".exe"; dir += "__tmp/"; } else { fileName = CFile.GetUnusedFileName(dir, PlayerSettings.companyName, ".exe"); destFileName = fileName; destFileName += "_V" + data.Version + ".exe"; saveAsFileName = destFileName; } } else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) { if (compressNeeds) { dir += "__tmp/"; } destFileName += PlayerSettings.companyName; destFileName += "_" + data.Version; saveAsFileName = destFileName; } else { destFileName += PlayerSettings.companyName; saveAsFileName = destFileName; } Debug.Log("destFileName:" + destFileName); Debug.Log("saveAsFileName:" + saveAsFileName); /*//SDK转移 * if (!CopySDK(companyName, EditorUserBuildSettings.activeBuildTarget)) * { * Debug.LogError("CopySDK Error."); * return false; * }*/ //TODO 拷贝随包游戏 /*if (!CopyAssetbundles(data)) * { * Debug.LogError("Copy Assetbundles Error"); * return false; * }*/ //生成ab包 /*if (!BuildAssetBundle(data)) * { * return false; * }*/ //拷贝 //标题画面更改 if (!CopyLogo()) { return(false); } if (!CopyAssetbundles(data)) { return(false); } if (!CopyCustomAssets(data)) { return(false); } //保存配置文件 if (!SaveConfig(data, encrypt)) { return(false); } if (encrypt) { options |= BuildOptions.AcceptExternalModificationsToPlayer; } //保存配置文件 if (!BuildPlayer(dir, destFileName, options)) { return(false); } if (encrypt && !Encrypt(dir, destFileName)) { return(false); } //处理编译完成后问题 if (compressNeeds && !DoCompress(dir, destFileName, saveAsFileName)) { return(false); } if (buildAsSetup && !MakeSetup(dir, destFileName, saveAsFileName)) { return(false); } //处理编译完成后问题 if (!BuildEnd(dir)) { return(false); } PlayerSettings.SetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup, data.SymbolDefine ); AssetDatabase.Refresh(); Debug.Log(">------------------ Build finished! Name: " + data.Name + " Target: " + EditorUserBuildSettings.activeBuildTarget); return(true); }
void NewProject() { selected = -1; add = true; project = BuildTools.CreateProject(); }