浏览代码

Undo/redo/sync/serialization fixes

/2018.1
Thomas 7 年前
当前提交
12334521
共有 4 个文件被更改,包括 54 次插入24 次删除
  1. 6
      ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugState.cs
  2. 36
      ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs
  3. 1
      ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugUIDrawer.cs
  4. 35
      ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugWindow.cs

6
ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugState.cs


[SerializeField]
protected string m_QueryPath;
// We need this to keep track of the state modified in the current frame.
// This helps reduces the cost of re-applying states to original widgets and is also needed
// when two states point to the same value (e.g. when using split enums like HDRP does for
// the `fullscreenDebugMode`.
internal static DebugState m_CurrentDirtyState;
public string queryPath
{
get { return m_QueryPath; }

36
ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugUIDrawer.Builtins.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

EditorGUI.BeginChangeCheck();
var rect = PrepareControlRect();
bool value = EditorGUI.Toggle(rect, CoreEditorUtils.GetContent(w.displayName), s.value);
bool value = EditorGUI.Toggle(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue());
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

var rect = PrepareControlRect();
int value = w.min != null && w.max != null
? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.min(), w.max())
: EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), s.value);
? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue(), w.min(), w.max())
: EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue());
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

// No UIntField so we need to max to 0 ourselves or the value will wrap around
var rect = PrepareControlRect();
int tmp = w.min != null && w.max != null
? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)s.value), Mathf.Max(0, (int)w.min()), Mathf.Max(0, (int)w.max()))
: EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)s.value));
? EditorGUI.IntSlider(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)w.GetValue()), Mathf.Max(0, (int)w.min()), Mathf.Max(0, (int)w.max()))
: EditorGUI.IntField(rect, CoreEditorUtils.GetContent(w.displayName), Mathf.Max(0, (int)w.GetValue()));
uint value = (uint)Mathf.Max(0, tmp);

var rect = PrepareControlRect();
float value = w.min != null && w.max != null
? EditorGUI.Slider(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.min(), w.max())
: EditorGUI.FloatField(rect, CoreEditorUtils.GetContent(w.displayName), s.value);
? EditorGUI.Slider(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue(), w.min(), w.max())
: EditorGUI.FloatField(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue());
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

EditorGUI.BeginChangeCheck();
int value = s.value;
int value = w.GetValue();
if (w.enumNames == null || w.enumValues == null)
{
EditorGUILayout.LabelField("Can't draw an empty enumeration.");

var rect = PrepareControlRect();
value = EditorGUI.IntPopup(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.enumNames, w.enumValues);
int index = Array.IndexOf(w.enumValues, w.GetValue());
// Fallback just in case, we may be handling sub/sectionned enums here
if (index < 0)
value = w.enumValues[0];
value = EditorGUI.IntPopup(rect, CoreEditorUtils.GetContent(w.displayName), value, w.enumNames, w.enumValues);
}
if (EditorGUI.EndChangeCheck())

EditorGUI.BeginChangeCheck();
bool value = EditorGUILayout.Foldout(s.value, CoreEditorUtils.GetContent(w.displayName), true);
bool value = EditorGUILayout.Foldout(w.GetValue(), CoreEditorUtils.GetContent(w.displayName), true);
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

EditorGUI.BeginChangeCheck();
var rect = PrepareControlRect();
var value = EditorGUI.ColorField(rect, CoreEditorUtils.GetContent(w.displayName), s.value, w.showPicker, w.showAlpha, w.hdr);
var value = EditorGUI.ColorField(rect, CoreEditorUtils.GetContent(w.displayName), w.GetValue(), w.showPicker, w.showAlpha, w.hdr);
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

EditorGUI.BeginChangeCheck();
var value = EditorGUILayout.Vector2Field(w.displayName, s.value);
var value = EditorGUILayout.Vector2Field(w.displayName, w.GetValue());
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

EditorGUI.BeginChangeCheck();
var value = EditorGUILayout.Vector3Field(w.displayName, s.value);
var value = EditorGUILayout.Vector3Field(w.displayName, w.GetValue());
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

EditorGUI.BeginChangeCheck();
var value = EditorGUILayout.Vector4Field(w.displayName, s.value);
var value = EditorGUILayout.Vector4Field(w.displayName, w.GetValue());
if (EditorGUI.EndChangeCheck())
Apply(w, s, value);

1
ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugUIDrawer.cs


state.SetValue(value, widget);
widget.SetValue(value);
EditorUtility.SetDirty(state);
DebugState.m_CurrentDirtyState = state;
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}

35
ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugWindow.cs


void OnDestroy()
{
DebugManager.instance.onSetDirty -= MarkDirty;
Undo.ClearUndo(m_Settings);
if (m_WidgetStates != null)
{

}
}
public void ApplyStates()
public void ApplyStates(bool forceApplyAll = false)
if (!forceApplyAll && DebugState.m_CurrentDirtyState != null)
{
ApplyState(DebugState.m_CurrentDirtyState.queryPath, DebugState.m_CurrentDirtyState);
DebugState.m_CurrentDirtyState = null;
return;
}
{
var widget = DebugManager.instance.GetItem(state.Key) as DebugUI.IValueField;
ApplyState(state.Key, state.Value);
DebugState.m_CurrentDirtyState = null;
}
void ApplyState(string queryPath, DebugState state)
{
var widget = DebugManager.instance.GetItem(queryPath) as DebugUI.IValueField;
if (widget == null)
continue;
if (widget == null)
return;
widget.SetValue(state.Value.GetValue());
}
widget.SetValue(state.GetValue());
}
void OnUndoRedoPerformed()

// Something has been undone / redone, re-apply states to the debug tree
if (stateHash != m_Settings.currentStateHash)
{
ApplyStates();
ApplyStates(true);
m_Settings.currentStateHash = stateHash;
}

if (m_Settings.selectedPanel == i && Event.current.type == EventType.Repaint)
s_Styles.selected.Draw(elementRect, false, false, false, false);
if (GUI.Toggle(elementRect, m_Settings.selectedPanel == i, panel.displayName, s_Styles.sectionElement))
EditorGUI.BeginChangeCheck();
GUI.Toggle(elementRect, m_Settings.selectedPanel == i, panel.displayName, s_Styles.sectionElement);
if (EditorGUI.EndChangeCheck())
Undo.RecordObject(m_Settings, "Debug Panel Selection");
Undo.RegisterCompleteObjectUndo(m_Settings, "Debug Panel Selection");
m_Settings.selectedPanel = i;
}
}

正在加载...
取消
保存