From 10636cd24356083ebf72084b28e2ef9ebdc6d30e Mon Sep 17 00:00:00 2001 From: Icarus <1375400884@qq.com> Date: Sat, 21 Dec 2019 20:47:59 +0800 Subject: [PATCH] !T(Port) remove baseType --- Scripts/Editor/NodeEditorGUILayout.cs | 19 +++++++------- Scripts/NodePort.cs | 37 +-------------------------- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 56deb3b..b4a756a 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -314,8 +314,8 @@ namespace XNodeEditor { } [Obsolete("Use DynamicPortList instead")] - public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None,Type inputTypeConstraintBaseType = null, Action onCreation = null) { - DynamicPortList(fieldName, type, serializedObject, io, connectionType, typeConstraint, inputTypeConstraintBaseType,onCreation); + public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None, Action onCreation = null) { + DynamicPortList(fieldName, type, serializedObject, io, connectionType, typeConstraint, onCreation); } #endregion @@ -331,16 +331,16 @@ namespace XNodeEditor { return false; } - /// Draw an editable list of dynamic ports. Port names are named as "[fieldName] [index]" + /// Draw an editable list of dynamic ports. /// Supply a list for editable values /// Value type of added dynamic ports /// The serializedObject of the node /// Connection type of added dynamic ports - /// 并且时可用 /// Called on the list on creation. Use this if you want to customize the created ReorderableList + /// Return port name after adding port public static void DynamicPortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, - XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None,Type inputTypeConstraintBaseType = null, + XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None, Action onCreation = null,Action onAdd = null) { XNode.Node node = serializedObject.targetObject as XNode.Node; @@ -358,7 +358,7 @@ namespace XNodeEditor { if (list == null) { SerializedProperty arrayData = serializedObject.FindProperty(fieldName); list = CreateReorderableList(fieldName, dynamicPorts, arrayData, type, serializedObject, - io, connectionType, typeConstraint, inputTypeConstraintBaseType,onAdd); + io, connectionType, typeConstraint, onAdd); onCreation?.Invoke(list); if (reorderableListCache.TryGetValue(serializedObject.targetObject, out rlc)) rlc.Add(fieldName, list); else reorderableListCache.Add(serializedObject.targetObject, new Dictionary() { { fieldName, list } }); @@ -368,8 +368,7 @@ namespace XNodeEditor { } private static ReorderableList CreateReorderableList(string fieldName, List dynamicPorts, SerializedProperty arrayData, Type type, - SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, - Type inputTypeConstraintBaseType,Action onAdd) { + SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint,Action onAdd) { bool hasArrayData = arrayData != null && arrayData.isArray; XNode.Node node = serializedObject.targetObject as XNode.Node; ReorderableList list = new ReorderableList(dynamicPorts, null, true, true, true, true); @@ -465,7 +464,7 @@ namespace XNodeEditor { while (node.HasPort(newName)) newName = fieldName + " " + (++i); if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, XNode.Node.TypeConstraint.None, newName); - else node.AddDynamicInput(type, connectionType, typeConstraint,inputTypeConstraintBaseType, newName); + else node.AddDynamicInput(type, connectionType, typeConstraint, newName); serializedObject.Update(); EditorUtility.SetDirty(node); if (hasArrayData) { @@ -495,7 +494,7 @@ namespace XNodeEditor { int i = 0; while (node.HasPort(newName)) newName = arrayData.name + " " + (++i); if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, typeConstraint,newName); - else node.AddDynamicInput(type, connectionType, typeConstraint, inputTypeConstraintBaseType,newName); + else node.AddDynamicInput(type, connectionType, typeConstraint, newName); EditorUtility.SetDirty(node); dynamicPortCount++; } diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index e59e036..146a8ca 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -51,30 +51,13 @@ namespace XNode { } } - public Type TypeConstraintBaseType { - get { - if (_typeConstraintBaseType == null && !string.IsNullOrEmpty(_typeConstraintBaseTypeQualifiedName)) - _typeConstraintBaseType = Type.GetType(_typeConstraintBaseTypeQualifiedName, false); - return _typeConstraintBaseType; - } - set { - _typeConstraintBaseType = value; - if (value != null) - { - _typeConstraintBaseTypeQualifiedName = value.AssemblyQualifiedName; - } - } - } - private Type valueType; - private Type _typeConstraintBaseType; #if UNITY_EDITOR public const string FieldNameEditor = nameof(_fieldName); #endif [SerializeField] private string _fieldName; [SerializeField] private Node _node; [SerializeField] private string _typeQualifiedName; - [SerializeField] private string _typeConstraintBaseTypeQualifiedName; [SerializeField] private List connections = new List(); [SerializeField] private IO _direction; [SerializeField] private Node.ConnectionType _connectionType; @@ -92,7 +75,6 @@ namespace XNode { _direction = IO.Input; _connectionType = (attribs[i] as Node.InputAttribute).connectionType; _typeConstraint = (attribs[i] as Node.InputAttribute).typeConstraint; - TypeConstraintBaseType = (attribs[i] as Node.InputAttribute).BaseType; } else if (attribs[i] is Node.OutputAttribute) { _direction = IO.Output; _connectionType = (attribs[i] as Node.OutputAttribute).connectionType; @@ -105,7 +87,6 @@ namespace XNode { public NodePort(NodePort nodePort, Node node) { _fieldName = nodePort._fieldName; ValueType = nodePort.valueType; - TypeConstraintBaseType = nodePort.TypeConstraintBaseType; _direction = nodePort.direction; _dynamic = nodePort._dynamic; _connectionType = nodePort._connectionType; @@ -114,10 +95,9 @@ namespace XNode { } /// Construct a dynamic port. Dynamic ports are not forgotten on reimport, and is ideal for runtime-created ports. - public NodePort(string fieldName, Type type, IO direction, Node.ConnectionType connectionType, Node.TypeConstraint typeConstraint,Type baseType, Node node) { + public NodePort(string fieldName, Type type, IO direction, Node.ConnectionType connectionType, Node.TypeConstraint typeConstraint, Node node) { _fieldName = fieldName; this.ValueType = type; - TypeConstraintBaseType = baseType; _direction = direction; _node = node; _dynamic = true; @@ -301,21 +281,6 @@ 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) - { - //无法分配,失败 - if (!input.ValueType.IsAssignableFrom(output.ValueType)) - { - return false; - } - - //如果存在指定基类,同时无法分配,失败 - if (input.TypeConstraintBaseType != null && !input.TypeConstraintBaseType.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