コガネブログ

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

【Unity】【Odin - Inspector and Serializer】変数ごとのコンテキストメニューに項目を追加する「CustomContextMenu」属性

目次

「CustomContextMenu」属性

「CustomContextMenu」属性を使用すると
変数を右クリックした時に表示されるコンテキストメニューに
項目を追加することができます

f:id:baba_s:20170721152003p:plain

using Sirenix.OdinInspector;
using UnityEngine;

public class Example : MonoBehaviour
{
    [CustomContextMenu( "Tools/Log", "Log" )]
    public int i;

    private void Log()
    {
        Debug.Log( "こんにちは!" );
    }
}

使い方

下記の様に記述するだけで使用できます
第 1 引数にコンテキストメニューに表示される名前を指定します
第 2 引数に呼び出される関数の名前を指定します

[CustomContextMenu( "Tools/Log", "Log" )]
public int i;

private void Log()
{
    Debug.Log( "こんにちは!" );
}

参考サイト様

Odin Inspector and Serializer | Improve your workflow in Unity