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(); OnBodyGUI();
} }
public void OnHeaderGUI() { public virtual void OnHeaderGUI() {
GUI.color = Color.white; GUI.color = Color.white;
string title = NodeEditorUtilities.PrettifyCamelCase(target.name); string title = NodeEditorUtilities.PrettifyCamelCase(target.name);
GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30));
@ -45,6 +45,13 @@ namespace XNodeEditor {
public virtual int GetWidth() { public virtual int GetWidth() {
return 200; 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)] [AttributeUsage(AttributeTargets.Class)]

View File

@ -73,25 +73,30 @@ namespace XNodeEditor {
/// <summary> Show right-click context menu </summary> /// <summary> Show right-click context menu </summary>
public void ShowContextMenu() { public void ShowContextMenu() {
if (hoveredNode != null) {
GetNodeEditor(hoveredNode.GetType()).ShowNodeContextMenu(hoveredNode);
}
else
{
ShowGraphContextMenu();
}
}
public virtual void ShowGraphContextMenu()
{
GenericMenu contextMenu = new GenericMenu(); GenericMenu contextMenu = new GenericMenu();
Vector2 pos = WindowToGridPosition(Event.current.mousePosition); Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
for (int i = 0; i < nodeTypes.Length; i++) {
Type type = nodeTypes[i];
if (hoveredNode != null) { string name = nodeTypes[i].ToString().Replace('.', '/');
Node node = hoveredNode; Node.CreateNodeMenuAttribute attrib;
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node)); if (NodeEditorUtilities.GetAttrib(type, out attrib)) {
} else { name = attrib.menuName;
for (int i = 0; i < nodeTypes.Length; i++) {
Type type = nodeTypes[i];
string name = nodeTypes[i].ToString().Replace('.', '/');
Node.CreateNodeMenuAttribute attrib;
if (NodeEditorUtilities.GetAttrib(type, out attrib)) {
name = attrib.menuName;
}
contextMenu.AddItem(new GUIContent(name), false, () => {
CreateNode(type, pos);
});
} }
contextMenu.AddItem(new GUIContent(name), false, () => {
CreateNode(type, pos);
});
} }
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
} }