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:
commit
81c12c6adf
@ -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)]
|
||||
|
||||
@ -73,25 +73,30 @@ 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);
|
||||
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||
Type type = nodeTypes[i];
|
||||
|
||||
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];
|
||||
|
||||
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);
|
||||
});
|
||||
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.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user