Skip to content

Commit

Permalink
Merge pull request #368 from guizix/PortTypeOverride
Browse files Browse the repository at this point in the history
Ability to override ValueType of a Port
  • Loading branch information
Siccity authored Jul 10, 2023
2 parents 5967cef + 556547b commit 82f7887
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Scripts/Attributes/PortTypeOverrideAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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;
}
}
11 changes: 11 additions & 0 deletions Scripts/Attributes/PortTypeOverrideAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Scripts/NodePort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public NodePort(FieldInfo fieldInfo) {
_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;
}
}
}

Expand Down

0 comments on commit 82f7887

Please sign in to comment.