|
|
|
|
|
|
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) |
|
|
|