浏览代码

Find serialized properties using an expression instead of a string (safer and won't break on refactor)

/main
Chman 8 年前
当前提交
f8c4dad7
共有 3 个文件被更改,包括 53 次插入15 次删除
  1. 21
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 11
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  3. 36
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs

21
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


using System;
using System.Linq.Expressions;
using UnityEditor;
//using EditorGUIUtility=UnityEditor.EditorGUIUtility;

}
}
const float k_MaxExposure = 32.0f;
SerializedProperty m_ShowDebug = null;
SerializedProperty m_ShowDebugShadow = null;
SerializedProperty m_DebugOverlayRatio = null;

private void InitializeProperties()
{
m_DebugOverlayRatio = serializedObject.FindProperty("m_GlobalDebugParameters.debugOverlayRatio");
m_ShowDebugShadow = serializedObject.FindProperty("m_GlobalDebugParameters.displayShadowDebug");
m_ShowDebug = serializedObject.FindProperty("m_GlobalDebugParameters.displayDebug");
m_DebugOverlayRatio = FindProperty(x => x.globalDebugParameters.debugOverlayRatio);
m_ShowDebugShadow = FindProperty(x => x.globalDebugParameters.displayShadowDebug);
m_ShowDebug = FindProperty(x => x.globalDebugParameters.displayDebug);
m_DebugShadowEnabled = serializedObject.FindProperty("m_GlobalDebugParameters.shadowDebugParameters.enableShadows");
m_DebugShadowVisualizationMode = serializedObject.FindProperty("m_GlobalDebugParameters.shadowDebugParameters.visualizationMode");
m_DebugShadowVisualizeShadowIndex = serializedObject.FindProperty("m_GlobalDebugParameters.shadowDebugParameters.visualizeShadowMapIndex");
m_DebugShadowEnabled = FindProperty(x => x.globalDebugParameters.shadowDebugParameters.enableShadows);
m_DebugShadowVisualizationMode = FindProperty(x => x.globalDebugParameters.shadowDebugParameters.visualizationMode);
m_DebugShadowVisualizeShadowIndex = FindProperty(x => x.globalDebugParameters.shadowDebugParameters.visualizeShadowMapIndex);
}
SerializedProperty FindProperty<TValue>(Expression<Func<HDRenderPipeline, TValue>> expr)
{
var path = Utilities.GetFieldPath(expr);
return serializedObject.FindProperty(path);
}
string GetSubNameSpaceName(Type type)

11
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


}
// Debugging
[SerializeField]
GlobalDebugParameters m_GlobalDebugParameters = new GlobalDebugParameters();
DebugParameters m_DebugParameters = new DebugParameters();
public GlobalDebugParameters globalDebugParameters = new GlobalDebugParameters();
DebugParameters m_DebugParameters = new DebugParameters();
public DebugParameters debugParameters
{

debugCB.name = "Debug Overlay";
float x = 0;
float overlayRatio = m_GlobalDebugParameters.debugOverlayRatio;
float overlayRatio = globalDebugParameters.debugOverlayRatio;
ShadowDebugParameters shadowDebug = m_GlobalDebugParameters.shadowDebugParameters;
ShadowDebugParameters shadowDebug = globalDebugParameters.shadowDebugParameters;
if (shadowDebug.visualizationMode != ShadowDebugMode.None)
{

void ApplyDebugParameters()
{
m_ShadowSettings.enabled = m_GlobalDebugParameters.shadowDebugParameters.enableShadows;
m_ShadowSettings.enabled = globalDebugParameters.shadowDebugParameters.enableShadows;
}
void UpdateCommonSettings()

36
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityObject = UnityEngine.Object;

buffer.Release();
buffer = null;
}
}
public static string GetFieldPath<TType, TValue>(Expression<Func<TType, TValue>> expr)
{
MemberExpression me;
switch (expr.Body.NodeType)
{
case ExpressionType.Convert:
case ExpressionType.ConvertChecked:
var ue = expr.Body as UnaryExpression;
me = (ue != null ? ue.Operand : null) as MemberExpression;
break;
default:
me = expr.Body as MemberExpression;
break;
}
var members = new List<string>();
while (me != null)
{
members.Add(me.Member.Name);
me = me.Expression as MemberExpression;
}
var sb = new StringBuilder();
for (int i = members.Count - 1; i >= 0; i--)
{
sb.Append(members[i]);
if (i > 0) sb.Append('.');
}
return sb.ToString();
}

正在加载...
取消
保存