On Inspector GUIAttribute:可用于任何屬性烙肺,只要檢查器代碼正在運行饮焦,它將調用指定的函數(shù)眼虱。使用它為對象創(chuàng)建自定義檢查器GUI马胧。
using Sirenix.OdinInspector;
using Sirenix.Utilities.Editor;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnInspectorGUIAttributeExample : MonoBehaviour
{
[OnInspectorGUI("DrawPreview", append: true)]
public Texture2D Texture;
private void DrawPreview()
{
if (this.Texture == null) return;
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.Label(this.Texture);
GUILayout.EndVertical();
}
[OnInspectorGUI]
private void OnInspectorGUI()
{
UnityEditor.EditorGUILayout.HelpBox("OnInspectorGUI還可以用于方法和屬性", UnityEditor.MessageType.Info);
}
}