From 63c3ae2f7d532d253bb9d7515845a83788f37249 Mon Sep 17 00:00:00 2001 From: Simon Rodriguez Date: Wed, 6 Nov 2019 13:12:04 +0100 Subject: [PATCH] Fixed TypeConstraint.Inherited, and added TypeConstraint.InheritedInverse (#205) * Added TypeConstraint to check inheritance but inverted. * Flipped output inherited type constraints, edited comments --- Scripts/Node.cs | 4 +++- Scripts/NodePort.cs | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 27e32c7..a07679a 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -45,10 +45,12 @@ namespace XNode { public enum TypeConstraint { /// Allow all types of input None, - /// Allow similar and inherited types + /// Allow connections where input value type is assignable from output value type (eg. ScriptableObject --> Object) Inherited, /// Allow only similar types Strict, + /// Allow connections where output value type is assignable from input value type (eg. Object --> ScriptableObject) + InheritedInverse, } #region Obsolete diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index 9db7aee..58a3bd6 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -263,9 +263,11 @@ namespace XNode { // Check input type constraints if (input.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(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; // Check output type constraints - if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !output.ValueType.IsAssignableFrom(input.ValueType)) return false; - if (output.typeConstraint == XNode.Node.TypeConstraint.Strict && output.ValueType != input.ValueType) return false; + if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(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; // Success return true; }