以下の内容はhttps://baba-s.hatenablog.com/entry/2017/08/02/180000より取得しました。


【Unity】【Odin - Inspector and Serializer】GUI を拡張する「OnInspectorGUI」属性

目次

「OnInspectorGUI」属性

「OnInspectorGUI」属性を使用すると
GUI を拡張することができます

f:id:baba_s:20170721180616p:plain

using Sirenix.OdinInspector;
using UnityEngine;

public class Example : MonoBehaviour
{
    [OnInspectorGUI( "DrawLabel1" )]
    public int i1;
    
    [OnInspectorGUI( "DrawLabel2", false )]
    public int i2;

    private void DrawLabel1()
    {
        GUILayout.Label( "ヒトカゲ" );
    }

    private void DrawLabel2()
    {
        GUILayout.Label( "ゼニガメ" );
    }

    [OnInspectorGUI]
    private void DrawButton()
    {
        GUILayout.Button( "フシギダネ" );
    }
}

使い方

下記のように記述するだけで使用できます
引数には GUI を拡張する関数の名前を文字列で指定します

[OnInspectorGUI( "DrawLabel1" )]
public int i1;

変数やプロパティの上側で GUI を拡張したい場合は
第 2 引数に false を指定します

[OnInspectorGUI( "DrawLabel2", false )]
public int i2;

関数に対して OnInspectorGUI 属性を適用することも可能です

[OnInspectorGUI]
private void DrawButton()
{
    GUILayout.Button( "フシギダネ" );
}

参考サイト様

Odin Inspector and Serializer | Improve your workflow in Unity




以上の内容はhttps://baba-s.hatenablog.com/entry/2017/08/02/180000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14