unity脚本上挂载材质球,让材质球属性显示出来

image.png

image.png
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;

[CustomEditor(typeof(DynamicCookie))]
public class DynamicCookieEditor : Editor
{
    private MaterialEditor m_MaterialEditor;
    DynamicCookie dynamicCookie;
    Material[] materials;

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        if (dynamicCookie == null)
        {
            dynamicCookie = target as DynamicCookie;
        }
        if (dynamicCookie.m_CookieMaterial != null)
        {
            materials = new Material[] { dynamicCookie.m_CookieMaterial };
            m_MaterialEditor = (MaterialEditor)CreateEditor(materials);
            // 绘制MaterialEditor的GUI
            m_MaterialEditor.DrawHeader();
            m_MaterialEditor.OnInspectorGUI();
        }    
        else
        {
            DestroyImmediate(m_MaterialEditor);
            m_MaterialEditor = null;
        }
    }
}

你可能感兴趣的:(unity脚本上挂载材质球,让材质球属性显示出来)