浏览代码

Move more stuff from MaterialGraphPresenter, also introduce proper constructor

/main
Peter Bay Bastian 7 年前
当前提交
46b505fb
共有 3 个文件被更改,包括 21 次插入29 次删除
  1. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  2. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

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


graphPresenter.graph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
}
var toDelete = graphView.selection.OfType<MaterialNodeView>();
graphPresenter.RemoveElements(toDelete, new List<Edge>());
graphPresenter.graph.RemoveElements(
graphView.selection.OfType<MaterialNodeView>().Select(x => x.node as INode),
Enumerable.Empty<IEdge>());
graphPresenter.graph.ValidateGraph();
}
void UpdateAbstractSubgraphOnDisk<T>(string path) where T : AbstractSubGraph

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


public IGraph graph { get; private set; }
void OnNodeChanged(INode inNode, ModificationScope scope)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theViews = m_GraphView.nodes.ToList().OfType<MaterialNodeView>();
var viewsFound = theViews.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in viewsFound)
drawableNodeData.OnModified(scope);
}
// We might need to do something here
// if (scope == ModificationScope.Topological)
}
public void Initialize(MaterialGraphView graphView, IGraph graph, PreviewSystem previewSystem)
public MaterialGraphPresenter(MaterialGraphView graphView, IGraph graph, PreviewSystem previewSystem)
{
m_GraphView = graphView;
m_PreviewSystem = previewSystem;

foreach (var edge in graph.edges)
EdgeAdded(new EdgeAddedGraphChange(edge));
this.graph.onChange += OnChange;
this.graph.onChange += OnGraphChange;
}
void OnNodeChanged(INode inNode, ModificationScope scope)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theViews = m_GraphView.nodes.ToList().OfType<MaterialNodeView>();
var viewsFound = theViews.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in viewsFound)
drawableNodeData.OnModified(scope);
}
void OnChange(GraphChange change)
void OnGraphChange(GraphChange change)
{
var nodeAdded = change as NodeAddedGraphChange;
if (nodeAdded != null)

edgeView.input.Disconnect(edgeView);
m_GraphView.RemoveElement(edgeView);
}
}
public void RemoveElements(IEnumerable<MaterialNodeView> nodes, IEnumerable<Edge> edges)
{
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.userData as IEdge));
graph.ValidateGraph();
}
}
}

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


}
Add(m_ToolbarView);
m_GraphPresenter = new MaterialGraphPresenter();
var content = new VisualElement { name = "content" };
{

m_GraphView.graphViewChanged = GraphViewChanged;
}
m_GraphPresenter.Initialize(m_GraphView, graph, previewSystem);
m_GraphPresenter = new MaterialGraphPresenter(m_GraphView, graph, previewSystem);
Add(content);
}

正在加载...
取消
保存