From d705c8bdd1e6529c0cf9330b3f328551be18e43e Mon Sep 17 00:00:00 2001 From: Icarus <1375400884@qq.com> Date: Sat, 12 Sep 2020 02:33:53 +0800 Subject: [PATCH] !B(Node Port) Now the conversion judgment will be made, if it can be converted, it is considered to be allowed --- Scripts/NodePort.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index fea85c8..4cfca4d 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Reflection; using UnityEngine; @@ -291,12 +292,25 @@ namespace XNode { else output = port; // If there isn't one of each, they can't connect if (input == null || output == null) return false; + // Check input type constraints + if (input.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType) + // Judgment conversion + && TypeDescriptor.GetConverter(input.ValueType).CanConvertTo(output.ValueType)) return false; + if (input.typeConstraint == XNode.Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false; - if (input.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false; + if (input.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType) + // Judgment conversion + && TypeDescriptor.GetConverter(output.ValueType).CanConvertTo(input.ValueType)) return false; + // Check output type constraints - if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false; + if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType) + // Judgment conversion + && TypeDescriptor.GetConverter(input.ValueType).CanConvertTo(output.ValueType)) return false; + if (output.typeConstraint == XNode.Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false; - if (output.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false; + if (output.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType) + // Judgment conversion + && TypeDescriptor.GetConverter(output.ValueType).CanConvertTo(input.ValueType)) return false; // Success return true; }