mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Merge branch 'master-upstream'
This commit is contained in:
commit
04343032e6
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
Support xNode on [Ko-fi](https://ko-fi.com/Z8Z5DYWA) or [Patreon](https://www.patreon.com/thorbrigsted)
|
Support xNode on [Ko-fi](https://ko-fi.com/Z8Z5DYWA) or [Patreon](https://www.patreon.com/thorbrigsted)
|
||||||
|
|
||||||
|
For full Odin support, consider using [KAJed82's fork](https://github.com/KAJed82/xNode)
|
||||||
|
|
||||||
### xNode
|
### xNode
|
||||||
Thinking of developing a node-based plugin? Then this is for you. You can download it as an archive and unpack to a new unity project, or connect it as git submodule.
|
Thinking of developing a node-based plugin? Then this is for you. You can download it as an archive and unpack to a new unity project, or connect it as git submodule.
|
||||||
|
|
||||||
|
|||||||
@ -221,7 +221,7 @@ namespace XNodeEditor {
|
|||||||
//Port drag release
|
//Port drag release
|
||||||
if (IsDraggingPort) {
|
if (IsDraggingPort) {
|
||||||
// If connection is valid, save it
|
// If connection is valid, save it
|
||||||
if (draggedOutputTarget != null && draggedOutput.CanConnectTo(draggedOutputTarget)) {
|
if (draggedOutputTarget != null && graphEditor.CanConnect(draggedOutput, draggedOutputTarget)) {
|
||||||
XNode.Node node = draggedOutputTarget.node;
|
XNode.Node node = draggedOutputTarget.node;
|
||||||
if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget);
|
if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget);
|
||||||
|
|
||||||
@ -553,12 +553,9 @@ namespace XNodeEditor {
|
|||||||
public void AutoConnect(XNode.Node node) {
|
public void AutoConnect(XNode.Node node) {
|
||||||
if (autoConnectOutput == null) return;
|
if (autoConnectOutput == null) return;
|
||||||
|
|
||||||
// Find input port of same type
|
// Find compatible input port
|
||||||
XNode.NodePort inputPort = node.Ports.FirstOrDefault(x => x.IsInput && x.ValueType == autoConnectOutput.ValueType);
|
XNode.NodePort inputPort = node.Ports.FirstOrDefault(x => x.IsInput && graphEditor.CanConnect(autoConnectOutput, x));
|
||||||
// Fallback to input port
|
if (inputPort != null) autoConnectOutput.Connect(inputPort);
|
||||||
if (inputPort == null) inputPort = node.Ports.FirstOrDefault(x => x.IsInput);
|
|
||||||
// Autoconnect if connection is compatible
|
|
||||||
if (inputPort != null && inputPort.CanConnectTo(autoConnectOutput)) autoConnectOutput.Connect(inputPort);
|
|
||||||
|
|
||||||
// Save changes
|
// Save changes
|
||||||
EditorUtility.SetDirty(graph);
|
EditorUtility.SetDirty(graph);
|
||||||
|
|||||||
@ -394,6 +394,7 @@ namespace XNodeEditor {
|
|||||||
};
|
};
|
||||||
list.onReorderCallback =
|
list.onReorderCallback =
|
||||||
(ReorderableList rl) => {
|
(ReorderableList rl) => {
|
||||||
|
serializedObject.Update();
|
||||||
bool hasRect = false;
|
bool hasRect = false;
|
||||||
bool hasNewRect = false;
|
bool hasNewRect = false;
|
||||||
Rect rect = Rect.zero;
|
Rect rect = Rect.zero;
|
||||||
|
|||||||
@ -59,6 +59,13 @@ namespace XNodeEditor {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called before connecting two ports in the graph view to see if the output port is compatible with the input port
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool CanConnect(XNode.NodePort output, XNode.NodePort input) {
|
||||||
|
return output.CanConnectTo(input);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add items for the context menu when right-clicking this node.
|
/// Add items for the context menu when right-clicking this node.
|
||||||
/// Override to add custom menu items.
|
/// Override to add custom menu items.
|
||||||
@ -96,7 +103,7 @@ namespace XNodeEditor {
|
|||||||
if (disallowed) menu.AddItem(new GUIContent(path), false, null);
|
if (disallowed) menu.AddItem(new GUIContent(path), false, null);
|
||||||
else menu.AddItem(new GUIContent(path), false, () => {
|
else menu.AddItem(new GUIContent(path), false, () => {
|
||||||
XNode.Node node = CreateNode(type, pos);
|
XNode.Node node = CreateNode(type, pos);
|
||||||
NodeEditorWindow.current.AutoConnect(node);
|
if (node != null) NodeEditorWindow.current.AutoConnect(node); // handle null nodes to avoid nullref exceptions
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
@ -206,6 +213,7 @@ namespace XNodeEditor {
|
|||||||
public virtual XNode.Node CreateNode(Type type, Vector2 position) {
|
public virtual XNode.Node CreateNode(Type type, Vector2 position) {
|
||||||
Undo.RecordObject(target, "Create Node");
|
Undo.RecordObject(target, "Create Node");
|
||||||
XNode.Node node = target.AddNode(type);
|
XNode.Node node = target.AddNode(type);
|
||||||
|
if (node == null) return null; // handle null nodes to avoid nullref exceptions
|
||||||
Undo.RegisterCreatedObjectUndo(node, "Create Node");
|
Undo.RegisterCreatedObjectUndo(node, "Create Node");
|
||||||
node.position = position;
|
node.position = position;
|
||||||
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);
|
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);
|
||||||
@ -221,7 +229,7 @@ namespace XNodeEditor {
|
|||||||
XNode.Node node = target.CopyNode(original);
|
XNode.Node node = target.CopyNode(original);
|
||||||
Undo.RegisterCreatedObjectUndo(node, "Duplicate Node");
|
Undo.RegisterCreatedObjectUndo(node, "Duplicate Node");
|
||||||
node.name = original.name;
|
node.name = original.name;
|
||||||
AssetDatabase.AddObjectToAsset(node, target);
|
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) AssetDatabase.AddObjectToAsset(node, target);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,8 +53,10 @@ namespace XNodeEditor {
|
|||||||
if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) {
|
if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) {
|
||||||
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
|
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
|
||||||
NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
|
NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
|
||||||
AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
|
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) {
|
||||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
|
AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
|
||||||
|
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
|
||||||
|
}
|
||||||
Close();
|
Close();
|
||||||
target.TriggerOnValidate();
|
target.TriggerOnValidate();
|
||||||
}
|
}
|
||||||
@ -64,8 +66,10 @@ namespace XNodeEditor {
|
|||||||
if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
|
if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
|
||||||
target.name = input;
|
target.name = input;
|
||||||
NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
|
NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
|
||||||
AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
|
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) {
|
||||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
|
AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
|
||||||
|
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
|
||||||
|
}
|
||||||
Close();
|
Close();
|
||||||
target.TriggerOnValidate();
|
target.TriggerOnValidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,6 +70,9 @@ namespace XNode {
|
|||||||
for (int i = 0; i < reconnectConnections.Count; i++) {
|
for (int i = 0; i < reconnectConnections.Count; i++) {
|
||||||
NodePort connection = reconnectConnections[i];
|
NodePort connection = reconnectConnections[i];
|
||||||
if (connection == null) continue;
|
if (connection == null) continue;
|
||||||
|
// CAVEAT: Ports connected under special conditions defined in graphEditor.CanConnect overrides will not auto-connect.
|
||||||
|
// To fix this, this code would need to be moved to an editor script and call graphEditor.CanConnect instead of port.CanConnectTo.
|
||||||
|
// This is only a problem in the rare edge case where user is using non-standard CanConnect overrides and changes port type of an already connected port
|
||||||
if (port.CanConnectTo(connection)) port.Connect(connection);
|
if (port.CanConnectTo(connection)) port.Connect(connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +207,7 @@ namespace XNode {
|
|||||||
portDataCache[nodeType].Add(new NodePort(fieldInfo[i]));
|
portDataCache[nodeType].Add(new NodePort(fieldInfo[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(formerlySerializedAsAttribute != null) {
|
if (formerlySerializedAsAttribute != null) {
|
||||||
if (formerlySerializedAsCache == null) formerlySerializedAsCache = new Dictionary<System.Type, Dictionary<string, string>>();
|
if (formerlySerializedAsCache == null) formerlySerializedAsCache = new Dictionary<System.Type, Dictionary<string, string>>();
|
||||||
if (!formerlySerializedAsCache.ContainsKey(nodeType)) formerlySerializedAsCache.Add(nodeType, new Dictionary<string, string>());
|
if (!formerlySerializedAsCache.ContainsKey(nodeType)) formerlySerializedAsCache.Add(nodeType, new Dictionary<string, string>());
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user