Odin-Inspector-系列教程—–OnInspectorGUIAttribute

On Inspector GUIAttribute:可用于任何属性,只要检查器代码正在运行,它将调用指定的函数。使用它为对象创建自定义检查器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);
    }
}

更多教程内容详见:革命性Unity 编辑器扩展工具 — Odin Inspector 系列教程

发表评论