浏览代码

[mat graph]Readd the delete operator.

/main
Tim Cooper 8 年前
当前提交
8dc43619
共有 2 个文件被更改,包括 36 次插入0 次删除
  1. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
  2. 28
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs

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


UpdateData();
}
public void RemoveNodes(IEnumerable<MaterialNodeData> nodes)
{
var toDelete = nodes.Select(x => x.node).ToList();
graphAsset.graph.RemoveElements(toDelete, new List<IEdge> (){});
graphAsset.graph.ValidateGraph();
UpdateData ();
}
public IEnumerable<GraphElementData> elements
{
get { return m_Elements; }

28
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs


using System;
using System.Linq;
using System.Reflection;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;

using UnityEngine.RMGUI;
using System.Collections.Generic;
using Object = UnityEngine.Object;
namespace UnityEditor.Graphing.Drawing

{
public MaterialGraphView()
{
// Shortcut handler to delete elements
var dictionary = new Dictionary<Event, ShortcutDelegate>();
dictionary[Event.KeyboardEvent("delete")] = DeleteSelection;
contentViewContainer.AddManipulator(new ShortcutHandler(dictionary));
AddManipulator(new ContentZoomer());
AddManipulator(new ContentDragger());
AddManipulator(new RectangleSelector());

dataMapper[typeof(MaterialNodeData)] = typeof(MaterialGraphNode);
dataMapper[typeof(NodeAnchorData)] = typeof(NodeAnchor);
}
private EventPropagation DeleteSelection()
{
var nodalViewData = dataSource as MaterialGraphDataSource;
if (nodalViewData == null)
return EventPropagation.Stop;
// TODO We will want to move this up to GraphView
var elementsToRemove = new List<MaterialNodeData>();
foreach (var selectedElement in selection.OfType<MaterialGraphNode>())
{
var nodeData = selectedElement.dataProvider as MaterialNodeData;
if (nodeData != null)
elementsToRemove.Add(nodeData);
}
nodalViewData.RemoveNodes(elementsToRemove);
return EventPropagation.Stop;
}
public virtual bool CanAddToNodeMenu(Type type)

正在加载...
取消
保存