mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
Merge 82a102459a1a798b07563fbd31f7becf2bea25f8 into d6effd70f5574369e3415c423ef3e621ea309564
This commit is contained in:
commit
753400c318
@ -121,6 +121,19 @@ namespace XNodeEditor {
|
||||
contextMenu.AddItem(new GUIContent(string.Format("Disconnect({0})", name)), false, () => hoveredPort.Disconnect(index));
|
||||
}
|
||||
contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections());
|
||||
if (hoveredPort.IsDynamic && hoveredPort.IsOutput) {
|
||||
contextMenu.AddItem(new GUIContent($"Remove({hoveredPort.fieldName})"), false, () => {
|
||||
hoveredPort.node.RemoveDynamicPort(hoveredPort);
|
||||
});
|
||||
contextMenu.AddItem(new GUIContent($"Rename({hoveredPort.fieldName})"), false, () => {
|
||||
TextInputPopup dlg = TextInputPopup.Show(hoveredPort.fieldName, "Rename Port", "Port Name");
|
||||
dlg.onAfterClose += () => {
|
||||
XNode.Node node = hoveredPort.node;
|
||||
node.RenameDynamicPort(hoveredPort, dlg.input);
|
||||
EditorUtility.SetDirty(graph);
|
||||
};
|
||||
});
|
||||
}
|
||||
//Get compatible nodes with this port
|
||||
if (NodeEditorPreferences.GetSettings().createFilter) {
|
||||
contextMenu.AddSeparator("");
|
||||
|
||||
71
Scripts/Editor/TextInputPopup.cs
Normal file
71
Scripts/Editor/TextInputPopup.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XNodeEditor {
|
||||
public class TextInputPopup : EditorWindow {
|
||||
private string inputControlName = "";
|
||||
|
||||
public static TextInputPopup current { get; private set; }
|
||||
public string input;
|
||||
public Action onAfterClose;
|
||||
private bool firstFrame = true;
|
||||
|
||||
/// <summary> Show a rename popup for an asset at mouse position. Will trigger reimport of the asset on apply.
|
||||
public static TextInputPopup Show(
|
||||
string textContnet,
|
||||
string title = "Text",
|
||||
string inputControlName = "Input",
|
||||
float width = 200) {
|
||||
TextInputPopup window = EditorWindow.GetWindow<TextInputPopup>(true, title, true);
|
||||
if (current != null) current.Close();
|
||||
current = window;
|
||||
window.inputControlName = inputControlName;
|
||||
window.input = textContnet;
|
||||
window.minSize = new Vector2(100, 44);
|
||||
window.position = new Rect(0, 0, width, 44);
|
||||
window.UpdatePositionToMouse();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void UpdatePositionToMouse() {
|
||||
if (Event.current == null) return;
|
||||
Vector3 mousePoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
|
||||
Rect pos = position;
|
||||
pos.x = mousePoint.x - position.width * 0.5f;
|
||||
pos.y = mousePoint.y - 10;
|
||||
position = pos;
|
||||
}
|
||||
|
||||
private void OnLostFocus() {
|
||||
// Make the popup close on lose focus
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnGUI() {
|
||||
if (firstFrame) {
|
||||
UpdatePositionToMouse();
|
||||
firstFrame = false;
|
||||
}
|
||||
GUI.SetNextControlName(inputControlName);
|
||||
input = EditorGUILayout.TextField(input);
|
||||
EditorGUI.FocusTextInControl(inputControlName);
|
||||
Event e = Event.current;
|
||||
// If input is empty, revert name to default instead
|
||||
if (input != null && input.Trim() != "") {
|
||||
if (GUILayout.Button("Confirm") || (e.isKey && e.keyCode == KeyCode.Return)) {
|
||||
Close();
|
||||
onAfterClose?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
if (e.isKey && e.keyCode == KeyCode.Escape) {
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy() {
|
||||
EditorGUIUtility.editingTextField = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Editor/TextInputPopup.cs.meta
Normal file
11
Scripts/Editor/TextInputPopup.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72aa667b695ba02478ca2a447c37c410
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -181,10 +181,32 @@ namespace XNode {
|
||||
public void RemoveDynamicPort(NodePort port) {
|
||||
if (port == null) throw new ArgumentNullException("port");
|
||||
else if (port.IsStatic) throw new ArgumentException("cannot remove static port");
|
||||
OnRemoveDynamicPort(port);
|
||||
port.ClearConnections();
|
||||
ports.Remove(port.fieldName);
|
||||
}
|
||||
|
||||
/// <summary> Rename an dynamic port</summary>
|
||||
public void RenameDynamicPort(NodePort port, string newFileName) {
|
||||
if(!port.IsDynamic) {
|
||||
return;
|
||||
}
|
||||
XNode.NodePort newPort = AddDynamicOutput(
|
||||
port.ValueType,
|
||||
port.connectionType,
|
||||
port.typeConstraint,
|
||||
newFileName
|
||||
);
|
||||
if (port.Connection != null) {
|
||||
newPort.Connect(port.Connection);
|
||||
}
|
||||
OnRenameDynamicPort(port.fieldName, newFileName);
|
||||
RemoveDynamicPort(port);
|
||||
}
|
||||
|
||||
protected virtual void OnRenameDynamicPort(string oldName, string newName) { }
|
||||
protected virtual void OnRemoveDynamicPort(NodePort port) { }
|
||||
|
||||
/// <summary> Removes all dynamic ports from the node </summary>
|
||||
[ContextMenu("Clear Dynamic Ports")]
|
||||
public void ClearDynamicPorts() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user