private static string CreateMpcArgument(MessagePackConfig messagePackConfig, string csprojPath, string generatePath) { var processArgument = new StringBuilder(); processArgument.AppendFormat(" --input \"{0}\"", ReplacePathSeparator(csprojPath)); processArgument.AppendFormat(" --output \"{0}\"", ReplacePathSeparator(generatePath)); if (messagePackConfig.UseMapMode) { processArgument.Append(" --usemapmode"); } if (!string.IsNullOrEmpty(messagePackConfig.ResolverNameSpace)) { processArgument.AppendFormat(" --namespace {0}", messagePackConfig.ResolverNameSpace); } if (!string.IsNullOrEmpty(messagePackConfig.ResolverName)) { processArgument.AppendFormat(" --resolverName {0}", messagePackConfig.ResolverName); } if (!string.IsNullOrEmpty(messagePackConfig.ConditionalCompilerSymbols)) { processArgument.AppendFormat(" --conditionalSymbol {0}", messagePackConfig.ConditionalCompilerSymbols); } return(processArgument.ToString()); }
//----- property ----- //----- method ----- public override void OnInspectorGUI() { instance = target as MessagePackConfig; serializedObject.Update(); var winCompilerRelativePath = serializedObject.FindProperty("winCompilerRelativePath"); var osxCompilerRelativePath = serializedObject.FindProperty("osxCompilerRelativePath"); var scriptExportAssetDir = serializedObject.FindProperty("scriptExportAssetDir"); var scriptName = serializedObject.FindProperty("scriptName"); // Style. var pathTextStyle = GUI.skin.GetStyle("TextArea"); pathTextStyle.alignment = TextAnchor.MiddleLeft; GUILayout.Label("MessagePack compiler (Win)"); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(winCompilerRelativePath.stringValue, pathTextStyle); if (GUILayout.Button("Edit", GUILayout.Width(45f))) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); var path = EditorUtility.OpenFilePanel("Select MessagePack compiler", Application.dataPath, "exe"); winCompilerRelativePath.stringValue = UnityPathUtility.MakeRelativePath(path); serializedObject.ApplyModifiedProperties(); } } GUILayout.Label("MessagePack compiler (OSX)"); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(osxCompilerRelativePath.stringValue, pathTextStyle); if (GUILayout.Button("Edit", GUILayout.Width(45f))) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); var path = EditorUtility.OpenFilePanel("Select MessagePack compiler", Application.dataPath, ""); osxCompilerRelativePath.stringValue = UnityPathUtility.MakeRelativePath(path); serializedObject.ApplyModifiedProperties(); } } GUILayout.Label("MessagePack Script Export"); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(scriptExportAssetDir.stringValue, pathTextStyle); if (GUILayout.Button("Edit", GUILayout.Width(45f))) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); var path = EditorUtility.OpenFolderPanel("Select Export Folder", Application.dataPath, string.Empty); scriptExportAssetDir.stringValue = UnityPathUtility.MakeRelativePath(path); serializedObject.ApplyModifiedProperties(); } } EditorGUI.BeginChangeCheck(); GUILayout.Label("Export FileName"); scriptName.stringValue = EditorGUILayout.DelayedTextField(scriptName.stringValue); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); serializedObject.ApplyModifiedProperties(); } GUILayout.Space(25f); //------ Private settings ------ #if UNITY_EDITOR_OSX EditorLayoutTools.DrawLabelWithBackground("Private settings", new Color(1f, 1f, 0f, 1f)); using (new ContentsScope()) { EditorGUI.BeginChangeCheck(); GUILayout.Label("MsBuild Path"); MessagePackConfig.Prefs.msbuildPath = EditorGUILayout.DelayedTextField(MessagePackConfig.Prefs.msbuildPath); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); } } #endif }
public override void OnInspectorGUI() { instance = target as MessagePackConfig; Initialize(); if (findDotnet) { isLoading = true; findDotnet = false; Observable.FromMicroCoroutine(() => FindDotnet()).Subscribe(_ => isLoading = false); } serializedObject.Update(); var scriptExportAssetDir = serializedObject.FindProperty("scriptExportAssetDir"); var scriptName = serializedObject.FindProperty("scriptName"); var useMapMode = serializedObject.FindProperty("useMapMode"); var resolverNameSpace = serializedObject.FindProperty("resolverNameSpace"); var resolverName = serializedObject.FindProperty("resolverName"); var conditionalCompilerSymbols = serializedObject.FindProperty("conditionalCompilerSymbols"); var winMpcRelativePath = serializedObject.FindProperty("winMpcRelativePath"); var osxMpcRelativePath = serializedObject.FindProperty("osxMpcRelativePath"); if (isLoading) { return; } //------ .Netバージョン ------ if (string.IsNullOrEmpty(dotnetVersion)) { if (!isDotnetInstalled) { EditorGUILayout.HelpBox(".NET Core SDK not found.", MessageType.Error); #if UNITY_EDITOR_OSX EditorGUILayout.HelpBox("If installed and not found.\n\nTerminal run this command:\nln -s /usr/local/share/dotnet/dotnet /usr/local/bin/", MessageType.Info); #endif // インストールページ. if (GUILayout.Button("Open .NET Core install page.")) { Application.OpenURL("https://dotnet.microsoft.com/download"); } EditorGUILayout.Separator(); } } else { EditorGUILayout.HelpBox(string.Format(".NET Core SDK {0}(Require Version {1})", dotnetVersion, RequireDotnetSDKVersion), MessageType.Info); } //------ 基本設定 ------ EditorLayoutTools.ContentTitle("MessagePack Script Export"); using (new ContentsScope()) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(scriptExportAssetDir.stringValue, pathTextStyle); if (GUILayout.Button("Edit", GUILayout.Width(45f))) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); var path = EditorUtility.OpenFolderPanel("Select Export Folder", Application.dataPath, string.Empty); scriptExportAssetDir.stringValue = UnityPathUtility.MakeRelativePath(path); serializedObject.ApplyModifiedProperties(); } } EditorGUI.BeginChangeCheck(); GUILayout.Label("Export FileName"); scriptName.stringValue = EditorGUILayout.DelayedTextField(scriptName.stringValue); useMapMode.boolValue = EditorGUILayout.Toggle("MapMode", useMapMode.boolValue); } GUILayout.Space(4f); //------ オプション設定 ------ EditorLayoutTools.ContentTitle("CodeGenerator Options"); using (new ContentsScope()) { GUILayout.Label("NameSpace"); resolverNameSpace.stringValue = EditorGUILayout.DelayedTextField(resolverNameSpace.stringValue); GUILayout.Label("ClassName"); resolverName.stringValue = EditorGUILayout.DelayedTextField(resolverName.stringValue); GUILayout.Label("Conditional Compiler Symbols"); conditionalCompilerSymbols.stringValue = EditorGUILayout.DelayedTextField(conditionalCompilerSymbols.stringValue); } GUILayout.Space(4f); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); serializedObject.ApplyModifiedProperties(); } //------ CustomCodeGenerator ------ EditorLayoutTools.ContentTitle("CodeGenerator"); using (new ContentsScope()) { EditorGUILayout.HelpBox("When the mpc command is not used.\n the code generator is directly specified for generation.", MessageType.Info); GUILayout.Label("Windows"); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(winMpcRelativePath.stringValue, pathTextStyle); if (GUILayout.Button("Edit", GUILayout.Width(45f))) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); var path = EditorUtility.OpenFilePanel("Select MessagePack compiler", Application.dataPath, "exe"); if (!string.IsNullOrEmpty(path)) { winMpcRelativePath.stringValue = UnityPathUtility.MakeRelativePath(path); serializedObject.ApplyModifiedProperties(); } } if (GUILayout.Button("Clear", GUILayout.Width(45f))) { winMpcRelativePath.stringValue = string.Empty; serializedObject.ApplyModifiedProperties(); } } GUILayout.Label("MacOSX"); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(osxMpcRelativePath.stringValue, pathTextStyle); if (GUILayout.Button("Edit", GUILayout.Width(45f))) { UnityEditorUtility.RegisterUndo("MessagePackConfigInspector Undo", instance); var path = EditorUtility.OpenFilePanel("Select MessagePack compiler", Application.dataPath, ""); if (!string.IsNullOrEmpty(path)) { osxMpcRelativePath.stringValue = UnityPathUtility.MakeRelativePath(path); serializedObject.ApplyModifiedProperties(); } } if (GUILayout.Button("Clear", GUILayout.Width(45f))) { osxMpcRelativePath.stringValue = string.Empty; serializedObject.ApplyModifiedProperties(); } } } GUILayout.Space(4f); }
private static string GetScriptGeneratePath(MessagePackConfig messagePackConfig) { return(PathUtility.Combine(messagePackConfig.ScriptExportDir, messagePackConfig.ExportScriptName)); }
private static bool GenerateCode(MessagePackConfig messagePackConfig) { //------ Solution同期 ------ var unitySyncVS = Type.GetType("UnityEditor.SyncVS,UnityEditor"); var syncSolution = unitySyncVS.GetMethod("SyncSolution", BindingFlags.Public | BindingFlags.Static); syncSolution.Invoke(null, null); //------ csproj検索 ------ var csproj = string.Empty; var projectFolder = UnityPathUtility.GetProjectFolderPath(); var csprojNames = new string[] { "Assembly-CSharp", UnityPathUtility.GetProjectName() }; foreach (var csprojName in csprojNames) { var path = PathUtility.Combine(projectFolder, string.Format("{0}{1}", csprojName, CSProjExtension)); if (File.Exists(path)) { csproj = path; break; } } if (!File.Exists(csproj)) { throw new FileNotFoundException("csproj file not found"); } //------ mpc実行 ------ var compilerPath = messagePackConfig.CompilerPath; if (File.Exists(compilerPath)) { var generatePath = GetScriptGeneratePath(messagePackConfig); var arguments = string.Format(" --input {0} --output {1} --usemapmode", csproj, generatePath); #if UNITY_EDITOR_WIN // 実行. var result = ExecuteProcess(compilerPath, arguments); if (result.Item1 == 1) { throw new Exception(result.Item2); } #elif UNITY_EDITOR_OSX // msbuildへのパスを設定. var environmentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process); var path = string.Format("{0}:{1}", environmentPath, MessagePackConfig.Prefs.msbuildPath); Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process); // mpc権限変更. ExecuteProcess("/bin/bash", string.Format("-c 'chmod 755 {0}'", compilerPath)); // 実行. var result = ExecuteProcess(compilerPath, arguments); if (result.Item1 == 1) { throw new Exception(result.Item2); } #endif AssetDatabase.ImportAsset(generatePath, ImportAssetOptions.ForceUpdate); } else { throw new FileNotFoundException("MessagePack compiler not found."); } return(true); }