1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00

Merge d41a8871112dba5458110cdd663a98068ae45188 into d6effd70f5574369e3415c423ef3e621ea309564

This commit is contained in:
Ittipon Teerapruettikulchai 2025-03-03 01:28:26 +03:00 committed by GitHub
commit 0c5b020efc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 35 deletions

View File

@ -1,5 +1,7 @@
using UnityEngine;
/// <summary> Draw enums correctly within nodes. Without it, enums show up at the wrong positions. </summary>
/// <remarks> Enums with this attribute are not detected by EditorGui.ChangeCheck due to waiting before executing </remarks>
public class NodeEnumAttribute : PropertyAttribute { }
namespace XNode {
/// <summary> Draw enums correctly within nodes. Without it, enums show up at the wrong positions. </summary>
/// <remarks> Enums with this attribute are not detected by EditorGui.ChangeCheck due to waiting before executing </remarks>
public class NodeEnumAttribute : PropertyAttribute { }
}

View File

@ -1,12 +1,17 @@
using System;
/// <summary> Overrides the ValueType of the Port, to have a ValueType different from the type of its serializable field </summary>
/// <remarks> Especially useful in Dynamic Port Lists to create Value-Port Pairs with different type. </remarks>
[AttributeUsage(AttributeTargets.Field)]
public class PortTypeOverrideAttribute : Attribute {
public Type type;
/// <summary> Overrides the ValueType of the Port </summary>
/// <param name="type">ValueType of the Port</param>
public PortTypeOverrideAttribute(Type type) {
this.type = type;
namespace XNode {
/// <summary> Overrides the ValueType of the Port, to have a ValueType different from the type of its serializable field </summary>
/// <remarks> Especially useful in Dynamic Port Lists to create Value-Port Pairs with different type. </remarks>
[AttributeUsage(AttributeTargets.Field)]
public class PortTypeOverrideAttribute : Attribute
{
public Type type;
/// <summary> Overrides the ValueType of the Port </summary>
/// <param name="type">ValueType of the Port</param>
public PortTypeOverrideAttribute(Type type)
{
this.type = type;
}
}
}
}

View File

@ -250,12 +250,15 @@ namespace XNode {
#endregion
/// <summary> Called after a connection between two <see cref="NodePort"/>s is created </summary>
/// <param name="from">Output</param> <param name="to">Input</param>
public virtual void OnCreateConnection(NodePort from, NodePort to) { }
/// <param name="from">Output</param>
/// <param name="to">Input</param>
/// <param name="swapping">Creating while swapping or not?</param>
public virtual void OnCreateConnection(NodePort from, NodePort to, bool swapping) { }
/// <summary> Called after a connection is removed from this port </summary>
/// <param name="port">Output or Input</param>
public virtual void OnRemoveConnection(NodePort port) { }
/// <param name="swapping">Removing while swapping or not?</param>
public virtual void OnRemoveConnection(NodePort port, bool swapping) { }
/// <summary> Disconnect everything from this node </summary>
public void ClearConnections() {

View File

@ -162,7 +162,15 @@ namespace XNode {
case "Microsoft":
continue;
default:
nodeTypes.AddRange(assembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)).ToArray());
try
{
nodeTypes.AddRange(assembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)).ToArray());
}
catch (System.Exception ex)
{
Debug.LogError($"Catched exception when building {assemblyName} caches");
Debug.LogException(ex);
}
break;
}
}

View File

@ -207,7 +207,8 @@ namespace XNode {
/// <summary> Connect this <see cref="NodePort"/> to another </summary>
/// <param name="port">The <see cref="NodePort"/> to connect to</param>
public void Connect(NodePort port) {
/// <param name="swapping">Creating while swapping or not?</param>
public void Connect(NodePort port, bool swapping = false) {
if (connections == null) connections = new List<PortConnection>();
if (port == null) { Debug.LogWarning("Cannot connect to null port"); return; }
if (port == this) { Debug.LogWarning("Cannot connect port to self."); return; }
@ -217,13 +218,13 @@ namespace XNode {
UnityEditor.Undo.RecordObject(node, "Connect Port");
UnityEditor.Undo.RecordObject(port.node, "Connect Port");
#endif
if (port.connectionType == Node.ConnectionType.Override && port.ConnectionCount != 0) { port.ClearConnections(); }
if (connectionType == Node.ConnectionType.Override && ConnectionCount != 0) { ClearConnections(); }
if (port.connectionType == Node.ConnectionType.Override && port.ConnectionCount != 0) { port.ClearConnections(swapping); }
if (connectionType == Node.ConnectionType.Override && ConnectionCount != 0) { ClearConnections(swapping); }
connections.Add(new PortConnection(port));
if (port.connections == null) port.connections = new List<PortConnection>();
if (!port.IsConnectedTo(this)) port.connections.Add(new PortConnection(this));
node.OnCreateConnection(this, port);
port.node.OnCreateConnection(this, port);
node.OnCreateConnection(this, port, swapping);
port.node.OnCreateConnection(this, port, swapping);
}
public List<NodePort> GetConnections() {
@ -289,7 +290,7 @@ namespace XNode {
}
/// <summary> Disconnect this port from another port </summary>
public void Disconnect(NodePort port) {
public void Disconnect(NodePort port, bool swapping = false) {
// Remove this ports connection to the other
for (int i = connections.Count - 1; i >= 0; i--) {
if (connections[i].Port == port) {
@ -302,16 +303,16 @@ namespace XNode {
if (port.connections[i].Port == this) {
port.connections.RemoveAt(i);
// Trigger OnRemoveConnection from this side port
port.node.OnRemoveConnection(port);
port.node.OnRemoveConnection(port, swapping);
}
}
}
// Trigger OnRemoveConnection
node.OnRemoveConnection(this);
node.OnRemoveConnection(this, swapping);
}
/// <summary> Disconnect this port from another port </summary>
public void Disconnect(int i) {
public void Disconnect(int i, bool swapping = false) {
// Remove the other ports connection to this port
NodePort otherPort = connections[i].Port;
if (otherPort != null) {
@ -321,13 +322,13 @@ namespace XNode {
connections.RemoveAt(i);
// Trigger OnRemoveConnection
node.OnRemoveConnection(this);
if (otherPort != null) otherPort.node.OnRemoveConnection(otherPort);
node.OnRemoveConnection(this, swapping);
if (otherPort != null) otherPort.node.OnRemoveConnection(otherPort, swapping);
}
public void ClearConnections() {
public void ClearConnections(bool swapping = false) {
while (connections.Count > 0) {
Disconnect(connections[0].Port);
Disconnect(connections[0].Port, swapping);
}
}
@ -352,16 +353,16 @@ namespace XNode {
for (int i = 0; i < bConnectionCount; i++)
targetPortConnections.Add(targetPort.connections[i].Port);
ClearConnections();
targetPort.ClearConnections();
ClearConnections(true);
targetPort.ClearConnections(true);
// Add port connections to targetPort
for (int i = 0; i < portConnections.Count; i++)
targetPort.Connect(portConnections[i]);
targetPort.Connect(portConnections[i], true);
// Add target port connections to this one
for (int i = 0; i < targetPortConnections.Count; i++)
Connect(targetPortConnections[i]);
Connect(targetPortConnections[i], true);
}
@ -385,7 +386,7 @@ namespace XNode {
NodePort otherPort = connection.Port;
Connect(otherPort);
}
ClearConnections();
ClearConnections(false);
}
/// <summary> Swap connected nodes from the old list with nodes from the new list </summary>