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

Fixed TypeConstraint.Inherited, and added TypeConstraint.InheritedInverse (#205)

* Added TypeConstraint to check inheritance but inverted.

* Flipped output inherited type constraints, edited comments
This commit is contained in:
Simon Rodriguez 2019-11-06 13:12:04 +01:00 committed by Thor Brigsted
parent be0d452d12
commit 63c3ae2f7d
2 changed files with 7 additions and 3 deletions

View File

@ -45,10 +45,12 @@ namespace XNode {
public enum TypeConstraint { public enum TypeConstraint {
/// <summary> Allow all types of input</summary> /// <summary> Allow all types of input</summary>
None, None,
/// <summary> Allow similar and inherited types </summary> /// <summary> Allow connections where input value type is assignable from output value type (eg. ScriptableObject --> Object)</summary>
Inherited, Inherited,
/// <summary> Allow only similar types </summary> /// <summary> Allow only similar types </summary>
Strict, Strict,
/// <summary> Allow connections where output value type is assignable from input value type (eg. Object --> ScriptableObject)</summary>
InheritedInverse,
} }
#region Obsolete #region Obsolete

View File

@ -263,9 +263,11 @@ namespace XNode {
// Check input type constraints // Check input type constraints
if (input.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false; 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.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 // Check output type constraints
if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !output.ValueType.IsAssignableFrom(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 && output.ValueType != input.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 // Success
return true; return true;
} }