浏览代码

#31 UIElements-based graph inspector

/main
Peter Bay Bastian 7 年前
当前提交
a92b64bb
共有 20 个文件被更改,包括 427 次插入15 次删除
  1. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  3. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphInspectorView.cs
  4. 78
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  5. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector.meta
  6. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters.meta
  7. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs
  8. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs.meta
  9. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/IMGUISlotEditorPresenter.cs
  10. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/IMGUISlotEditorPresenter.cs.meta
  11. 45
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs
  12. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs.meta
  13. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views.meta
  14. 105
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs
  15. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs.meta
  16. 85
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs
  17. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs.meta

25
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing.Util;
using UnityEditor.MaterialGraph.Drawing.Inspector;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

{
[SerializeField]
List<AbstractNodeInspector> m_Inspectors;
[SerializeField]
List<AbstractNodeEditorPresenter> m_Editors;
[SerializeField]
string m_Title;
public List<AbstractNodeInspector> inspectors
{

public List<AbstractNodeEditorPresenter> editors
{
get { return m_Editors; }
}
public string title
{
get { return m_Title; }
set { m_Title = value; }
}
m_Editors = new List<AbstractNodeEditorPresenter>();
m_Title = "Name of graph";
m_InspectorFactory = new ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector>(new[]
{
new TypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector)),

public void UpdateSelection(IEnumerable<INode> nodes)
{
m_Inspectors.Clear();
editors.Clear();
var editor = CreateInstance<StandardNodeEditorPresenter>();
editor.Initialize(node);
editors.Add(editor);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


m_TitleBarView = new TitleBarView();
m_TitleBarView.name = "TitleBar";
m_GraphInspectorView = new GraphInspectorView();
m_GraphInspectorView = new GraphInspectorView() { name = "inspector" };
Add(m_TitleBarView);
var contentContainer = new VisualElement() { m_GraphView, m_GraphInspectorView };

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphInspectorView.cs


using System;
using System;
using UnityEditor.MaterialGraph.Drawing.Inspector;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Object = UnityEngine.Object;

[SerializeField]
GraphInspectorPresenter m_Presenter;
IMGUIContainer m_ImguiContainer;
int m_EditorHash;
VisualElement m_EditorContainer;
VisualElement m_Title;
Add(m_ImguiContainer = new IMGUIContainer(OnGUIHandler));
var headerContainer = new VisualElement() { name = "header" };
m_Title = new VisualElement() { name = "title" };
headerContainer.Add(m_Title);
Add(headerContainer);
Add(m_EditorContainer = new VisualElement {name = "editorContainer"});
}
void OnGUIHandler()

public override void OnDataChanged()
{
if (presenter == null)
{
m_EditorContainer.Clear();
m_EditorHash = 0;
}
m_Title.text = presenter.title;
var editorHash = 17;
unchecked
{
foreach (var editorPresenter in presenter.editors)
editorHash = editorHash * 31 + editorPresenter.GetHashCode();
}
if (editorHash != m_EditorHash)
{
m_EditorHash = editorHash;
m_EditorContainer.Clear();
foreach (var editorPresenter in presenter.editors)
// TODO: Use abstract base class to allow custom node editors
m_EditorContainer.Add(new StandardNodeEditorView {presenter = editorPresenter as StandardNodeEditorPresenter});
}
Dirty(ChangeType.Repaint);
}

return;
RemoveWatch();
m_Presenter = value;
// m_ImguiContainer.executionContext = presenter.GetInstanceID();
OnDataChanged();
AddWatch();
}

78
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


flex: 1;
}
GraphEditorView #content GraphInspectorView {
width: 300;
padding-left: 10;
padding-right: 10;
padding-top: 10;
padding-bottom: 10;
}
GraphEditorView #content GraphInspectorView IMGUIContainer {
flex: 1;
GraphEditorView #content #inspector {
width: 400;
}
.MaterialNode #preview {

}
GraphInspectorView {
background-color: rgb(56, 56, 56);
}
GraphInspectorView > #header {
background-color: rgb(64, 64, 64);
border-color: rgb(79, 79, 79);
border-bottom-width: 1;
}
GraphInspectorView > #header > #title {
text-color: rgb(180, 180, 180);
font-style: bold;
padding-left: 16;
padding-right: 16;
padding-top: 10;
padding-bottom: 10;
}
.nodeEditor {
border-color: rgb(79, 79, 79);
border-bottom-width: 1;
padding-top: 10;
}
.nodeEditor > .header {
padding-left: 16;
padding-right: 16;
padding-bottom: 10;
flex-direction: row;
}
.nodeEditor > .header > .type {
text-color: rgb(180, 180, 180);
margin-left: 10;
}
.nodeEditor > .header > .title {
text-color: rgb(180, 180, 180);
font-style: bold;
}
.nodeEditor > .section {
padding-bottom: 10;
}
.nodeEditor > .section.hidden {
height: 0;
padding-bottom: 0;
}
.nodeEditor > .section > .title {
text-color: rgb(180, 180, 180);
font-style: bold;
padding-left: 16;
padding-right: 16;
padding-bottom: 2;
}
.nodeEditor > .section > #slots {
flex-direction: column;
padding-left: 15;
padding-right: 15;
}
IMGUISlotEditorView {
flex-direction: column;
padding-bottom: 2;
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector.meta


fileFormatVersion: 2
guid: 1d1f4aaa81084a13aaeb78dfaf7d35d7
timeCreated: 1503663057

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters.meta


fileFormatVersion: 2
guid: 2d08dfb360644031a5e64558d4a93263
timeCreated: 1503663071

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs


using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public abstract class AbstractNodeEditorPresenter : ScriptableObject
{
public abstract void Initialize(INode node);
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs.meta


fileFormatVersion: 2
guid: 97d910cfa5d2452e9ac7500b6cee25ab
timeCreated: 1503661223

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/IMGUISlotEditorPresenter.cs


using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public class IMGUISlotEditorPresenter : ScriptableObject
{
[SerializeField]
MaterialSlot m_Slot;
public MaterialSlot slot
{
get { return m_Slot; }
set { m_Slot = value; }
}
public Vector4 value
{
get { return m_Slot.currentValue; }
set
{
if (value == slot.currentValue)
return;
slot.currentValue = value;
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node);
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/IMGUISlotEditorPresenter.cs.meta


fileFormatVersion: 2
guid: 7be91f540ac243ec9bf12002b0fb8c1d
timeCreated: 1504002750

45
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public sealed class StandardNodeEditorPresenter : AbstractNodeEditorPresenter
{
[SerializeField]
AbstractMaterialNode m_Node;
// TODO: Use abstract base class such that other editors can be used
[SerializeField]
List<IMGUISlotEditorPresenter> m_SlotEditorPresenters;
public AbstractMaterialNode node
{
get { return m_Node; }
}
public IEnumerable<IMGUISlotEditorPresenter> slotEditorPresenters
{
get { return m_SlotEditorPresenters; }
}
public override void Initialize(INode node)
{
m_Node = node as AbstractMaterialNode;
m_SlotEditorPresenters = new List<IMGUISlotEditorPresenter>();
foreach (var slot in node.GetInputSlots<MaterialSlot>())
{
if (slot.concreteValueType == ConcreteSlotValueType.Vector1
|| slot.concreteValueType == ConcreteSlotValueType.Vector2
|| slot.concreteValueType == ConcreteSlotValueType.Vector3
|| slot.concreteValueType == ConcreteSlotValueType.Vector4)
{
var slotEditorPresenter = CreateInstance<IMGUISlotEditorPresenter>();
slotEditorPresenter.slot = slot;
m_SlotEditorPresenters.Add(slotEditorPresenter);
}
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs.meta


fileFormatVersion: 2
guid: a0786fdde6014aa6b3222772757dbbb5
timeCreated: 1503661346

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views.meta


fileFormatVersion: 2
guid: 0969ff891b874694aa732e1240ee159b
timeCreated: 1503663067

105
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public class IMGUISlotEditorView : DataWatchContainer
{
[SerializeField]
IMGUISlotEditorPresenter m_Presenter;
ConcreteSlotValueType m_CurrentValueType = ConcreteSlotValueType.Error;
public override void OnDataChanged()
{
if (presenter == null)
{
Clear();
return;
}
if (presenter.slot.concreteValueType == m_CurrentValueType)
return;
Clear();
m_CurrentValueType = presenter.slot.concreteValueType;
Action onGUIHandler;
if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector4)
onGUIHandler = Vector4OnGUIHandler;
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector3)
onGUIHandler = Vector3OnGUIHandler;
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector2)
onGUIHandler = Vector2OnGUIHandler;
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector1)
onGUIHandler = Vector1OnGUIHandler;
else
return;
Add(new IMGUIContainer(onGUIHandler) { executionContext = presenter.GetInstanceID() });
}
void Vector4OnGUIHandler()
{
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = EditorGUILayout.Vector4Field(presenter.slot.displayName, presenter.value);
EditorGUIUtility.wideMode = previousWideMode;
}
void Vector3OnGUIHandler()
{
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = EditorGUILayout.Vector3Field(presenter.slot.displayName, presenter.value);
EditorGUIUtility.wideMode = previousWideMode;
}
void Vector2OnGUIHandler()
{
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = EditorGUILayout.Vector2Field(presenter.slot.displayName, presenter.value);
EditorGUIUtility.wideMode = previousWideMode;
}
void Vector1OnGUIHandler()
{
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = new Vector4(EditorGUILayout.FloatField(presenter.slot.displayName, presenter.value.x), 0, 0, 0);
EditorGUIUtility.wideMode = previousWideMode;
}
protected override Object[] toWatch
{
get { return new Object[] { presenter }; }
}
public IMGUISlotEditorPresenter presenter
{
get { return m_Presenter; }
set
{
if (value == m_Presenter)
return;
RemoveWatch();
m_Presenter = value;
OnDataChanged();
AddWatch();
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs.meta


fileFormatVersion: 2
guid: 1c0c3a78bde740fba369b4d5a58d5354
timeCreated: 1503663627

85
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs


using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public class StandardNodeEditorView : DataWatchContainer
{
VisualElement m_EditorTitle;
VisualElement m_SlotsContainer;
VisualElement m_DefaultSlotValuesSection;
public StandardNodeEditorView()
{
AddToClassList("nodeEditor");
var headerContainer = new VisualElement();
headerContainer.AddToClassList("header");
{
m_EditorTitle = new VisualElement();
m_EditorTitle.AddToClassList("title");
headerContainer.Add(m_EditorTitle);
var headerType = new VisualElement { text = "(node)" };
headerType.AddToClassList("type");
headerContainer.Add(headerType);
}
Add(headerContainer);
m_DefaultSlotValuesSection = new VisualElement();
m_DefaultSlotValuesSection.AddToClassList("section");
{
var sectionTitle = new VisualElement { text = "Default Slot Values" };
sectionTitle.AddToClassList("title");
m_DefaultSlotValuesSection.Add(sectionTitle);
m_SlotsContainer = new VisualElement { name = "slots" };
m_DefaultSlotValuesSection.Add(m_SlotsContainer);
}
Add(m_DefaultSlotValuesSection);
}
[SerializeField]
StandardNodeEditorPresenter m_Presenter;
public StandardNodeEditorPresenter presenter
{
get { return m_Presenter; }
set
{
if (value == m_Presenter)
return;
RemoveWatch();
m_Presenter = value;
OnDataChanged();
AddWatch();
}
}
public override void OnDataChanged()
{
if (presenter == null)
return;
m_EditorTitle.text = presenter.node.name;
m_SlotsContainer.Clear();
foreach (var slotEditorPresenter in presenter.slotEditorPresenters)
{
m_SlotsContainer.Add(new IMGUISlotEditorView { presenter = slotEditorPresenter });
}
if (m_SlotsContainer.Any())
m_DefaultSlotValuesSection.RemoveFromClassList("hidden");
else
m_DefaultSlotValuesSection.AddToClassList("hidden");
}
protected override Object[] toWatch
{
get { return new Object[] { presenter }; }
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs.meta


fileFormatVersion: 2
guid: 61b4edcdcc1949a29fa0b42e25241429
timeCreated: 1503661486
正在加载...
取消
保存