浏览代码

Graph inspector now only shows editor for at most 1 node

/main
Peter Bay Bastian 7 年前
当前提交
25ed3aaf
共有 7 个文件被更改,包括 102 次插入65 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs
  2. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/GraphInspectorPresenter.cs
  3. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs
  4. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/SurfaceMasterNodeEditorPresenter.cs
  5. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs
  7. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

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


{
public abstract class AbstractNodeEditorPresenter : ScriptableObject
{
public abstract void Initialize(INode node);
public abstract INode node { get; set; }
}
}

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/GraphInspectorPresenter.cs


public class GraphInspectorPresenter : ScriptableObject
{
[SerializeField]
List<AbstractNodeEditorPresenter> m_Editors;
AbstractNodeEditorPresenter m_Editor;
public List<AbstractNodeEditorPresenter> editors
[SerializeField]
int m_SelectionCount;
TypeMapper m_TypeMapper;
public AbstractNodeEditorPresenter editor
get { return m_Editors; }
get { return m_Editor; }
}
public string title

}
TypeMapper m_TypeMapper;
public int selectionCount
{
get { return m_SelectionCount; }
set { m_SelectionCount = value; }
}
m_Editors = new List<AbstractNodeEditorPresenter>();
// m_InspectorMapper = new TypeMapper<INode, AbstractNodeInspector>(typeof(BasicNodeInspector))
// {
// {typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector)},
// {typeof(PropertyNode), typeof(PropertyNodeInspector)},
// {typeof(SubGraphInputNode), typeof(SubgraphInputNodeInspector)},
// {typeof(SubGraphOutputNode), typeof(SubgraphOutputNodeInspector)}
// };
// Nodes missing custom editors:
// - PropertyNode
// - SubGraphInputNode
// - SubGraphOutputNode
editors.Clear();
foreach (var node in nodes.OfType<SerializableNode>())
using (var nodesList = ListPool<INode>.GetDisposable())
var editor = (AbstractNodeEditorPresenter) CreateInstance(m_TypeMapper.MapType(node.GetType()));
editor.Initialize(node);
editors.Add(editor);
nodesList.value.AddRange(nodes);
m_SelectionCount = nodesList.value.Count;
if (m_SelectionCount == 1)
{
var node = nodesList.value.First();
if (m_Editor == null || node != m_Editor.node)
{
m_Editor = (AbstractNodeEditorPresenter) CreateInstance(m_TypeMapper.MapType(node.GetType()));
m_Editor.node = node;
}
}
else
{
m_Editor = null;
}
}
}
}

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


[SerializeField]
AbstractMaterialNode m_Node;
// TODO: Use abstract base class such that other editors can be used
public AbstractMaterialNode node
public override INode node
set
{
m_Node = (AbstractMaterialNode)value;
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);
}
}
}
}
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);
}
}
}
}
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/SurfaceMasterNodeEditorPresenter.cs


[SerializeField]
AbstractSurfaceMasterNode m_Node;
public AbstractSurfaceMasterNode node
public override INode node
set { m_Node = (AbstractSurfaceMasterNode)value; }
public override void Initialize(INode node)
public AbstractSurfaceMasterNode materialNode
m_Node = (AbstractSurfaceMasterNode) node;
get { return m_Node; }
}
}
}

58
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs


[SerializeField]
GraphInspectorPresenter m_Presenter;
int m_EditorHash;
int m_PresenterHash;
VisualElement m_EditorContainer;
VisualElement m_ContentContainer;
VisualElement m_MultipleSelectionsElement;
TypeMapper m_TypeMapper;

var headerContainer = new VisualElement() { name = "header" };
m_Title = new VisualElement() { name = "title" };
headerContainer.Add(m_Title);
var headerContainer = new VisualElement { name = "header" };
{
m_Title = new VisualElement() { name = "title" };
headerContainer.Add(m_Title);
}
Add(m_EditorContainer = new VisualElement {name = "editorContainer"});
m_ContentContainer = new VisualElement { name = "contentContainer" };
Add(m_ContentContainer);
{typeof(StandardNodeEditorPresenter), typeof(StandardNodeEditorView)},
{typeof(SurfaceMasterNodeEditorPresenter), typeof(SurfaceMasterNodeEditorView)}
{ typeof(StandardNodeEditorPresenter), typeof(StandardNodeEditorView) },
{ typeof(SurfaceMasterNodeEditorPresenter), typeof(SurfaceMasterNodeEditorView) }
};
}

{
m_EditorContainer.Clear();
m_EditorHash = 0;
m_ContentContainer.Clear();
m_PresenterHash = 0;
m_Title.text = presenter.title;
var editorHash = 17;
var presenterHash = 17;
foreach (var editorPresenter in presenter.editors)
editorHash = editorHash * 31 + editorPresenter.GetHashCode();
presenterHash = presenterHash * 31 + (presenter.editor == null ? 79 : presenter.editor.GetHashCode());
presenterHash = presenterHash * 31 + presenter.selectionCount;
if (editorHash != m_EditorHash)
m_Title.text = presenter.title;
if (presenterHash != m_PresenterHash)
m_EditorHash = editorHash;
m_EditorContainer.Clear();
foreach (var editorPresenter in presenter.editors)
m_PresenterHash = presenterHash;
m_ContentContainer.Clear();
if (presenter.selectionCount > 1)
{
var element = new VisualElement { name = "selectionCount", text = string.Format("{0} nodes selected.", presenter.selectionCount) };
m_ContentContainer.Add(element);
}
else if (presenter.editor != null)
var view = (AbstractNodeEditorView) Activator.CreateInstance(m_TypeMapper.MapType(editorPresenter.GetType()));
view.presenter = editorPresenter;
m_EditorContainer.Add(view);
var view = (AbstractNodeEditorView)Activator.CreateInstance(m_TypeMapper.MapType(presenter.editor.GetType()));
view.presenter = presenter.editor;
m_ContentContainer.Add(view);
}
}

protected override Object[] toWatch
{
get { return new Object[] {m_Presenter}; }
get { return new Object[] { m_Presenter }; }
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs


if (presenter == null)
return;
var options = presenter.node.options;
var options = presenter.materialNode.options;
EditorGUI.BeginChangeCheck();
options.srcBlend = (SurfaceMaterialOptions.BlendMode)EditorGUILayout.EnumPopup("Src Blend", options.srcBlend);

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


padding-bottom: 10;
}
GraphInspectorView > #contentContainer > #selectionCount {
text-color: rgb(180, 180, 180);
padding-left: 16;
padding-right: 16;
padding-top: 10;
padding-bottom: 10;
}
.nodeEditor {
border-color: rgb(79, 79, 79);
border-bottom-width: 1;

正在加载...
取消
保存