目次
「OnInspectorGUI」属性
「OnInspectorGUI」属性を使用すると
GUI を拡張することができます
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