From 111378de945d9c59ef38f0e8a73b5faabea74353 Mon Sep 17 00:00:00 2001
From: guizix <46198159+guizix@users.noreply.github.com>
Date: Thu, 29 Jun 2023 13:09:43 +0800
Subject: [PATCH 1/2] Add Attribute PortTypeOverride
---
Scripts/Attributes/PortTypeOverrideAttribute.cs | 12 ++++++++++++
Scripts/Attributes/PortTypeOverrideAttribute.cs.meta | 11 +++++++++++
2 files changed, 23 insertions(+)
create mode 100644 Scripts/Attributes/PortTypeOverrideAttribute.cs
create mode 100644 Scripts/Attributes/PortTypeOverrideAttribute.cs.meta
diff --git a/Scripts/Attributes/PortTypeOverrideAttribute.cs b/Scripts/Attributes/PortTypeOverrideAttribute.cs
new file mode 100644
index 0000000..316ca2d
--- /dev/null
+++ b/Scripts/Attributes/PortTypeOverrideAttribute.cs
@@ -0,0 +1,12 @@
+using System;
+/// Overrides the ValueType of the Port, to have a ValueType different from the type of its serializable field
+/// Especially useful in Dynamic Port Lists to create Value-Port Pairs with different type.
+[AttributeUsage(AttributeTargets.Field)]
+public class PortTypeOverrideAttribute : Attribute {
+ public Type type;
+ /// Overrides the ValueType of the Port
+ /// ValueType of the Port
+ public PortTypeOverrideAttribute(Type type) {
+ this.type = type;
+ }
+}
diff --git a/Scripts/Attributes/PortTypeOverrideAttribute.cs.meta b/Scripts/Attributes/PortTypeOverrideAttribute.cs.meta
new file mode 100644
index 0000000..a587759
--- /dev/null
+++ b/Scripts/Attributes/PortTypeOverrideAttribute.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1410c1437e863ab4fac7a7428aaca35b
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
From 556547b54137736e9f802cbb6353585afd9e05b6 Mon Sep 17 00:00:00 2001
From: guizix <46198159+guizix@users.noreply.github.com>
Date: Thu, 29 Jun 2023 13:18:29 +0800
Subject: [PATCH 2/2] Enables Port Type Override
When Constructing a NodePort, check the PortTypeOverrideAttribute to change the ValueType of the Port.
---
Scripts/NodePort.cs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs
index b8656ef..1fbc62f 100644
--- a/Scripts/NodePort.cs
+++ b/Scripts/NodePort.cs
@@ -79,6 +79,10 @@ namespace XNode {
_connectionType = (attribs[i] as Node.OutputAttribute).connectionType;
_typeConstraint = (attribs[i] as Node.OutputAttribute).typeConstraint;
}
+ // Override ValueType of the Port
+ if(attribs[i] is PortTypeOverrideAttribute) {
+ ValueType = (attribs[i] as PortTypeOverrideAttribute).type;
+ }
}
}