1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Merge 0f372ea7f3121a19edfb2177a7da423e1a554466 into 1ddfdeb1d39d2f3472618948e429f23baeaffe52

This commit is contained in:
neko1990 2017-11-19 17:02:11 +00:00 committed by GitHub
commit 81c12c6adf
2 changed files with 28 additions and 16 deletions

View File

@ -21,7 +21,7 @@ namespace XNodeEditor {
OnBodyGUI();
}
public void OnHeaderGUI() {
public virtual void OnHeaderGUI() {
GUI.color = Color.white;
string title = NodeEditorUtilities.PrettifyCamelCase(target.name);
GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30));
@ -45,6 +45,13 @@ namespace XNodeEditor {
public virtual int GetWidth() {
return 200;
}
public virtual void ShowNodeContextMenu(Node node)
{
GenericMenu contextMenu = new GenericMenu();
contextMenu.AddItem(new GUIContent("Remove"), false, () => target.graph.RemoveNode(node));
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
}
}
[AttributeUsage(AttributeTargets.Class)]

View File

@ -73,13 +73,19 @@ namespace XNodeEditor {
/// <summary> Show right-click context menu </summary>
public void ShowContextMenu() {
if (hoveredNode != null) {
GetNodeEditor(hoveredNode.GetType()).ShowNodeContextMenu(hoveredNode);
}
else
{
ShowGraphContextMenu();
}
}
public virtual void ShowGraphContextMenu()
{
GenericMenu contextMenu = new GenericMenu();
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
if (hoveredNode != null) {
Node node = hoveredNode;
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node));
} else {
for (int i = 0; i < nodeTypes.Length; i++) {
Type type = nodeTypes[i];
@ -92,7 +98,6 @@ namespace XNodeEditor {
CreateNode(type, pos);
});
}
}
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
}