Unityを複数起動したい事が多々あり、以前はターミナルでコマンドを打って起動していましたが、面倒になったのでFileメニューに項目を追加してそこから起動できるようにしてみました。
環境
- Unity2018.30f2
- MacBookPro Mojave v10.14.3
準備
まず最初にFileメニューに項目を追加する為に、Editorフォルダを作りそのフォルダ内にCustomMenuFile.csスクリプトを作成しました。

ファイルの中身はこちら
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using UnityEngine; using UnityEditor; using UnityEditorInternal; public static class CustomFileMenu { // Fileメニューの下に追加するには、File/をつける // ショートカットキーでも実行できるようにメニューの後ろに「&o」を追加 // (option+oで実行できます) [MenuItem("File/Open Unity &o")] public static void OpenUnity () { } } |
Fileメニューに追加されたものがこちら

実装
使用しているEditorのパスを取得する為に、InternalEditorUtility.GetEngineAssemblyPath関数を使って取得しています。実装はこんな感じに
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
using UnityEngine; using UnityEditor; using UnityEditorInternal; public static class CustomFileMenu { [MenuItem("File/Open Unity &o")] public static void OpenUnity () { // プロジェクトフォルダを選択 string projectPath = EditorUtility.OpenFolderPanel( "フォルダを選択して下さい", Application.dataPath+"/../", "FolderName" ); if ( string.IsNullOrEmpty( projectPath ) ) { return; } // 開いているUnityエディタのパスを取得する string editorPath = GetUnityEditorPath(); if ( string.IsNullOrEmpty( editorPath ) ) { return; } // processを使ってコマンド起動させる var process = new System.Diagnostics.Process(); process.StartInfo.FileName = editorPath; process.StartInfo.Arguments = "-projectPath " + projectPath; process.Start(); } private static string GetUnityEditorPath () { string path = string.Empty; string assemblypath = InternalEditorUtility.GetEngineAssemblyPath(); switch ( Application.platform ) { case RuntimePlatform.OSXEditor: { int index = assemblypath.IndexOf( "Frameworks" ); if ( 0 > index ) { index = assemblypath.IndexOf( "Managed" ); if ( 0 > index ) { break; } } path = assemblypath.Substring( 0, index ) + "MacOS/Unity"; } break; case RuntimePlatform.WindowsEditor: { path = EditorApplication.applicationPath; } break; default: break; } return path; } } |
まとめ
メニュー追加も簡単にでき、複数起動もショートカットキーで簡単に立ち上げれるようになってとても便利になりました。普段よく使う機能をメニュー項目に追加するだけで作業効率が上がっていいですね!