Unityのエディタ拡張を使えば、シーンビューにボタンを配置することが出来ます。普段はWindowsで開発をしているので、Git Bashで実行するシェルスクリプトのボタンを置いてみました。
動作環境
OS: Windows 11 Home(21H2)
$ uname -a MINGW64_NT-10.0-22000 *************** 3.3.4-341.x86_64 2022-05-09 11:56 UTC x86_64 Msys $ bash --version GNU bash, version 4.4.23(1)-release (x86_64-pc-msys) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
シーンビューにボタンを配置する
ボタンを配置するスクリプトは下記サイト様を参考にさせていただきました。
shell-script1.sh、shell-script2.shは任意のシェルスクリプトですので別途任意のものをご用意ください。
using System; using System.Diagnostics; using UnityEditor; using UnityEngine; public class OriginalButtons { [InitializeOnLoadMethod] static void Init() { SceneView.onSceneGUIDelegate += OnGUI; } static void ExecuteSh(string fileName) { try { Process p = new Process(); // Git Bashの絶対パスを指定 p.StartInfo.FileName = @"C:\Program Files\Git\git-bash.exe"; // 実行するシェルスクリプトの絶対パスを指定 p.StartInfo.Arguments = Application.dataPath + $"/{fileName}"; p.Start(); p.WaitForExit(); p.Close(); } catch (Exception e){ UnityEngine.Debug.Log(e.Message); UnityEngine.Debug.Log(e.StackTrace); throw; } } static void OnGUI( SceneView sceneView ) { var rect = new Rect( 8, 24, 80, 0 ); GUI.WindowFunction func = id => { if (GUILayout.Button("execute script1")) { ExecuteSh("shell-script1.sh"); } else if (GUILayout.Button("execute script2")) { ExecuteSh("shell-script2.sh"); } }; GUILayout.Window(1, rect, func, string.Empty); } }
Git Bashの場合は、p.StartInfo.FileName
にexeファイルの絶対パスを指定する必要があるので注意です。
Application.dataPath
はUnity Editor上では、<path to project folder>/Assets
となります。
下記は私の実際のエディタ画面です。 AWS S3にAssetBundleをアップロードする処理をCUIから実行するのが面倒だったので、ボタン化してみました。
シェルスクリプトを叩けると、ChromeでWebページを開いたりCLIツールでデプロイを実行したりもできるのでかなり出来ることが広がるのでかなり便利です。