浏览代码

Duplication support for graph nodes

/main
Peter Bay Bastian 8 年前
当前提交
1770fee9
共有 2 个文件被更改,包括 36 次插入11 次删除
  1. 36
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs
  2. 11
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs

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


}
}
public void Copy(IEnumerable<GraphElementPresenter> selection)
private CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElementPresenter> selection)
{
var graph = new CopyPasteGraph();
foreach (var presenter in selection)

if (edgeDrawData != null)
graph.AddEdge(edgeDrawData.edge);
}
EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(graph, true);
return graph;
private CopyPasteGraph DeserializeCopyBuffer()
private CopyPasteGraph DeserializeCopyBuffer(string copyBuffer)
return JsonUtility.FromJson<CopyPasteGraph>(EditorGUIUtility.systemCopyBuffer);
return JsonUtility.FromJson<CopyPasteGraph>(copyBuffer);
}
catch
{

}
public void Paste()
private void InsertCopyPasteGraph(CopyPasteGraph graph)
var pastedGraph = DeserializeCopyBuffer();
if (pastedGraph == null || graphAsset == null || graphAsset.graph == null)
if (graph == null || graphAsset == null || graphAsset.graph == null)
foreach (var node in pastedGraph.GetNodes<INode>())
foreach (var node in graph.GetNodes<INode>())
{
var oldGuid = node.guid;
var newGuid = node.RewriteGuid();

// external edges.
var addedEdges = new List<IEdge>();
foreach (var edge in pastedGraph.edges)
foreach (var edge in graph.edges)
{
var outputSlot = edge.outputSlot;
var inputSlot = edge.inputSlot;

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)

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


{Event.KeyboardEvent("#tab"), FramePrev},
{Event.KeyboardEvent("tab"), FrameNext},
{Event.KeyboardEvent("#c"), CopySelection},
{Event.KeyboardEvent("#v"), Paste}
{Event.KeyboardEvent("#v"), Paste},
{Event.KeyboardEvent("#d"), DuplicateSelection}
}));
AddManipulator(new ClickGlobalSelector());

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

正在加载...
取消
保存