您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
76 行
2.9 KiB
76 行
2.9 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Experimental.Rendering;
|
|
using UnityEngine.Experimental.Rendering.HDPipeline;
|
|
using UnityEditor;
|
|
|
|
namespace UnityEditor.Experimental.Rendering.HDPipeline
|
|
{
|
|
[CustomEditor(typeof(DecalProjectorComponent))]
|
|
public class DecalProjectorComponentEditor : Editor
|
|
{
|
|
private MaterialEditor m_MaterialEditor = null;
|
|
private DecalProjectorComponent m_DecalProjectorComponent = null;
|
|
private SerializedProperty m_MaterialProperty;
|
|
private SerializedProperty m_DrawDistanceProperty;
|
|
private SerializedProperty m_FadeScaleProperty;
|
|
|
|
|
|
private void OnEnable()
|
|
{
|
|
// Create an instance of the MaterialEditor
|
|
m_DecalProjectorComponent = (DecalProjectorComponent)target;
|
|
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
|
|
m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
|
|
m_MaterialProperty = serializedObject.FindProperty("m_Material");
|
|
m_DrawDistanceProperty = serializedObject.FindProperty("m_DrawDistance");
|
|
m_FadeScaleProperty = serializedObject.FindProperty("m_FadeScale");
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
m_DecalProjectorComponent.OnMaterialChange -= OnMaterialChange;
|
|
}
|
|
|
|
public void OnMaterialChange()
|
|
{
|
|
// Update material editor with the new material
|
|
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
EditorGUI.BeginChangeCheck();
|
|
|
|
EditorGUILayout.PropertyField(m_MaterialProperty);
|
|
EditorGUILayout.PropertyField(m_DrawDistanceProperty);
|
|
EditorGUILayout.Slider(m_FadeScaleProperty, 0.0f, 1.0f, new GUIContent("Fade scale"));
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
|
|
if (m_MaterialEditor != null)
|
|
{
|
|
// Draw the material's foldout and the material shader field
|
|
// Required to call m_MaterialEditor.OnInspectorGUI ();
|
|
m_MaterialEditor.DrawHeader();
|
|
|
|
// We need to prevent the user to edit default decal materials
|
|
bool isDefaultMaterial = false;
|
|
var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
|
|
if (hdrp != null)
|
|
{
|
|
isDefaultMaterial = m_DecalProjectorComponent.Mat == hdrp.GetDefaultDecalMaterial();
|
|
}
|
|
using (new EditorGUI.DisabledGroupScope(isDefaultMaterial))
|
|
{
|
|
// Draw the material properties
|
|
// Works only if the foldout of m_MaterialEditor.DrawHeader () is open
|
|
m_MaterialEditor.OnInspectorGUI();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|