7 继承 BZShaderGUI 来扩展首尾的绘制

BZShaderGUI 提供了两个虚函数,便于用于继承并进行绘制的自定义。

protected virtual void DrawTop(MaterialEditor materialEditor, MaterialProperty[] props)
protected virtual void DrawBottom(MaterialEditor materialEditor, MaterialProperty[] props)

示例代码

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace BZTA
{
    public class CustomGUI : BZShaderGUI
    {
        protected override void DrawTop(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            var customProperty = FindProperty("_DrawOnTop", props);
            if (customProperty != null)
            {
                GUILayout.BeginVertical("box");
                materialEditor.ShaderProperty(customProperty,"This Property Draw On Top");
                GUILayout.Label("Some Custom Label or anything else");
                GUILayout.EndVertical();
            }
        }

        protected override void DrawBottom(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            var customProperty = FindProperty("_DrawOnBottom", props);
            if (customProperty != null)
            {
                GUILayout.BeginHorizontal("box");
                materialEditor.ShaderProperty(customProperty,"This Property Draw On Top");
                if(GUILayout.Button("CustomBtn"))
                {
                    Debug.Log("you clicked the CustomBtn");
                }
                GUILayout.EndHorizontal();
            }
        }
    }
}