您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
44 行
1.6 KiB
44 行
1.6 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using RMGUI.GraphView;
|
|
using UnityEngine;
|
|
using UnityEngine.RMGUI;
|
|
|
|
namespace UnityEditor.Graphing.Drawing
|
|
{
|
|
[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss")]
|
|
public class SerializableGraphView : GraphView
|
|
{
|
|
public SerializableGraphView()
|
|
{
|
|
// Shortcut handler to delete elements
|
|
var dictionary = new Dictionary<Event, ShortcutDelegate>();
|
|
dictionary[Event.KeyboardEvent("delete")] = DeleteSelection;
|
|
AddManipulator(new ShortcutHandler(dictionary));
|
|
|
|
AddManipulator(new ContentZoomer());
|
|
AddManipulator(new ContentDragger());
|
|
AddManipulator(new RectangleSelector());
|
|
AddManipulator(new SelectionDragger());
|
|
AddManipulator(new ClickSelector());
|
|
AddDecorator(new GridBackground());
|
|
|
|
dataMapper[typeof(NodeDrawData)] = typeof(NodeDrawer);
|
|
dataMapper[typeof(HeaderDrawData)] = typeof(HeaderDrawer);
|
|
}
|
|
|
|
private EventPropagation DeleteSelection()
|
|
{
|
|
var nodalViewData = dataSource as AbstractGraphDataSource;
|
|
if (nodalViewData == null)
|
|
return EventPropagation.Stop;
|
|
|
|
nodalViewData.RemoveElements(
|
|
selection.OfType<NodeDrawer>().Select(x => x.dataProvider as NodeDrawData),
|
|
selection.OfType<Edge>().Select(x => x.dataProvider as EdgeDrawData)
|
|
);
|
|
|
|
return EventPropagation.Stop;
|
|
}
|
|
}
|
|
}
|