mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
1. custom header 2. custom contextmenu
This commit is contained in:
parent
1ddfdeb1d3
commit
0f372ea7f3
@ -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)]
|
||||||
|
|||||||
@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user