浏览代码

DrawData be gone

Signed-off-by: joce <joce@unity3d.com>
/main
joce 8 年前
当前提交
3e485a48
共有 95 个文件被更改,包括 792 次插入588 次删除
  1. 16
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
  2. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs
  3. 24
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/GraphEditorDrawer.cs
  4. 24
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  5. 6
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarButtonDrawer.cs
  6. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs
  7. 26
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  8. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
  9. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs
  10. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawState.cs
  11. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs
  12. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs
  13. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/NodePreviewDrawer.cs
  14. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  15. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
  16. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs
  17. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodePresenter.cs
  18. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  19. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
  20. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodePresenter.cs
  21. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodePresenter.cs
  22. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodePresenter.cs
  23. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodePresenter.cs
  24. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterPresenter.cs
  25. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs
  26. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodePresenter.cs
  27. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs
  28. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodePresenter.cs
  29. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodePresenter.cs
  30. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodePresenter.cs
  31. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphAnchorPresenter.cs
  32. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphControlPresenter.cs
  33. 329
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs
  34. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters.meta
  35. 17
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphPresenter.cs
  36. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters.meta
  37. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  38. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs
  39. 19
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphEdgePresenter.cs
  40. 105
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphNodePresenter.cs
  41. 14
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs
  42. 69
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarPresenter.cs
  43. 329
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs
  44. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData.meta
  45. 17
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs
  46. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphDataSource.cs
  47. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodeDrawData.cs
  48. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData.meta
  49. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs.meta
  50. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphPresenter.cs.meta
  51. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawState.cs.meta
  52. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawState.cs
  53. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters
  54. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs.meta
  55. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodePresenter.cs.meta
  56. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs.meta
  57. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs.meta
  58. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs.meta
  59. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs.meta
  60. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodePresenter.cs.meta
  61. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodePresenter.cs.meta
  62. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodePresenter.cs.meta
  63. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodePresenter.cs.meta
  64. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterPresenter.cs.meta
  65. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs.meta
  66. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodePresenter.cs.meta
  67. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs.meta
  68. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodePresenter.cs.meta
  69. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodePresenter.cs.meta
  70. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodePresenter.cs.meta
  71. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs
  72. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodePresenter.cs
  73. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  74. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
  75. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodePresenter.cs
  76. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodePresenter.cs
  77. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodePresenter.cs
  78. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodePresenter.cs
  79. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterPresenter.cs
  80. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs
  81. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodePresenter.cs
  82. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs
  83. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodePresenter.cs
  84. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodePresenter.cs
  85. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodePresenter.cs
  86. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphAnchorPresenter.cs.meta
  87. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphControlPresenter.cs.meta
  88. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphEdgePresenter.cs.meta
  89. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphNodePresenter.cs.meta
  90. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarPresenter.cs.meta
  91. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs.meta
  92. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphAnchorPresenter.cs
  93. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphControlPresenter.cs

16
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs


private GraphEditorDrawer m_GraphEditorDrawer;
public virtual AbstractGraphDataSource CreateDataSource()
public virtual AbstractGraphPresenter CreateDataSource()
return CreateInstance<SerializedGraphDataSource>();
return CreateInstance<SerializedGraphPresenter>();
}
public virtual GraphView CreateGraphView()

var source = CreateDataSource();
source.Initialize(m_LastSelection, this);
m_GraphEditorDrawer.dataSource = source;
m_GraphEditorDrawer.presenter = source;
//m_GraphView.StretchToParentSize();
Repaint();
focused = false;

/*
private void ConvertSelectionToSubGraph()
{
if (m_Canvas.dataSource == null)
if (m_Canvas.presenter == null)
var dataSource = m_Canvas.dataSource as GraphDataSource;
if (dataSource == null)
var presenter = m_Canvas.presenter as GraphDataSource;
if (presenter == null)
var asset = dataSource.graphAsset;
var asset = presenter.graphAsset;
if (asset == null)
return;

}
var toDelete = m_Canvas.selection.Where(x => x is DrawableNode).ToList();
dataSource.DeleteElements(toDelete);
presenter.DeleteElements(toDelete);
targetGraph.ValidateGraph();
m_Canvas.ReloadData();

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs


if (pastedGraph == null)
return;
if (parent.dataSource == null)
if (parent.presenter == null)
var dataSource = parent.dataSource as GraphDataSource;
if (dataSource == null)
var presenter = parent.presenter as GraphDataSource;
if (presenter == null)
var asset = dataSource.graphAsset;
var asset = presenter.graphAsset;
if (asset == null)
return;

24
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/GraphEditorDrawer.cs


namespace UnityEditor.Graphing.Drawing
{
// TODO JOCE Remove all traces of dataSource
// TODO JOCE: Maybe this needs to dereive from something we already have?
[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/GraphEditor.uss")]
public class GraphEditorDrawer : DataWatchContainer

private TitleBarDrawer m_TitleBarDrawer;
// TODO: Create graphView from here rather than have it passed in through constructor
public GraphEditorDrawer(GraphView graphView, AbstractGraphDataSource dataSource)
public GraphEditorDrawer(GraphView graphView, AbstractGraphPresenter presenter)
m_TitleBarDrawer = new TitleBarDrawer(dataSource.titleBar);
m_TitleBarDrawer = new TitleBarDrawer(presenter.titleBar);
this.dataSource = dataSource;
this.presenter = presenter;
m_GraphView.presenter = m_DataSource;
m_TitleBarDrawer.dataProvider = m_DataSource.titleBar;
m_GraphView.presenter = m_Presenter;
m_TitleBarDrawer.dataProvider = m_Presenter.titleBar;
private AbstractGraphDataSource m_DataSource;
private AbstractGraphPresenter m_Presenter;
public AbstractGraphDataSource dataSource
public AbstractGraphPresenter presenter
get { return m_DataSource; }
get { return m_Presenter; }
if (m_DataSource == value)
if (m_Presenter == value)
m_DataSource = value;
m_Presenter = value;
OnDataChanged();
AddWatch();
}

{
get { return m_DataSource; }
get { return m_Presenter; }
}
}
}

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


public class NodeDrawer : Node
{
private readonly VisualContainer m_ControlsContainer;
private readonly List<ControlDrawData> m_CurrentControlDrawData;
private readonly List<GraphControlPresenter> m_CurrentControlPresenter;
public NodeDrawer()
{

};
leftContainer.AddChild(m_ControlsContainer);
m_CurrentControlDrawData = new List<ControlDrawData>();
m_CurrentControlPresenter = new List<GraphControlPresenter>();
private void AddControls(NodeDrawData nodeData)
private void AddControls(GraphNodePresenter nodeData)
var controlDrawData = nodeData.elements.OfType<ControlDrawData>().ToList();
var controlPresenters = nodeData.elements.OfType<GraphControlPresenter>().ToList();
m_CurrentControlDrawData.Clear();
m_CurrentControlPresenter.Clear();
if (controlDrawData.ItemsReferenceEquals(m_CurrentControlDrawData))
if (controlPresenters.ItemsReferenceEquals(m_CurrentControlPresenter))
for (int i = 0; i < controlDrawData.Count; i++)
for (int i = 0; i < controlPresenters.Count; i++)
var controlData = controlDrawData[i];
var controlData = controlPresenters[i];
var imContainer = m_ControlsContainer.GetChildAtIndex(i) as IMGUIContainer;
imContainer.OnGUIHandler = controlData.OnGUIHandler;
imContainer.height = controlData.GetHeight();

{
m_ControlsContainer.ClearChildren();
m_CurrentControlDrawData.Clear();
m_CurrentControlPresenter.Clear();
foreach (var controlData in controlDrawData)
foreach (var controlData in controlPresenters)
{
var imContainer = new IMGUIContainer()
{

height = controlData.GetHeight()
};
m_ControlsContainer.AddChild(imContainer);
m_CurrentControlDrawData.Add(controlData);
m_CurrentControlPresenter.Add(controlData);
}
}
}

base.OnDataChanged();
var nodeData = GetPresenter<NodeDrawData>();
var nodeData = GetPresenter<GraphNodePresenter>();
if (nodeData == null)
{

6
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarButtonDrawer.cs


{
public class TitleBarButtonDrawer : DataWatchContainer
{
TitleBarButtonDrawData m_dataProvider;
TitleBarButtonPresenter m_dataProvider;
public TitleBarButtonDrawData dataProvider
public TitleBarButtonPresenter dataProvider
{
get { return m_dataProvider; }
set

}
}
public TitleBarButtonDrawer(TitleBarButtonDrawData dataProvider)
public TitleBarButtonDrawer(TitleBarButtonPresenter dataProvider)
{
classList = new ClassList("titleBarItem");

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs


[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/TitleBar.uss")]
public class TitleBarDrawer : DataWatchContainer
{
TitleBarDrawData m_DataProvider;
TitleBarPresenter m_DataProvider;
public TitleBarDrawData dataProvider
public TitleBarPresenter dataProvider
{
get { return m_DataProvider; }
set

}
}
public TitleBarDrawer(TitleBarDrawData dataProvider)
public TitleBarDrawer(TitleBarPresenter dataProvider)
{
classList = ClassList.empty;
name = "TitleBar";

UpdateContainer(m_RightContainer, m_DataProvider.rightItems);
}
void UpdateContainer(VisualContainer container, IEnumerable<TitleBarButtonDrawData> itemDatas)
void UpdateContainer(VisualContainer container, IEnumerable<TitleBarButtonPresenter> itemDatas)
{
// The number of items can't change for now.
foreach (var pair in itemDatas.Zip(container.children.OfType<TitleBarButtonDrawer>()))

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


InsertChild(0, new GridBackground());
dataMapper[typeof(NodeDrawData)] = typeof(NodeDrawer);
dataMapper[typeof(GraphNodePresenter)] = typeof(NodeDrawer);
var nodalViewData = GetPresenter<AbstractGraphDataSource>();
var nodalViewData = GetPresenter<AbstractGraphPresenter>();
selection.OfType<NodeDrawer>().Select(x => x.GetPresenter<NodeDrawData>()),
selection.OfType<Edge>().Select(x => x.GetPresenter<EdgeDrawData>())
selection.OfType<NodeDrawer>().Select(x => x.GetPresenter<GraphNodePresenter>()),
selection.OfType<Edge>().Select(x => x.GetPresenter<GraphEdgePresenter>())
);
return EventPropagation.Stop;

{
base.OnDataChanged();
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
if (graphAsset == null || graphAsset.drawingData.selection.SequenceEqual(selection.OfType<NodeDrawer>().Select(d => ((NodeDrawData) d.presenter).node.guid))) return;
if (graphAsset == null || graphAsset.drawingData.selection.SequenceEqual(selection.OfType<NodeDrawer>().Select(d => ((GraphNodePresenter) d.presenter).node.guid))) return;
.FirstOrDefault(drawer => ((NodeDrawData) drawer.presenter).node.guid == guid))
.FirstOrDefault(drawer => ((GraphNodePresenter) drawer.presenter).node.guid == guid))
.ToList();
ClearSelection();

public void SetGlobalSelection()
{
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
if (graphDataSource == null || graphDataSource.graphAsset == null)
return;
Selection.activeObject = graphDataSource.graphAsset.GetScriptableObject();

{
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
var selectedNodeGuids = selection.OfType<NodeDrawer>().Select(x => ((NodeDrawData) x.presenter).node.guid);
var selectedNodeGuids = selection.OfType<NodeDrawer>().Select(x => ((GraphNodePresenter) x.presenter).node.guid);
graphDataSource.graphAsset.drawingData.selection = selectedNodeGuids;
}

public EventPropagation CopySelection()
{
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
if (selection.Any() && graphDataSource != null)
graphDataSource.Copy(selection.OfType<GraphElement>().Select(ge => ge.presenter));
return EventPropagation.Stop;

{
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
if (selection.Any() && graphDataSource != null)
graphDataSource.Duplicate(selection.OfType<GraphElement>().Select(ge => ge.presenter));
return EventPropagation.Stop;

{
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
if (graphDataSource != null)
graphDataSource.Paste();
return EventPropagation.Stop;

10
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs


private string m_Name;
[SerializeField]
private DrawingData m_DrawData;
private DrawState m_DrawState;
[NonSerialized]
private List<ISlot> m_Slots = new List<ISlot>();

get { return true; }
}
public DrawingData drawState
public DrawState drawState
get { return m_DrawData; }
get { return m_DrawState; }
m_DrawData = value;
m_DrawState = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}

public SerializableNode()
{
m_DrawData.expanded = true;
m_DrawState.expanded = true;
m_Guid = Guid.NewGuid();
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs


T FindInputSlot<T>(int slotId) where T : ISlot;
T FindOutputSlot<T>(int slotId) where T : ISlot;
IEnumerable<ISlot> GetInputsWithNoConnection();
DrawingData drawState { get; set; }
DrawState drawState { get; set; }
bool hasError { get; }
void ValidateNode();
void UpdateNodeAfterDeserialization();

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawState.cs


namespace UnityEngine.Graphing
{
[Serializable]
public struct DrawingData
public struct DrawState
{
[SerializeField]
private bool m_Expanded;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs


protected GUIContent m_Title = new GUIContent();
private NodePreviewDrawData m_NodePreviewPresenter;
private NodePreviewPresenter m_NodePreviewPresenter;
private AbstractMaterialNode m_PreviewNode;

public override void OnEnable()
{
m_NodePreviewPresenter = CreateInstance<NodePreviewDrawData>();
m_NodePreviewPresenter = CreateInstance<NodePreviewPresenter>();
base.OnEnable();
previewNode = null;
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs


public class MaterialNodeDrawer : NodeDrawer
{
VisualContainer m_PreviewContainer;
private List<NodePreviewDrawData> m_currentPreviewData;
private List<NodePreviewPresenter> m_currentPreviewData;
bool m_IsScheduled;
public MaterialNodeDrawer()

};
leftContainer.AddChild(m_PreviewContainer);
m_currentPreviewData = new List<NodePreviewDrawData>();
m_currentPreviewData = new List<NodePreviewPresenter>();
}
private void SchedulePolling()

private void InvalidateUIIfNeedsTime(TimerState timerState)
{
var data = GetPresenter<MaterialNodeDrawData>();
var data = GetPresenter<MaterialNodePresenter>();
var childrenNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, data.node);
if (childrenNodes.OfType<IRequiresTime>().Any())

ListPool<INode>.Release(childrenNodes);
}
private void AddPreview(MaterialNodeDrawData nodeData)
private void AddPreview(MaterialNodePresenter nodeData)
if (!nodeData.elements.OfType<NodePreviewDrawData>().Any())
if (!nodeData.elements.OfType<NodePreviewPresenter>().Any())
var previews = nodeData.elements.OfType<NodePreviewDrawData>().ToList();
var previews = nodeData.elements.OfType<NodePreviewPresenter>().ToList();
if (!previews.ItemsReferenceEquals(m_currentPreviewData))
{

{
base.OnDataChanged();
var nodeData = GetPresenter<MaterialNodeDrawData>();
var nodeData = GetPresenter<MaterialNodePresenter>();
if (nodeData == null)
{
m_PreviewContainer.ClearChildren();

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/NodePreviewDrawer.cs


{
public class NodePreviewDrawer : Image
{
public NodePreviewDrawData data;
public NodePreviewPresenter data;
public override void DoRepaint(IStylePainter painter)
{

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


GetWindow<MaterialGraphEditWindow>();
}
public override AbstractGraphDataSource CreateDataSource()
public override AbstractGraphPresenter CreateDataSource()
return CreateInstance<MaterialGraphDataSource>();
return CreateInstance<MaterialGraphPresenter>();
}
public override GraphView CreateGraphView()

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs


{
AddManipulator(new ContextualMenu(DoContextMenu));
dataMapper[typeof(MaterialNodeDrawData)] = typeof(MaterialNodeDrawer);
dataMapper[typeof(AnchorDrawData)] = typeof(NodeAnchor);
dataMapper[typeof(MaterialNodePresenter)] = typeof(MaterialNodeDrawer);
dataMapper[typeof(GraphAnchorPresenter)] = typeof(NodeAnchor);
dataMapper[typeof(EdgePresenter)] = typeof(Edge);
}

drawstate.position = new Rect(localPos.x, localPos.y, 0, 0);
node.drawState = drawstate;
var graphDataSource = GetPresenter<AbstractGraphDataSource>();
var graphDataSource = GetPresenter<AbstractGraphPresenter>();
graphDataSource.AddNode(node);
}

var path = EditorUtility.SaveFilePanelInProject("Export shader to file...", "shader.shader", "shader", "Enter file name");
var ds = dataSource as AbstractGraphDataSource;
var ds = presenter as AbstractGraphPresenter;
if (ds != null && !string.IsNullOrEmpty(path))
{
ExportShader(ds.graphAsset as MaterialGraphAsset, path);

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class ColorContolDrawData : ControlDrawData
class ColorContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class ColorNodeDrawData : MaterialNodeDrawData
public class ColorNodePresenter : MaterialNodePresenter
var instance = CreateInstance<ColorContolDrawData>();
var instance = CreateInstance<ColorContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class MasterNodeControlDrawData : ControlDrawData
class MasterNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class MasterNodeDrawData : MaterialNodeDrawData
public class MasterNodePresenter : MaterialNodePresenter
var instance = CreateInstance<MasterNodeControlDrawData>();
var instance = CreateInstance<MasterNodeControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class NodePreviewDrawData : GraphElementPresenter
public class NodePreviewPresenter : GraphElementPresenter
protected NodePreviewDrawData()
protected NodePreviewPresenter()
{}
private MaterialGraphPreviewGenerator m_PreviewGenerator;

var localNode = (IMasterNode)m_Node;
if (localNode == null)
return string.Empty;
List<PropertyGenerator.TextureInfo> defaultTextures;
var resultShader = ((IMasterNode) m_Node).GetFullShader(GenerationMode.Preview, out defaultTextures);
m_GeneratedShaderMode = PreviewMode.Preview3D;

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
public class PropertyControlDrawData : ControlDrawData
public class PropertyControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public abstract class PropertyNodeDrawData : MaterialNodeDrawData
public abstract class PropertyNodePresenter : MaterialNodePresenter
var instance = CreateInstance<PropertyControlDrawData>();
var instance = CreateInstance<PropertyControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class RemapInputControlDrawData : ControlDrawData
class RemapInputControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class RemapInputNodeDrawData : MaterialNodeDrawData
public class RemapInputNodePresenter : MaterialNodePresenter
var instance = CreateInstance<RemapInputControlDrawData>();
var instance = CreateInstance<RemapInputControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class RemapMasterControlDrawData : ControlDrawData
class RemapMasterControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

return;
remapNode.remapAsset = (MaterialRemapAsset)EditorGUILayout.MiniThumbnailObjectField(
new GUIContent("Remap Asset"),
remapNode.remapAsset,
new GUIContent("Remap Asset"),
remapNode.remapAsset,
typeof(MaterialRemapAsset), null);
}

}
[Serializable]
public class RemapMasterNodeDrawData : MasterNodeDrawData
public class RemapMasterNodePresenter : MasterNodePresenter
var instance = CreateInstance<RemapMasterControlDrawData>();
var instance = CreateInstance<RemapMasterControlPresenter>();
instance.Initialize(node);
var controls = new List<GraphElementPresenter>(base.GetControlData());
controls.Add(instance);

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SubgraphIONodeControlDrawData : ControlDrawData
class SubgraphIONodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class SubgraphIONodeDrawData : MaterialNodeDrawData
public class SubgraphIONodePresenter : MaterialNodePresenter
var instance = CreateInstance<SubgraphIONodeControlDrawData>();
var instance = CreateInstance<SubgraphIONodeControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SubgraphContolDrawData : ControlDrawData
class SubgraphContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class SubgraphNodeDrawData : MaterialNodeDrawData
public class SubgraphNodePresenter : MaterialNodePresenter
var instance = CreateInstance<SubgraphContolDrawData>();
var instance = CreateInstance<SubgraphContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterPresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SurfaceMasterContolDrawData : ControlDrawData
class SurfaceMasterContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class SurfaceMasterDrawData : MasterNodeDrawData
public class SurfaceMasterPresenter : MasterNodePresenter
var instance = CreateInstance<SurfaceMasterContolDrawData>();
var instance = CreateInstance<SurfaceMasterContolPresenter>();
instance.Initialize(node);
var controls = new List<GraphElementPresenter>(base.GetControlData());
controls.Add(instance);

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class TextureContolDrawData : ControlDrawData
class TextureContolPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames

}
[Serializable]
public class TextureNodeDrawData : MaterialNodeDrawData
public class TextureNodePresenter : MaterialNodePresenter
var instance = CreateInstance<TextureContolDrawData>();
var instance = CreateInstance<TextureContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class UVNodeContolDrawData : ControlDrawData
class UVNodeContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class UVNodeDrawData : MaterialNodeDrawData
public class UVNodePresenter : MaterialNodePresenter
var instance = CreateInstance<UVNodeContolDrawData>();
var instance = CreateInstance<UVNodeContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class Vector1ControlDrawData : ControlDrawData
class Vector1ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class Vector1NodeDrawData : PropertyNodeDrawData
public class Vector1NodePresenter : PropertyNodePresenter
var instance = CreateInstance<Vector1ControlDrawData>();
var instance = CreateInstance<Vector1ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class Vector2ControlDrawData : ControlDrawData
class Vector2ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class Vector2NodeDrawData : PropertyNodeDrawData
public class Vector2NodePresenter : PropertyNodePresenter
var instance = CreateInstance<Vector2ControlDrawData>();
var instance = CreateInstance<Vector2ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class Vector3ControlDrawData : ControlDrawData
class Vector3ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class Vector3NodeDrawData : PropertyNodeDrawData
public class Vector3NodePresenter : PropertyNodePresenter
var instance = CreateInstance<Vector3ControlDrawData>();
var instance = CreateInstance<Vector3ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class Vector4ControlDrawData : ControlDrawData
class Vector4ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

}
[Serializable]
public class Vector4NodeDrawData : PropertyNodeDrawData
public class Vector4NodePresenter : PropertyNodePresenter
var instance = CreateInstance<Vector4ControlDrawData>();
var instance = CreateInstance<Vector4ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphAnchorPresenter.cs


// TODO JOCE Use GraphView's Input and Output node anchors instead.
[Serializable]
public class AnchorDrawData : NodeAnchorPresenter
public class GraphAnchorPresenter : NodeAnchorPresenter
protected AnchorDrawData()
protected GraphAnchorPresenter()
{}
public ISlot slot { get; private set; }

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphControlPresenter.cs


namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public abstract class ControlDrawData : GraphElementPresenter
public abstract class GraphControlPresenter : GraphElementPresenter
protected ControlDrawData()
protected GraphControlPresenter()
{}
public void Initialize(INode inNode)

329
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public abstract class AbstractGraphPresenter : GraphViewPresenter
{
private readonly TypeMapper m_DataMapper = new TypeMapper(typeof(GraphNodePresenter));
public IGraphAsset graphAsset { get; private set; }
[SerializeField]
private TitleBarPresenter m_TitleBar;
[SerializeField]
private EditorWindow m_Container;
public TitleBarPresenter titleBar
{
get { return m_TitleBar; }
}
void OnNodeChanged(INode inNode, ModificationScope scope)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theElements = m_Elements.OfType<GraphNodePresenter>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
drawableNodeData.OnModified(scope);
}
if (scope == ModificationScope.Topological)
UpdateData();
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
if (m_Container != null)
m_Container.Repaint();
}
private void UpdateData()
{
// Find all nodes currently being drawn which are no longer in the graph (i.e. deleted)
var deletedElements = m_Elements
.OfType<GraphNodePresenter>()
.Where(nd => !graphAsset.graph.GetNodes<INode>().Contains(nd.node))
.OfType<GraphElementPresenter>()
.ToList();
var deletedEdges = m_Elements.OfType<GraphEdgePresenter>()
.Where(ed => !graphAsset.graph.edges.Contains(ed.edge));
// Find all edges currently being drawn which are no longer in the graph (i.e. deleted)
foreach (var edgeData in deletedEdges)
{
// Make sure to disconnect the node, otherwise new connections won't be allowed for the used slots
edgeData.output.Disconnect(edgeData);
edgeData.input.Disconnect(edgeData);
var toNodeGuid = edgeData.edge.inputSlot.nodeGuid;
var toNode = m_Elements.OfType<GraphNodePresenter>().FirstOrDefault(nd => nd.node.guid == toNodeGuid);
if (toNode != null)
{
// Make the input node (i.e. right side of the connection) re-render
OnNodeChanged(toNode.node, ModificationScope.Graph);
}
deletedElements.Add(edgeData);
}
// Remove all nodes and edges marked for deletion
foreach (var deletedElement in deletedElements)
{
m_Elements.Remove(deletedElement);
}
var addedNodes = new List<GraphNodePresenter>();
// Find all new nodes and mark for addition
foreach (var node in graphAsset.graph.GetNodes<INode>())
{
// Check whether node already exists
if (m_Elements.OfType<GraphNodePresenter>().Any(e => e.node == node))
continue;
var type = m_DataMapper.MapType(node.GetType());
var nodeData = (GraphNodePresenter)CreateInstance(type);
node.onModified += OnNodeChanged;
nodeData.Initialize(node);
addedNodes.Add(nodeData);
}
// Create edge data for nodes marked for addition
var drawableEdges = new List<GraphEdgePresenter>();
foreach (var addedNode in addedNodes)
{
var baseNode = addedNode.node;
foreach (var slot in baseNode.GetOutputSlots<ISlot>())
{
var sourceAnchors = addedNode.elements.OfType<GraphAnchorPresenter>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.id));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = addedNodes.FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.elements.OfType<GraphAnchorPresenter>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgeData = CreateInstance<GraphEdgePresenter>();
edgeData.Initialize(edge);
edgeData.output = sourceAnchor;
edgeData.output.Connect(edgeData);
edgeData.input = targetAnchor;
edgeData.input.Connect(edgeData);
drawableEdges.Add(edgeData);
}
}
}
// Add nodes marked for addition
m_Elements.AddRange(addedNodes.OfType<GraphElementPresenter>());
// Find edges in the graph that are not being drawn and create edge data for them
foreach (var edge in graphAsset.graph.edges)
{
if (!m_Elements.OfType<GraphEdgePresenter>().Any(ed => ed.edge == edge))
{
var fromNode = graphAsset.graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
var fromSlot = fromNode.FindOutputSlot<ISlot>(edge.outputSlot.slotId);
var sourceNode = m_Elements.OfType<GraphNodePresenter>().FirstOrDefault(x => x.node == fromNode);
var sourceAnchors = sourceNode.elements.OfType<GraphAnchorPresenter>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == fromSlot);
var toNode = graphAsset.graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = m_Elements.OfType<GraphNodePresenter>().FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.elements.OfType<GraphAnchorPresenter>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
OnNodeChanged(targetNode.node, ModificationScope.Graph);
var edgeData = CreateInstance<GraphEdgePresenter>();
edgeData.Initialize(edge);
edgeData.output = sourceAnchor;
edgeData.output.Connect(edgeData);
edgeData.input = targetAnchor;
edgeData.input.Connect(edgeData);
drawableEdges.Add(edgeData);
}
}
m_Elements.AddRange(drawableEdges.OfType<GraphElementPresenter>());
}
protected abstract void AddTypeMappings(Action<Type, Type> map);
public virtual void Initialize(IGraphAsset graphAsset, EditorWindow container)
{
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);
this.graphAsset = graphAsset;
m_Container = container;
m_TitleBar = CreateInstance<TitleBarPresenter>();
m_TitleBar.Initialize(graphAsset);
if (graphAsset == null)
return;
UpdateData();
}
public void AddNode(INode node)
{
graphAsset.graph.AddNode(node);
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
UpdateData();
}
public void RemoveElements(IEnumerable<GraphNodePresenter> nodes, IEnumerable<GraphEdgePresenter> edges)
{
graphAsset.graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graphAsset.graph.ValidateGraph();
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
UpdateData();
}
public void Connect(GraphAnchorPresenter left, GraphAnchorPresenter right)
{
if (left != null && right != null)
{
graphAsset.graph.Connect(left.slot.slotReference, right.slot.slotReference);
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
UpdateData();
}
}
private CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElementPresenter> selection)
{
var graph = new CopyPasteGraph();
foreach (var presenter in selection)
{
var nodePresenter = presenter as GraphNodePresenter;
if (nodePresenter != null)
{
graph.AddNode(nodePresenter.node);
foreach (var edge in NodeUtils.GetAllEdges(nodePresenter.node))
graph.AddEdge(edge);
}
var edgePresenter = presenter as GraphEdgePresenter;
if (edgePresenter != null)
graph.AddEdge(edgePresenter.edge);
}
return graph;
}
private CopyPasteGraph DeserializeCopyBuffer(string copyBuffer)
{
try
{
return JsonUtility.FromJson<CopyPasteGraph>(copyBuffer);
}
catch
{
// ignored. just means copy buffer was not a graph :(
return null;
}
}
private void InsertCopyPasteGraph(CopyPasteGraph graph)
{
if (graph == null || graphAsset == null || graphAsset.graph == null)
return;
var addedNodes = new List<INode>();
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in graph.GetNodes<INode>())
{
var oldGuid = node.guid;
var newGuid = node.RewriteGuid();
nodeGuidMap[oldGuid] = newGuid;
var drawState = node.drawState;
var position = drawState.position;
position.x += 30;
position.y += 30;
drawState.position = position;
node.drawState = drawState;
graphAsset.graph.AddNode(node);
addedNodes.Add(node);
}
// only connect edges within pasted elements, discard
// external edges.
var addedEdges = new List<IEdge>();
foreach (var edge in graph.edges)
{
var outputSlot = edge.outputSlot;
var inputSlot = edge.inputSlot;
Guid remappedOutputNodeGuid;
Guid remappedInputNodeGuid;
if (nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid)
&& nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid))
{
var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId);
var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
addedEdges.Add(graphAsset.graph.Connect(outputSlotRef, inputSlotRef));
}
}
graphAsset.graph.ValidateGraph();
UpdateData();
graphAsset.drawingData.selection = addedNodes.Select(n => n.guid);
}
public void Copy(IEnumerable<GraphElementPresenter> selection)
{
var graph = CreateCopyPasteGraph(selection);
EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(graph, true);
}
public void Duplicate(IEnumerable<GraphElementPresenter> selection)
{
var graph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(selection), true));
InsertCopyPasteGraph(graph);
}
public void Paste()
{
var pastedGraph = DeserializeCopyBuffer(EditorGUIUtility.systemCopyBuffer);
InsertCopyPasteGraph(pastedGraph);
}
public override void AddElement(EdgePresenter edge)
{
Connect(edge.output as GraphAnchorPresenter, edge.input as GraphAnchorPresenter);
}
public override void AddElement(GraphElementPresenter element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
public override void RemoveElement(GraphElementPresenter element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
}
}

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters.meta


fileFormatVersion: 2
guid: abc1ea28384e484438af384084d96c5a
folderAsset: yes
timeCreated: 1484667177
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

17
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphPresenter.cs


using System;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class SerializedGraphPresenter : AbstractGraphPresenter
{
protected SerializedGraphPresenter()
{}
protected override void AddTypeMappings(Action<Type, Type> map)
{
map(typeof(SerializableNode), typeof(GraphNodePresenter));
}
}
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters.meta


fileFormatVersion: 2
guid: 81d8b3117b1148a40bb10d5e6f159ce1
folderAsset: yes
timeCreated: 1484668588
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


using System;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
using RMGUI.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{
public class MaterialGraphPresenter : AbstractGraphPresenter
{
protected MaterialGraphPresenter()
{}
protected override void AddTypeMappings(Action<Type, Type> map)
{
map(typeof(AbstractMaterialNode), typeof(MaterialNodePresenter));
map(typeof(ColorNode), typeof(ColorNodePresenter));
map(typeof(TextureNode), typeof(TextureNodePresenter));
map(typeof(UVNode), typeof(UVNodePresenter));
map(typeof(Vector1Node), typeof(Vector1NodePresenter));
map(typeof(Vector2Node), typeof(Vector2NodePresenter));
map(typeof(Vector3Node), typeof(Vector3NodePresenter));
map(typeof(Vector4Node), typeof(Vector4NodePresenter));
map(typeof(SubGraphNode), typeof(SubgraphNodePresenter));
map(typeof(RemapMasterNode), typeof(RemapMasterNodePresenter));
map(typeof(MasterRemapInputNode), typeof(RemapInputNodePresenter));
map(typeof(AbstractSubGraphIONode), typeof(SubgraphIONodePresenter));
map(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterPresenter));
map(typeof(GraphEdgePresenter), typeof(Edge));
}
}
}

61
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class MaterialNodePresenter : GraphNodePresenter
{
NodePreviewPresenter m_NodePreviewPresenter;
public bool requiresTime
{
get { return node is IRequiresTime; }
}
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_NodePreviewPresenter;
}
}
public override void OnModified(ModificationScope scope)
{
base.OnModified(scope);
// TODO: Propagate callback rather than setting property
if (m_NodePreviewPresenter != null)
m_NodePreviewPresenter.modificationScope = scope;
}
protected MaterialNodePresenter()
{}
public override void Initialize(INode inNode)
{
base.Initialize(inNode);
AddPreview(inNode);
}
private void AddPreview(INode inNode)
{
var materialNode = inNode as AbstractMaterialNode;
if (materialNode == null || !materialNode.hasPreview)
return;
m_NodePreviewPresenter = CreateInstance<NodePreviewPresenter>();
m_NodePreviewPresenter.Initialize(materialNode);
}
}
}

19
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphEdgePresenter.cs


using System;
using RMGUI.GraphView;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class GraphEdgePresenter : EdgePresenter
{
protected GraphEdgePresenter()
{}
public UnityEngine.Graphing.IEdge edge { get; private set; }
public void Initialize(UnityEngine.Graphing.IEdge inEdge)
{
edge = inEdge;
}
}
}

105
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphNodePresenter.cs


using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class GraphNodePresenter : NodePresenter
{
protected GraphNodePresenter()
{}
public INode node { get; private set; }
[SerializeField]
protected List<GraphElementPresenter> m_Controls = new List<GraphElementPresenter>();
public virtual IEnumerable<GraphElementPresenter> elements
{
get { return inputAnchors.Concat(outputAnchors).Cast<GraphElementPresenter>().Concat(m_Controls); }
}
public override bool expanded
{
get { return base.expanded; }
set
{
if (base.expanded != value)
{
base.expanded = value;
DrawState ds = node.drawState;
ds.expanded = value;
node.drawState = ds;
}
}
}
public virtual void OnModified(ModificationScope scope)
{
expanded = node.drawState.expanded;
if (scope == ModificationScope.Topological)
{
var slots = node.GetSlots<ISlot>().ToList();
inputAnchors.RemoveAll(data => !slots.Contains(((GraphAnchorPresenter)data).slot));
outputAnchors.RemoveAll(data => !slots.Contains(((GraphAnchorPresenter)data).slot));
AddSlots(slots.Except(inputAnchors.Concat(outputAnchors).Select(data => ((GraphAnchorPresenter)data).slot)));
inputAnchors.Sort((x, y) => slots.IndexOf(((GraphAnchorPresenter)x).slot) - slots.IndexOf(((GraphAnchorPresenter)y).slot));
outputAnchors.Sort((x, y) => slots.IndexOf(((GraphAnchorPresenter)x).slot) - slots.IndexOf(((GraphAnchorPresenter)y).slot));
}
}
public override void CommitChanges()
{
var drawState = node.drawState;
drawState.position = position;
node.drawState = drawState;
}
protected virtual IEnumerable<GraphElementPresenter> GetControlData()
{
return Enumerable.Empty<GraphElementPresenter>();
}
protected void AddSlots(IEnumerable<ISlot> slots)
{
foreach (var slot in slots)
{
var data = CreateInstance<GraphAnchorPresenter>();
data.Initialize(slot);
if (slot.isOutputSlot)
{
outputAnchors.Add(data);
}
else
{
inputAnchors.Add(data);
}
}
}
// TODO JOCE: Move to OnEnable??
public virtual void Initialize(INode inNode)
{
node = inNode;
if (node == null)
return;
title = inNode.name;
expanded = node.drawState.expanded;
AddSlots(node.GetSlots<ISlot>());
var controlData = GetControlData();
m_Controls.AddRange(controlData);
position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
}
}
}

14
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs


using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
// TODO JOCE: Needed at all?
public class TitleBarButtonPresenter : ScriptableObject
{
public delegate void ClickCallback();
public string text;
public ClickCallback onClick { get; set; }
protected TitleBarButtonPresenter() {}
}
}

69
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarPresenter.cs


using UnityEngine;
using UnityEngine.Graphing;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
namespace UnityEditor.Graphing.Drawing
{
// TODO JOCE: Not sure the title bar requires a presenter at all.
public class TitleBarPresenter : ScriptableObject
{
List<TitleBarButtonPresenter> m_leftItems;
List<TitleBarButtonPresenter> m_rightItems;
IGraphAsset m_graphAsset;
public IEnumerable<TitleBarButtonPresenter> leftItems
{
get { return m_leftItems; }
}
public IEnumerable<TitleBarButtonPresenter> rightItems
{
get { return m_rightItems; }
}
protected TitleBarPresenter()
{
}
public void Initialize(IGraphAsset graphAsset)
{
m_graphAsset = graphAsset;
m_leftItems = new List<TitleBarButtonPresenter>();
m_rightItems = new List<TitleBarButtonPresenter>();
var currentGraphItem = CreateInstance<TitleBarButtonPresenter>();
currentGraphItem.text = graphAsset != null ? graphAsset.GetScriptableObject().name : "";
m_leftItems.Add(currentGraphItem);
var updateAsset = CreateInstance<TitleBarButtonPresenter>();
updateAsset.text = "Update Asset";
updateAsset.onClick += UpdateAsset;
m_leftItems.Add(updateAsset);
var showInProjectItem = CreateInstance<TitleBarButtonPresenter>();
showInProjectItem.text = "Show in project";
showInProjectItem.onClick += OnShowInProjectClick;
m_leftItems.Add(showInProjectItem);
var optionsItem = CreateInstance<TitleBarButtonPresenter>();
optionsItem.text = "Options";
m_rightItems.Add(optionsItem);
}
void OnShowInProjectClick()
{
if (m_graphAsset != null)
EditorGUIUtility.PingObject(m_graphAsset.GetScriptableObject());
}
void UpdateAsset()
{
if (m_graphAsset != null && m_graphAsset is MaterialGraphAsset)
{
var mg = (MaterialGraphAsset)m_graphAsset;
mg.RegenerateInternalShader();
}
}
}
}

329
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public abstract class AbstractGraphDataSource : GraphViewPresenter
{
private readonly TypeMapper m_DataMapper = new TypeMapper(typeof(NodeDrawData));
public IGraphAsset graphAsset { get; private set; }
[SerializeField]
private TitleBarDrawData m_TitleBar;
[SerializeField]
private EditorWindow m_Container;
public TitleBarDrawData titleBar
{
get { return m_TitleBar; }
}
void OnNodeChanged(INode inNode, ModificationScope scope)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theElements = m_Elements.OfType<NodeDrawData>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
drawableNodeData.OnModified(scope);
}
if (scope == ModificationScope.Topological)
UpdateData();
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
if (m_Container != null)
m_Container.Repaint();
}
private void UpdateData()
{
// Find all nodes currently being drawn which are no longer in the graph (i.e. deleted)
var deletedElements = m_Elements
.OfType<NodeDrawData>()
.Where(nd => !graphAsset.graph.GetNodes<INode>().Contains(nd.node))
.OfType<GraphElementPresenter>()
.ToList();
var deletedEdges = m_Elements.OfType<EdgeDrawData>()
.Where(ed => !graphAsset.graph.edges.Contains(ed.edge));
// Find all edges currently being drawn which are no longer in the graph (i.e. deleted)
foreach (var edgeData in deletedEdges)
{
// Make sure to disconnect the node, otherwise new connections won't be allowed for the used slots
edgeData.output.Disconnect(edgeData);
edgeData.input.Disconnect(edgeData);
var toNodeGuid = edgeData.edge.inputSlot.nodeGuid;
var toNode = m_Elements.OfType<NodeDrawData>().FirstOrDefault(nd => nd.node.guid == toNodeGuid);
if (toNode != null)
{
// Make the input node (i.e. right side of the connection) re-render
OnNodeChanged(toNode.node, ModificationScope.Graph);
}
deletedElements.Add(edgeData);
}
// Remove all nodes and edges marked for deletion
foreach (var deletedElement in deletedElements)
{
m_Elements.Remove(deletedElement);
}
var addedNodes = new List<NodeDrawData>();
// Find all new nodes and mark for addition
foreach (var node in graphAsset.graph.GetNodes<INode>())
{
// Check whether node already exists
if (m_Elements.OfType<NodeDrawData>().Any(e => e.node == node))
continue;
var type = m_DataMapper.MapType(node.GetType());
var nodeData = (NodeDrawData)CreateInstance(type);
node.onModified += OnNodeChanged;
nodeData.Initialize(node);
addedNodes.Add(nodeData);
}
// Create edge data for nodes marked for addition
var drawableEdges = new List<EdgeDrawData>();
foreach (var addedNode in addedNodes)
{
var baseNode = addedNode.node;
foreach (var slot in baseNode.GetOutputSlots<ISlot>())
{
var sourceAnchors = addedNode.elements.OfType<AnchorDrawData>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.id));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = addedNodes.FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.elements.OfType<AnchorDrawData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgeData = CreateInstance<EdgeDrawData>();
edgeData.Initialize(edge);
edgeData.output = sourceAnchor;
edgeData.output.Connect(edgeData);
edgeData.input = targetAnchor;
edgeData.input.Connect(edgeData);
drawableEdges.Add(edgeData);
}
}
}
// Add nodes marked for addition
m_Elements.AddRange(addedNodes.OfType<GraphElementPresenter>());
// Find edges in the graph that are not being drawn and create edge data for them
foreach (var edge in graphAsset.graph.edges)
{
if (!m_Elements.OfType<EdgeDrawData>().Any(ed => ed.edge == edge))
{
var fromNode = graphAsset.graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
var fromSlot = fromNode.FindOutputSlot<ISlot>(edge.outputSlot.slotId);
var sourceNode = m_Elements.OfType<NodeDrawData>().FirstOrDefault(x => x.node == fromNode);
var sourceAnchors = sourceNode.elements.OfType<AnchorDrawData>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == fromSlot);
var toNode = graphAsset.graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = m_Elements.OfType<NodeDrawData>().FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.elements.OfType<AnchorDrawData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
OnNodeChanged(targetNode.node, ModificationScope.Graph);
var edgeData = CreateInstance<EdgeDrawData>();
edgeData.Initialize(edge);
edgeData.output = sourceAnchor;
edgeData.output.Connect(edgeData);
edgeData.input = targetAnchor;
edgeData.input.Connect(edgeData);
drawableEdges.Add(edgeData);
}
}
m_Elements.AddRange(drawableEdges.OfType<GraphElementPresenter>());
}
protected abstract void AddTypeMappings(Action<Type, Type> map);
public virtual void Initialize(IGraphAsset graphAsset, EditorWindow container)
{
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);
this.graphAsset = graphAsset;
m_Container = container;
m_TitleBar = CreateInstance<TitleBarDrawData>();
m_TitleBar.Initialize(graphAsset);
if (graphAsset == null)
return;
UpdateData();
}
public void AddNode(INode node)
{
graphAsset.graph.AddNode(node);
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
UpdateData();
}
public void RemoveElements(IEnumerable<NodeDrawData> nodes, IEnumerable<EdgeDrawData> edges)
{
graphAsset.graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graphAsset.graph.ValidateGraph();
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
UpdateData();
}
public void Connect(AnchorDrawData left, AnchorDrawData right)
{
if (left != null && right != null)
{
graphAsset.graph.Connect(left.slot.slotReference, right.slot.slotReference);
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
UpdateData();
}
}
private CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElementPresenter> selection)
{
var graph = new CopyPasteGraph();
foreach (var presenter in selection)
{
var nodeDrawData = presenter as NodeDrawData;
if (nodeDrawData != null)
{
graph.AddNode(nodeDrawData.node);
foreach (var edge in NodeUtils.GetAllEdges(nodeDrawData.node))
graph.AddEdge(edge);
}
var edgeDrawData = presenter as EdgeDrawData;
if (edgeDrawData != null)
graph.AddEdge(edgeDrawData.edge);
}
return graph;
}
private CopyPasteGraph DeserializeCopyBuffer(string copyBuffer)
{
try
{
return JsonUtility.FromJson<CopyPasteGraph>(copyBuffer);
}
catch
{
// ignored. just means copy buffer was not a graph :(
return null;
}
}
private void InsertCopyPasteGraph(CopyPasteGraph graph)
{
if (graph == null || graphAsset == null || graphAsset.graph == null)
return;
var addedNodes = new List<INode>();
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in graph.GetNodes<INode>())
{
var oldGuid = node.guid;
var newGuid = node.RewriteGuid();
nodeGuidMap[oldGuid] = newGuid;
var drawState = node.drawState;
var position = drawState.position;
position.x += 30;
position.y += 30;
drawState.position = position;
node.drawState = drawState;
graphAsset.graph.AddNode(node);
addedNodes.Add(node);
}
// only connect edges within pasted elements, discard
// external edges.
var addedEdges = new List<IEdge>();
foreach (var edge in graph.edges)
{
var outputSlot = edge.outputSlot;
var inputSlot = edge.inputSlot;
Guid remappedOutputNodeGuid;
Guid remappedInputNodeGuid;
if (nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid)
&& nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid))
{
var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId);
var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
addedEdges.Add(graphAsset.graph.Connect(outputSlotRef, inputSlotRef));
}
}
graphAsset.graph.ValidateGraph();
UpdateData();
graphAsset.drawingData.selection = addedNodes.Select(n => n.guid);
}
public void Copy(IEnumerable<GraphElementPresenter> selection)
{
var graph = CreateCopyPasteGraph(selection);
EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(graph, true);
}
public void Duplicate(IEnumerable<GraphElementPresenter> selection)
{
var graph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(selection), true));
InsertCopyPasteGraph(graph);
}
public void Paste()
{
var pastedGraph = DeserializeCopyBuffer(EditorGUIUtility.systemCopyBuffer);
InsertCopyPasteGraph(pastedGraph);
}
public override void AddElement(EdgePresenter edge)
{
Connect(edge.output as AnchorDrawData, edge.input as AnchorDrawData);
}
public override void AddElement(GraphElementPresenter element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
public override void RemoveElement(GraphElementPresenter element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
}
}

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData.meta


fileFormatVersion: 2
guid: 4e974459130fa5f4f9899e83b1e752d5
folderAsset: yes
timeCreated: 1476708485
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

17
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs


using System;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class SerializedGraphDataSource : AbstractGraphDataSource
{
protected SerializedGraphDataSource()
{}
protected override void AddTypeMappings(Action<Type, Type> map)
{
map(typeof(SerializableNode), typeof(NodeDrawData));
}
}
}

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphDataSource.cs


using System;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
using RMGUI.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{
public class MaterialGraphDataSource : AbstractGraphDataSource
{
protected MaterialGraphDataSource()
{}
protected override void AddTypeMappings(Action<Type, Type> map)
{
map(typeof(AbstractMaterialNode), typeof(MaterialNodeDrawData));
map(typeof(ColorNode), typeof(ColorNodeDrawData));
map(typeof(TextureNode), typeof(TextureNodeDrawData));
map(typeof(UVNode), typeof(UVNodeDrawData));
map(typeof(Vector1Node), typeof(Vector1NodeDrawData));
map(typeof(Vector2Node), typeof(Vector2NodeDrawData));
map(typeof(Vector3Node), typeof(Vector3NodeDrawData));
map(typeof(Vector4Node), typeof(Vector4NodeDrawData));
map(typeof(SubGraphNode), typeof(SubgraphNodeDrawData));
map(typeof(RemapMasterNode), typeof(RemapMasterNodeDrawData));
map(typeof(MasterRemapInputNode), typeof(RemapInputNodeDrawData));
map(typeof(AbstractSubGraphIONode), typeof(SubgraphIONodeDrawData));
map(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterDrawData));
map(typeof(EdgeDrawData), typeof(Edge));
}
}
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodeDrawData.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class MaterialNodeDrawData : NodeDrawData
{
NodePreviewDrawData m_NodePreviewDrawData;
public bool requiresTime
{
get { return node is IRequiresTime; }
}
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;
}
}
public override void OnModified(ModificationScope scope)
{
base.OnModified(scope);
// TODO: Propagate callback rather than setting property
if (m_NodePreviewDrawData != null)
m_NodePreviewDrawData.modificationScope = scope;
}
protected MaterialNodeDrawData()
{}
public override void Initialize(INode inNode)
{
base.Initialize(inNode);
AddPreview(inNode);
}
private void AddPreview(INode inNode)
{
var materialNode = inNode as AbstractMaterialNode;
if (materialNode == null || !materialNode.hasPreview)
return;
m_NodePreviewDrawData = CreateInstance<NodePreviewDrawData>();
m_NodePreviewDrawData.Initialize(materialNode);
// m_Children.Add(m_NodePreviewDrawData);
}
}
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData.meta


fileFormatVersion: 2
guid: d53f98da57e19bd47aa9f6aed99ae412
folderAsset: yes
timeCreated: 1464865885
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphPresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawingData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawState.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawingData.cs → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawState.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphDataSource.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterPresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodeDrawData.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodePresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MasterNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapInputNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/RemapMasterNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphIONodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SubgraphNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SurfaceMasterPresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/UVNodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector2NodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector3NodePresenter.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodeDrawData.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector4NodePresenter.cs

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphAnchorPresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphControlPresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphEdgePresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphNodePresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarDrawData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarPresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/TitleBarButtonDrawData.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs.meta

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphAnchorPresenter.cs

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/GraphControlPresenter.cs

正在加载...
取消
保存