コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Mac の通知を表示するエディタ拡張の例

概要

brew install terminal-notifier

上記のコマンドで terminal-notifier をインストールしておく。

using System.Diagnostics;
using UnityEditor;

internal static class Example
{
    [MenuItem( "Tools/Example" )]
    private static void Run()
    {
        // `which terminal-notifier` コマンドで取得したパスを設定
        var fileName = "/opt/homebrew/bin/terminal-notifier";

        var title     = "ピカチュウ";
        var message   = "カイリュー";
        var arguments = $@"-title ""{title}"" -message ""{message}""";

        var startInfo = new ProcessStartInfo
        {
            FileName               = fileName,
            Arguments              = arguments,
            RedirectStandardOutput = true,
            RedirectStandardError  = true,
            UseShellExecute        = false,
            CreateNoWindow         = true
        };

        var process = new Process { StartInfo = startInfo };

        process.Start();
        process.WaitForExit();
    }
}