浏览代码

NodeDrawer now derives from Node.

And all the superfluous files have been removed.

Signed-off-by: joce <joce@unity3d.com>
/main
Peter Bay Bastian 8 年前
当前提交
4ff1c093
共有 16 个文件被更改,包括 79 次插入460 次删除
  1. 49
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  2. 136
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  3. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  4. 2
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Node.cs
  5. 3
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/NodePresenter.cs
  6. 19
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss
  7. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs
  8. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/cracks.ShaderSubGraph
  9. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs.meta
  10. 41
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs
  11. 80
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs
  12. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs.meta
  13. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.meta
  14. 24
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/Header.uss
  15. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/Header.uss.meta
  16. 100
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss

49
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


using System.Collections.Generic;
using System.Linq;
using System.Linq;
public class NodeDrawData : GraphElementPresenter
public class NodeDrawData : NodePresenter
{
protected NodeDrawData()
{}

public bool expanded = true;
[SerializeField]
protected List<GraphElementPresenter> m_Children = new List<GraphElementPresenter>();
[SerializeField]
protected List<AnchorDrawData> m_Anchors = new List<AnchorDrawData>();
[SerializeField]
public IEnumerable<GraphElementPresenter> elements
public virtual IEnumerable<GraphElementPresenter> elements
get { return m_Children.Concat(m_Anchors.Cast<GraphElementPresenter>()).Concat(m_Controls); }
get { return inputAnchors.Concat(outputAnchors).Cast<GraphElementPresenter>().Concat(m_Controls); }
}
public virtual void OnModified(ModificationScope scope)

if (scope == ModificationScope.Topological)
{
var slots = node.GetSlots<ISlot>().ToList();
m_Anchors.RemoveAll(data => !slots.Contains(data.slot));
AddSlots(slots.Except(m_Anchors.Select(x => x.slot)));
m_Anchors.Sort((x, y) => slots.IndexOf(x.slot) - slots.IndexOf(y.slot));
m_InputAnchors.RemoveAll(data => !slots.Contains(((AnchorDrawData)data).slot));
m_OutputAnchors.RemoveAll(data => !slots.Contains(((AnchorDrawData)data).slot));
AddSlots(slots.Except(m_InputAnchors.Concat(m_OutputAnchors).Select(data => ((AnchorDrawData)data).slot)));
m_InputAnchors.Sort((x, y) => slots.IndexOf(((AnchorDrawData)x).slot) - slots.IndexOf(((AnchorDrawData)y).slot));
m_OutputAnchors.Sort((x, y) => slots.IndexOf(((AnchorDrawData)x).slot) - slots.IndexOf(((AnchorDrawData)y).slot));
}
}

protected virtual IEnumerable<GraphElementPresenter> GetControlData()
{
return new ControlDrawData[0];
return Enumerable.Empty<GraphElementPresenter>();
foreach (var input in slots)
foreach (var slot in slots)
data.Initialize(input);
m_Anchors.Add(data);
data.Initialize(slot);
if (slot.isOutputSlot)
{
outputAnchors.Add(data);
}
else
{
inputAnchors.Add(data);
}
// TODO JOCE: Move to OnEnable??
capabilities |= Capabilities.Movable;
name = inNode.name;
title = inNode.name;
var headerData = CreateInstance<HeaderDrawData>();
headerData.Initialize(inNode);
m_Children.Add(headerData);
AddSlots(node.GetSlots<ISlot>());

position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
//position
}
}
}

136
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.Graphing.Util;
using UnityEditor.Graphing.Util;
using UnityEngine.RMGUI.StyleEnums;
using UnityEngine.RMGUI.StyleSheets;
public class NodeDrawer : GraphElement
public class NodeDrawer : Node
protected VisualContainer m_LeftContainer;
protected VisualContainer m_RightContainer;
private HeaderDrawer m_HeaderDrawer;
private VisualContainer m_InputContainer;
private VisualContainer m_OutputContainer;
private List<AnchorDrawData> m_CurrentAnchors;
private VisualContainer m_ControlsContainer;
private List<ControlDrawData> m_CurrentControlDrawData;
private bool m_CurrentExpanded;
private readonly VisualContainer m_ControlsContainer;
private readonly List<ControlDrawData> m_CurrentControlDrawData;
AddContainers();
classList = new ClassList("Node");
}
public override void SetPosition(Rect newPos)
{
positionType = PositionType.Absolute;
positionLeft = newPos.x;
positionTop = newPos.y;
}
private void AddContainers()
{
/*
* Layout structure:
* node
* - left
* - - header
* - - input
* - - controls
* - right
* - - output
*/
m_LeftContainer = new VisualContainer
{
classList = new ClassList("pane", "left"),
pickingMode = PickingMode.Ignore
};
{
m_HeaderDrawer = new HeaderDrawer();
m_HeaderDrawer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_HeaderDrawer);
m_InputContainer = new VisualContainer
{
name = "input",
pickingMode = PickingMode.Ignore,
};
m_InputContainer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_InputContainer);
m_ControlsContainer = new VisualContainer
{
name = "controls",
pickingMode = PickingMode.Ignore,
};
m_ControlsContainer.AddToClassList("paneItem");
m_LeftContainer.AddChild(m_ControlsContainer);
}
AddChild(m_LeftContainer);
m_RightContainer = new VisualContainer
m_ControlsContainer = new VisualContainer
classList = new ClassList("pane", "right"),
pickingMode = PickingMode.Ignore
name = "controls",
pickingMode = PickingMode.Ignore,
{
m_OutputContainer = new VisualContainer
{
name = "output",
pickingMode = PickingMode.Ignore,
};
m_OutputContainer.AddToClassList("paneItem");
m_RightContainer.AddChild(m_OutputContainer);
}
AddChild(m_RightContainer);
m_CurrentAnchors = new List<AnchorDrawData>();
m_LeftContainer.AddChild(m_ControlsContainer);
private void AddHeader(NodeDrawData nodeData)
{
var headerData = nodeData.elements.OfType<HeaderDrawData>().FirstOrDefault();
m_HeaderDrawer.dataProvider = headerData;
}
private void AddSlots(NodeDrawData nodeData)
{
var anchors = nodeData.elements.OfType<AnchorDrawData>().ToList();
if (anchors.Count == 0)
{
m_RightContainer.AddToClassList("empty");
return;
}
if (anchors.ItemsReferenceEquals(m_CurrentAnchors) && m_CurrentExpanded == nodeData.expanded)
return;
m_CurrentAnchors = anchors;
m_InputContainer.ClearChildren();
m_OutputContainer.ClearChildren();
int outputCount = 0;
foreach (var anchor in anchors)
{
var hidden = !nodeData.expanded && !anchor.connected;
if (!hidden && anchor.direction == Direction.Input)
{
m_InputContainer.AddChild(NodeAnchor.Create<EdgeDrawData>(anchor));
}
else if (!hidden && anchor.direction == Direction.Output)
{
outputCount++;
m_OutputContainer.AddChild(NodeAnchor.Create<EdgeDrawData>(anchor));
}
}
if (outputCount == 0)
m_RightContainer.AddToClassList("empty");
else
m_RightContainer.RemoveFromClassList("empty");
}
private void AddControls(NodeDrawData nodeData)
{
var controlDrawData = nodeData.elements.OfType<ControlDrawData>().ToList();

if (nodeData == null)
{
ClearChildren();
AddContainers();
return;
}

RemoveFromClassList("collapsed");
AddHeader(nodeData);
AddSlots(nodeData);
m_CurrentExpanded = nodeData.expanded;
}
}
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs


using System.Collections;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;

namespace UnityEditor.Graphing.Drawing
{
// TODO JOCE Maybe bring SimpleGraphView public. This implements pretty much all that it does.
[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss")]
public class SerializableGraphView : GraphView
{
public SerializableGraphView()

2
MaterialGraphProject/Assets/NewUI/Editor/Elements/Node.cs


namespace RMGUI.GraphView
{
class Node : GraphElement
public class Node : GraphElement
{
protected readonly VisualContainer m_MainContainer;
protected readonly VisualContainer m_LeftContainer;

3
MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/NodePresenter.cs


namespace RMGUI.GraphView
{
[Serializable]
class NodePresenter : SimpleElementPresenter
public class NodePresenter : SimpleElementPresenter
{
[SerializeField]
protected List<NodeAnchorPresenter> m_InputAnchors;

public virtual Orientation orientation
{
get { return m_Orientation; }
set { m_Orientation = value; }
}
// TODO make a simple creation function

19
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss


flex:1;
}
.node.horizontal #left > #controls {
padding-bottom: 8;
padding-left: 4;
padding-right: 6;
}
.node.horizontal #left > #controls > #element {
background-color: #FF0000;
margin-top: 5;
}
.node.horizontal #left > #preview {
background-color: rgb(45, 45, 45);
padding-left: 2;
padding-right: 2;
padding-bottom: 4;
margin-top: 5;
}
.node.vertical #pane > #left {
background-color: rgb(45, 45, 45);
flex:1;

28
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

[Serializable]
public class MaterialNodeDrawData : NodeDrawData
{
NodePreviewDrawData nodePreviewDrawData;
NodePreviewDrawData m_NodePreviewDrawData;
public bool requiresTime
{

public override IEnumerable<GraphElementPresenter> elements
{
// TODO JOCE Sub ideal to use yield, but will do for now.
get
{
foreach (var element in base.elements)
{
yield return element;
}
yield return m_NodePreviewDrawData;
}
}
if (nodePreviewDrawData != null)
nodePreviewDrawData.modificationScope = scope;
if (m_NodePreviewDrawData != null)
m_NodePreviewDrawData.modificationScope = scope;
}
protected MaterialNodeDrawData()

if (materialNode == null || !materialNode.hasPreview)
return;
nodePreviewDrawData = CreateInstance<NodePreviewDrawData>();
nodePreviewDrawData.Initialize(materialNode);
m_Children.Add(nodePreviewDrawData);
m_NodePreviewDrawData = CreateInstance<NodePreviewDrawData>();
m_NodePreviewDrawData.Initialize(materialNode);
// m_Children.Add(m_NodePreviewDrawData);
}
}
}

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/cracks.ShaderSubGraph


m_EditorClassIdentifier:
m_DrawingData:
m_SerializableSelection:
- be9ff4e1-caa8-4e27-afa3-cb97b096423e
- f1a71249-a296-4de6-a298-98da37ae3e1e
- 0d5979cf-43f6-4006-823e-ee52074f8b25
- 3d53f521-87aa-4d50-9276-8081340f4b7d
- 376ca068-34bd-413c-9d72-35cbbee15e79
- 992b43b5-7e46-4087-9dfa-2497303f2719
- 9d0b8029-de3f-4d49-8e94-2543eb26e4f1
- f21b82ea-7ed5-428c-923b-5173eff2ba9a
- afe32aee-e0a2-4ade-b355-e4d57b3ce835
m_MaterialSubGraph:
m_SerializableNodes:
- typeInfo:

JSONnodeData: "{\n \"m_GuidSerialized\": \"3d53f521-87aa-4d50-9276-8081340f4b7d\",\n
\ \"m_Name\": \"SubtractNode\",\n \"m_DrawData\": {\n \"m_Expanded\":
true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n
\ \"x\": 479.4627990722656,\n \"y\": 149.49801635742188,\n
\ \"x\": 479.4627990722656,\n \"y\": 152.49801635742188,\n
\ \"width\": 0.0,\n \"height\": 0.0\n }\n },\n
\ \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":

JSONnodeData: "{\n \"m_GuidSerialized\": \"376ca068-34bd-413c-9d72-35cbbee15e79\",\n
\ \"m_Name\": \"V1Node\",\n \"m_DrawData\": {\n \"m_Expanded\":
true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n
\ \"x\": 21.401573181152345,\n \"y\": 141.89109802246095,\n
\ \"x\": 78.401611328125,\n \"y\": 144.89111328125,\n
\ \"width\": 0.0,\n \"height\": 0.0\n }\n },\n
\ \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":

JSONnodeData: "{\n \"m_GuidSerialized\": \"9d0b8029-de3f-4d49-8e94-2543eb26e4f1\",\n
\ \"m_Name\": \"V1Node\",\n \"m_DrawData\": {\n \"m_Expanded\":
true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n
\ \"x\": 449.3622741699219,\n \"y\": 505.08001708984377,\n
\ \"x\": 482.3622741699219,\n \"y\": 526.0800170898438,\n
\ \"width\": 0.0,\n \"height\": 0.0\n }\n },\n
\ \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs.meta


fileFormatVersion: 2
guid: 3a2754e4165dbb54e886b7604ffbfb31
timeCreated: 1478187487
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

41
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs


using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class HeaderDrawData : GraphElementPresenter
{
protected HeaderDrawData()
{}
private INode node;
[SerializeField] private bool m_Expanded;
public string title
{
get { return node.name; }
}
public bool expanded
{
get { return m_Expanded; }
set
{
var state = node.drawState;
state.expanded = value;
node.drawState = state;
m_Expanded = value;
}
}
public void Initialize(INode inNode)
{
node = inNode;
name = inNode.name + " Header";
m_Expanded = node.drawState.expanded;
}
}
}

80
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs


using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/Header.uss")]
public class HeaderDrawer : DataWatchContainer
{
private VisualElement m_Title;
private VisualElement m_ExpandButton;
private HeaderDrawData m_DataProvider;
public HeaderDrawData dataProvider
{
get { return m_DataProvider; }
set
{
if (m_DataProvider == value)
return;
RemoveWatch();
m_DataProvider = value;
OnDataChanged();
AddWatch();
}
}
public HeaderDrawer()
{
m_Title = new VisualElement()
{
name = "title",
content = new GUIContent()
};
AddChild(m_Title);
m_ExpandButton = new VisualElement
{
name = "expandButton",
content = new GUIContent("")
};
var clickable = new Clickable(OnExpandClick);
m_ExpandButton.AddManipulator(clickable);
AddChild(m_ExpandButton);
}
public HeaderDrawer(HeaderDrawData dataProvider) : this()
{
this.dataProvider = dataProvider;
}
public override void OnDataChanged()
{
base.OnDataChanged();
if (dataProvider == null)
{
m_Title.content.text = "";
return;
}
m_Title.content.text = dataProvider.title;
m_ExpandButton.content.text = dataProvider.expanded ? "Collapse" : "Expand";
this.Touch(ChangeType.Repaint);
}
private void OnExpandClick()
{
if (dataProvider == null) return;
dataProvider.expanded = !dataProvider.expanded;
}
protected override object toWatch
{
get { return m_DataProvider; }
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs.meta


fileFormatVersion: 2
guid: 82f528cda04f18f4090208d5ff5a4700
timeCreated: 1478187487
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.meta


fileFormatVersion: 2
guid: c040dbfc587a399438b3f4bf8cc95f4b
timeCreated: 1478070440
licenseType: Pro
StyleSheetImporter:
userData:
assetBundleName:
assetBundleVariant:

24
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/Header.uss


HeaderDrawer {
flex-direction: row;
align-items: stretch;
justify-content: space-between;
padding-left: 5;
padding-right: 5;
padding-top: 5;
padding-bottom: 5;
}
HeaderDrawer #title {
flex: 2;
text-color: #FFFFFF;
text-alignment: middle-left;
font-size: 12;
font-style: bold;
}
HeaderDrawer #expandButton {
flex: 1;
text-color: rgb(153, 153, 153);
text-alignment: middle-right;
}

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/Header.uss.meta


fileFormatVersion: 2
guid: d8ee6a82394ca48bbbdc1184a36492e2
timeCreated: 1481286707
licenseType: Pro
StyleSheetImporter:
userData:
assetBundleName:
assetBundleVariant:

100
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss


.Node {
flex-direction: row;
align-items: stretch;
border-left: 4;
border-top: 4;
border-right: 4;
border-bottom: 4;
border-width: 2;
border-radius: 5;
}
.Node.selected {
border-color: rgb(210, 152, 0);
}
.Node .pane {
flex-direction: column;
align-items: stretch;
padding-left: 4;
padding-right: 4;
padding-top: 2;
padding-bottom: 4;
border-radius: 2;
}
.Node .pane.left {
width: 208;
background-color: rgb(45, 45, 45);
}
.Node .pane.right {
background-color: rgb(32, 33, 33);
margin-left: 2;
padding-left: 8;
}
.Node .pane.right.empty {
margin-left: 0;
padding-left: 0;
padding-right: 0;
}
.Node .paneItem {
margin-top: 2;
}
.Node NodeAnchor {
height: 26;
align-items: center;
}
.Node NodeAnchor #connector {
background-color: rgb(20, 21, 21);
border-color: rgb(20, 21, 21);
/* width is currently hard-coded */
border-width: 4;
margin-left: 5;
margin-right: 5;
width: 10;
height: 10;
border-radius: 15;
}
.Node NodeAnchor #connector.anchorHighlight {
background-color: rgb(220, 220, 220);
border-color: rgb(220, 220, 220);
}
.Node #input NodeAnchor {
flex-direction: row;
}
.Node #output NodeAnchor {
flex-direction: row-reverse;
}
.Node NodeAnchor #type {
text-color: rgb(153, 153, 153);
flex:1;
}
.Node #input NodeAnchor #type {
text-alignment: middle-left;
}
.Node #output NodeAnchor #type {
text-alignment: middle-right;
}
.Node #controls {
flex-direction: column;
padding-bottom: 2;
padding-left: 4;
padding-right: 4;
}
.Node #controls #element{
flex-direction: column;
}
正在加载...
取消
保存