浏览代码

Add presenter for GraphEditorView, such that the presenter hierarchy makes more sense (also, pass through asset name to graph inspector #31)

/main
Peter Bay Bastian 7 年前
当前提交
8e1d62b6
共有 7 个文件被更改,包括 107 次插入91 次删除
  1. 60
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  2. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs
  3. 37
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  4. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  5. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  6. 48
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs
  7. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs.meta

60
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs


set { m_Selected = value; }
}
public MaterialGraphPresenter CreateDataSource()
{
return CreateInstance<MaterialGraphPresenter>();
}
public GraphView CreateGraphView()
{
return new MaterialGraphView(this);
}
m_GraphEditorView.presenter.UpdateTimeDependentNodes();
m_GraphEditorView.presenter.graphPresenter.UpdateTimeDependentNodes();
m_GraphEditorView = new GraphEditorView(CreateGraphView());
m_GraphEditorView = new GraphEditorView();
var source = CreateDataSource();
source.Initialize(inMemoryAsset, this);
m_GraphEditorView.presenter = source;
var presenter = CreateInstance<GraphEditorPresenter>();
presenter.Initialize(inMemoryAsset, this, selected.name);
m_GraphEditorView.presenter = presenter;
}
void OnDisable()

var e = Event.current;
if (e.type == EventType.ValidateCommand && (
e.commandName == "Copy" && presenter.canCopy
|| e.commandName == "Paste" && presenter.canPaste
|| e.commandName == "Duplicate" && presenter.canDuplicate
|| e.commandName == "Cut" && presenter.canCut
|| (e.commandName == "Delete" || e.commandName == "SoftDelete") && presenter.canDelete))
e.commandName == "Copy" && presenter.graphPresenter.canCopy
|| e.commandName == "Paste" && presenter.graphPresenter.canPaste
|| e.commandName == "Duplicate" && presenter.graphPresenter.canDuplicate
|| e.commandName == "Cut" && presenter.graphPresenter.canCut
|| (e.commandName == "Delete" || e.commandName == "SoftDelete") && presenter.graphPresenter.canDelete))
{
e.Use();
}

if (e.commandName == "Copy")
presenter.Copy();
presenter.graphPresenter.Copy();
presenter.Paste();
presenter.graphPresenter.Paste();
presenter.Duplicate();
presenter.graphPresenter.Duplicate();
presenter.Cut();
presenter.graphPresenter.Cut();
presenter.Delete();
presenter.graphPresenter.Delete();
}
if (e.type == EventType.KeyDown)

if (path.Length == 0)
return;
var graphDataSource = m_GraphEditorView.presenter;
var selected = graphDataSource.elements.Where(e => e.selected).ToArray();
var graphPresenter = m_GraphEditorView.presenter.graphPresenter;
var selected = graphPresenter.elements.Where(e => e.selected).ToArray();
var deserialized = MaterialGraphPresenter.DeserializeCopyBuffer(JsonUtility.ToJson(MaterialGraphPresenter.CreateCopyPasteGraph(selected)));
if (deserialized == null)

return;
var subGraphNode = new SubGraphNode();
graphDataSource.AddNode(subGraphNode);
graphPresenter.AddNode(subGraphNode);
graphDataSource.graph.Connect(edgeMap.Key.outputSlot, new SlotReference(subGraphNode.guid, edgeMap.Value.outputSlot.slotId));
graphPresenter.graph.Connect(edgeMap.Key.outputSlot, new SlotReference(subGraphNode.guid, edgeMap.Value.outputSlot.slotId));
graphDataSource.graph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
graphPresenter.graph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
var toDelete = graphDataSource.elements.Where(e => e.selected).OfType<MaterialNodePresenter>();
graphDataSource.RemoveElements(toDelete, new List<GraphEdgePresenter>());
var toDelete = graphPresenter.elements.Where(e => e.selected).OfType<MaterialNodePresenter>();
graphPresenter.RemoveElements(toDelete, new List<GraphEdgePresenter>());
}
private void UpdateShaderSubGraphOnDisk(string path)

inMemoryAsset.OnEnable();
inMemoryAsset.ValidateGraph();
var source = CreateDataSource();
source.Initialize(inMemoryAsset, this);
m_GraphEditorView.presenter = source;
var presenter = CreateInstance<GraphEditorPresenter>();
presenter.Initialize(inMemoryAsset, this, selected.name);
m_GraphEditorView.presenter = presenter;
titleContent = new GUIContent(selected.name);

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


ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector> m_InspectorFactory;
public void Initialize()
public void Initialize(string graphName)
m_Title = "Name of graph";
m_Title = graphName;
m_InspectorFactory = new ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector>(new[]
{
new TypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector)),

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


[SerializeField]
IMaterialGraphEditWindow m_Container;
[SerializeField]
TitleBarPresenter m_TitleBar;
public TitleBarPresenter titleBar
{
get { return m_TitleBar; }
}
public GraphInspectorPresenter graphInspectorPresenter
{
get { return m_GraphInspectorPresenter; }
set { m_GraphInspectorPresenter = value; }
}
[SerializeField]
GraphInspectorPresenter m_GraphInspectorPresenter;
protected MaterialGraphPresenter()
{
typeMapper = new GraphTypeMapper(typeof(MaterialNodePresenter));

if (scope == ModificationScope.Topological)
UpdateData();
if (m_Container != null)
m_Container.Repaint();
}
void UpdateData()

this.graph = graph;
m_Container = container;
m_TitleBar = CreateInstance<TitleBarPresenter>();
m_TitleBar.Initialize(container);
m_GraphInspectorPresenter = CreateInstance<GraphInspectorPresenter>();
m_GraphInspectorPresenter.Initialize();
if (graph == null)
return;

Connect(edge.output as GraphAnchorPresenter, edge.input as GraphAnchorPresenter);
}
public delegate void OnSelectionChanged(IEnumerable<INode> presenters);
public OnSelectionChanged onSelectionChanged;
//TODO: Fix this
//drawingData.selection = presenters.Select(x => x.node.guid);
m_GraphInspectorPresenter.UpdateSelection(presenters.Select(x => x.node));
if (onSelectionChanged != null)
onSelectionChanged(presenters.Select(x => x.node));
}
public override void AddElement(GraphElementPresenter element)

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


get { return m_GraphView; }
}
private TitleBarView m_TitleBarView;
TitleBarView m_TitleBarView;
// TODO: Create graphView from here rather than have it passed in through constructor
public GraphEditorView(GraphView graphView)
public GraphEditorView()
m_GraphView = graphView;
m_GraphView.name = "GraphView";
m_TitleBarView = new TitleBarView();
m_TitleBarView.name = "TitleBar";
m_TitleBarView = new TitleBarView { name = "TitleBar" };
Add(m_TitleBarView);
m_GraphInspectorView = new GraphInspectorView() { name = "inspector" };
Add(m_TitleBarView);
var contentContainer = new VisualElement() { m_GraphView, m_GraphInspectorView };
contentContainer.name = "content";
Add(contentContainer);
var content = new VisualElement();
content.name = "content";
{
m_GraphView = new MaterialGraphView { name = "GraphView" };
m_GraphInspectorView = new GraphInspectorView() { name = "inspector" };
content.Add(m_GraphView);
content.Add(m_GraphInspectorView);
}
Add(content);
m_GraphView.presenter = m_Presenter;
m_TitleBarView.dataProvider = m_Presenter.titleBar;
m_GraphView.presenter = m_Presenter.graphPresenter;
m_TitleBarView.dataProvider = m_Presenter.titleBarPresenter;
MaterialGraphPresenter m_Presenter;
GraphEditorPresenter m_Presenter;
public MaterialGraphPresenter presenter
public GraphEditorPresenter presenter
{
get { return m_Presenter; }
set

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

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs


public sealed class MaterialGraphView : GraphView
{
[SerializeField]
private GraphDrawingData m_DrawingData = new GraphDrawingData();
GraphDrawingData m_DrawingData = new GraphDrawingData();
public GraphDrawingData drawingData
{

public MaterialGraphView(EditorWindow editorWindow)
public MaterialGraphView()
{
this.AddManipulator(new ContentZoomer());
this.AddManipulator(new ContentDragger());

void PropagateSelection()
{
var graphDataSource = GetPresenter<MaterialGraphPresenter>();
if (graphDataSource == null)
var graphPresenter = GetPresenter<MaterialGraphPresenter>();
if (graphPresenter == null)
graphDataSource.UpdateSelection(selectedNodes);
graphPresenter.UpdateSelection(selectedNodes);
}
public override void AddToSelection(ISelectable selectable)

48
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs


using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.MaterialGraph.Drawing
{
public class GraphEditorPresenter : ScriptableObject
{
[SerializeField]
TitleBarPresenter m_TitleBarPresenter;
[SerializeField]
MaterialGraphPresenter m_GraphPresenter;
[SerializeField]
GraphInspectorPresenter m_GraphInspectorPresenter;
public TitleBarPresenter titleBarPresenter
{
get { return m_TitleBarPresenter; }
set { m_TitleBarPresenter = value; }
}
public MaterialGraphPresenter graphPresenter
{
get { return m_GraphPresenter; }
set { m_GraphPresenter = value; }
}
public GraphInspectorPresenter graphInspectorPresenter
{
get { return m_GraphInspectorPresenter; }
set { m_GraphInspectorPresenter = value; }
}
public void Initialize(IGraph graph, IMaterialGraphEditWindow container, string graphName)
{
m_TitleBarPresenter = CreateInstance<TitleBarPresenter>();
m_TitleBarPresenter.Initialize(container);
m_GraphInspectorPresenter = CreateInstance<GraphInspectorPresenter>();
m_GraphInspectorPresenter.Initialize(graphName);
m_GraphPresenter = CreateInstance<MaterialGraphPresenter>();
m_GraphPresenter.Initialize(graph, container);
m_GraphPresenter.onSelectionChanged += m_GraphInspectorPresenter.UpdateSelection;
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs.meta


fileFormatVersion: 2
guid: fabca78859dd4417a90ce77e22bee37c
timeCreated: 1504007101
正在加载...
取消
保存