Exemplo n.º 1
0
 /// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 /// <param name="typeConstraint">Constrains which input connections can be made to this port </param>
 /// <param name="instancePortList">If true, will display a reorderable list of inputs instead of a single port. Will automatically add and display values for lists and arrays </param>
 public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool instancePortList = false)
 {
     this.backingValue     = backingValue;
     this.connectionType   = connectionType;
     this.instancePortList = instancePortList;
     this.typeConstraint   = typeConstraint;
 }
Exemplo n.º 2
0
 /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 /// <param name="typeConstraint">Constrains which input connections can be made from this port </param>
 /// <param name="dynamicPortList">If true, will display a reorderable list of outputs instead of a single port. Will automatically add and display values for lists and arrays </param>
 public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool dynamicPortList = false)
 {
     this.backingValue    = backingValue;
     this.connectionType  = connectionType;
     this.dynamicPortList = dynamicPortList;
     this.typeConstraint  = typeConstraint;
 }
Exemplo n.º 3
0
        public NodePort(
            int id,
            int nodeId,
            NodeGraph graph,
            string fieldName,
            PortIO direction = PortIO.Input,
            ConnectionType connectionType     = ConnectionType.Multiple,
            ShowBackingValue showBackingValue = ShowBackingValue.Always,
            IEnumerable <Type> types          = null,
            bool distinctValue = false)
        {
            this.id               = id;
            this.nodeId           = nodeId;
            this.graph            = graph;
            this.fieldName        = fieldName;
            this.direction        = direction;
            this.connectionType   = connectionType;
            this.showBackingValue = showBackingValue;
            this.distinctValue    = distinctValue;

            portValue.SetValueTypeFilter(types);
            portValue.distinctValues = distinctValue;

            Initialize(nodeId, graph);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/>
 /// </summary>
 /// <param name="backingValue">
 /// Should we display the backing value for this port as an editor field?
 /// </param>
 /// <param name="connectionType">Should we allow multiple connections?</param>
 /// <param name="typeConstraint">
 /// Constrains which input connections can be made to this port
 /// </param>
 /// <param name="dynamicPortList">
 /// If true, will display a reorderable list of inputs instead of a single port. Will
 /// automatically add and display values for lists and arrays
 /// </param>
 /// <param name="allowedTypes">If set apply to typeConstraint</param>
 public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool dynamicPortList = false, params Type[] allowedTypes)
 {
     this.backingValue    = backingValue;
     this.connectionType  = connectionType;
     this.dynamicPortList = dynamicPortList;
     this.typeConstraint  = typeConstraint;
     this.allowedTypes    = allowedTypes;
 }
Exemplo n.º 5
0
 public PortData(IPortData portData)
 {
     fieldName        = portData.ItemName;
     direction        = portData.Direction;
     connectionType   = portData.ConnectionType;
     showBackingValue = portData.ShowBackingValue;
     valueTypes       = portData.ValueTypes.ToList();
 }
Exemplo n.º 6
0
 public void SetPortData(IPortData portData)
 {
     fieldName        = portData.ItemName;
     direction        = portData.Direction;
     connectionType   = portData.ConnectionType;
     showBackingValue = portData.ShowBackingValue;
     portValue.SetValueTypeFilter(portData.ValueTypes);
 }
Exemplo n.º 7
0
 public PortAttribute(
     PortIO direction = PortIO.Input,
     ConnectionType connectionType = ConnectionType.Multiple,
     ShowBackingValue backingValue = ShowBackingValue.Always)
 {
     this.direction        = direction;
     this.connectionType   = connectionType;
     this.showBackingValue = backingValue;
 }
 /// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 public NodeInputAttribute(
     ShowBackingValue backingValue = ShowBackingValue.Always,
     ConnectionType connectionType = ConnectionType.Multiple,
     bool instancePortList         = false)
 {
     this.showBackingValue = backingValue;
     this.connectionType   = connectionType;
     this.instancePortList = instancePortList;
 }
Exemplo n.º 9
0
 public void Release()
 {
     fieldName        = string.Empty;
     direction        = PortIO.Input;
     connectionType   = ConnectionType.Multiple;
     isDynamic        = true;
     showBackingValue = ShowBackingValue.Always;
     instancePortList = false;
     valueTypes       = null;
 }
Exemplo n.º 10
0
 public PortAttribute(NodePort.PortDirection direction,
                      NodePort.PortCapacity capacity             = NodePort.PortCapacity.Multi,
                      NodePort.PortTypeConstraint typeConstraint = NodePort.PortTypeConstraint.None,
                      ShowBackingValue showBackingValue          = ShowBackingValue.Never)
 {
     Direction      = direction;
     Capacity       = capacity;
     TypeConstraint = typeConstraint;
     ShowBackValue  = showBackingValue;
 }
 public ReactivePortAttribute(
     PortIO direction              = PortIO.Input,
     bool distinctValues           = false,
     ConnectionType connectionType = ConnectionType.Multiple,
     ShowBackingValue backingValue = ShowBackingValue.Always)
 {
     this.distinctValues   = distinctValues;
     this.direction        = direction;
     this.connectionType   = connectionType;
     this.showBackingValue = backingValue;
 }
Exemplo n.º 12
0
 /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 public NodeOutputAttribute(
     bool distinctValues           = false,
     ShowBackingValue backingValue = ShowBackingValue.Always,
     ConnectionType connectionType = ConnectionType.Multiple,
     bool instancePortList         = false)
 {
     this.distinctValues   = distinctValues;
     this.showBackingValue = backingValue;
     this.connectionType   = connectionType;
     this.instancePortList = instancePortList;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Construct a dynamic port. Dynamic ports are not forgotten on reimport,
 /// and is ideal for runtime-created ports.
 /// </summary>
 public NodePort(
     int id,
     INode node,
     string fieldName,
     Type type,
     PortIO direction = PortIO.Input,
     ConnectionType connectionType     = ConnectionType.Multiple,
     ShowBackingValue showBackingValue = ShowBackingValue.Always) :
     this(id, node, fieldName, direction, connectionType, showBackingValue, new List <Type>() { type })
 {
 }
Exemplo n.º 14
0
        public static IPortValue UpdatePortValue(
            this INode node,
            string portName,
            PortIO direction = PortIO.Output,
            ConnectionType connectionType     = ConnectionType.Multiple,
            ShowBackingValue showBackingValue = ShowBackingValue.Always,
            IReadOnlyList <Type> types        = null)
        {
            types = types ?? new List <Type>();
            var port = node.AddPort(portName, types, direction, connectionType, showBackingValue);

            return(port.Value);
        }
Exemplo n.º 15
0
 public PortValueFilterAttribute(
     string portName,
     PortIO direction = PortIO.Input,
     ConnectionType connectionType = ConnectionType.Multiple,
     ShowBackingValue backingValue = ShowBackingValue.Always,
     params Type[] typeFilter)
 {
     this.portName       = portName;
     this.direction      = direction;
     this.connectionType = connectionType;
     this.backingValue   = backingValue;
     this.typeFilter     = typeFilter.ToList();
 }
Exemplo n.º 16
0
 /// <summary>
 /// Construct a dynamic port. Dynamic ports are not forgotten on reimport,
 /// and is ideal for runtime-created ports.
 /// </summary>
 public NodePort(
     int id,
     int nodeId,
     NodeGraph graph,
     string fieldName,
     Type type,
     PortIO direction = PortIO.Input,
     ConnectionType connectionType     = ConnectionType.Multiple,
     ShowBackingValue showBackingValue = ShowBackingValue.Always,
     bool distinctValue = false) :
     this(id, nodeId, graph, fieldName, direction, connectionType, showBackingValue, new List <Type>() { type }, distinctValue)
 {
 }
Exemplo n.º 17
0
        public static IPortValue UpdatePortValue(
            this INode node,
            string portName,
            PortIO direction,
            ConnectionType connectionType,
            ShowBackingValue showBackingValue = ShowBackingValue.Always,
            IEnumerable <Type> types          = null,
            bool distinctValue = false)
        {
            types ??= Enumerable.Empty <Type>();
            var port = node.AddPort(portName, types, direction, connectionType, showBackingValue, distinctValue);

            return(port.Value);
        }
Exemplo n.º 18
0
        public NodePort(
            int id,
            INode node,
            string fieldName,
            PortIO direction = PortIO.Input,
            ConnectionType connectionType     = ConnectionType.Multiple,
            ShowBackingValue showBackingValue = ShowBackingValue.Always,
            IEnumerable <Type> types          = null)
        {
            this.id               = id;
            this.node             = node;
            this.nodeId           = node.Id;
            this.fieldName        = fieldName;
            this.direction        = direction;
            this.connectionType   = connectionType;
            this.showBackingValue = showBackingValue;
            portValue.SetValueTypeFilter(types);

            Initialize(node);
        }
Exemplo n.º 19
0
 /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, bool instancePortList = false)
 {
     this.backingValue   = backingValue;
     this.connectionType = connectionType;
 }
Exemplo n.º 20
0
 public OutputAttribute(ShowBackingValue backingValue, ConnectionType connectionType, bool dynamicPortList) : this(backingValue, connectionType, TypeConstraint.None, dynamicPortList)
 {
 }
        protected InspectorPropertyInfo[] GetPropertyInfos()
        {
            if (this.processors == null)
            {
                this.processors = OdinPropertyProcessorLocator.GetMemberProcessors(this.Property);
            }

            var includeSpeciallySerializedMembers = this.Property.ValueEntry.SerializationBackend != SerializationBackend.Unity;
            var infos = InspectorPropertyInfoUtility.CreateMemberProperties(this.Property, typeof(TValue), includeSpeciallySerializedMembers);

            // If we resolve the ports from the port dictionary i might be able to communicate between properties
            // in order to make dynamic port adding cleaner

            // Resolve my own members so I can see them
#if DEBUG_RESOLVER
            infos.AddValue(
                $"resolver:{nameof(infos)}",
                () => this.infos,
                value => { }
                );

            infos.AddValue(
                $"resolver:{nameof( namesToIndex )}",
                () => this.namesToIndex,
                value => { }
                );

            infos.AddValue(
                $"resolver:{nameof( nameToNodePropertyInfo )}",
                () => this.nameToNodePropertyInfo,
                value => { }
                );

            infos.AddValue(
                $"resolver:{nameof( propertyToNodeProperty )}",
                () => this.propertyToNodeProperty,
                value => { }
                );
#endif

            LabelWidthAttribute labelWidthAttribute = Property.GetAttribute <LabelWidthAttribute>();
            displayDynamicPortsAttribute = Property.GetAttribute <DisplayDynamicPortsAttribute>();

            // Port makers
            {
                for (int i = 0; i < infos.Count; ++i)
                {
                    var info = infos[i];
                    if (labelWidthAttribute != null)
                    {
                        if (info.GetAttribute <LabelWidthAttribute>() == null)
                        {
                            info.GetEditableAttributesList().Add(labelWidthAttribute);
                        }
                    }

                    var inputAttribute  = info.GetMemberInfo().GetAttribute <InputAttribute>();
                    var outputAttribute = info.GetMemberInfo().GetAttribute <OutputAttribute>();
                    if (inputAttribute != null || outputAttribute != null)                       // Make a port.... we'll deal with dynamic later
                    {
                        string           baseFieldName     = info.PropertyName;
                        NodePort         port              = Node.GetPort(info.PropertyName);
                        ShowBackingValue showBackingValue  = ShowBackingValue.Always;
                        ConnectionType   connectionType    = ConnectionType.Multiple;
                        TypeConstraint   typeConstraint    = TypeConstraint.None;
                        bool             isDynamicPortList = false;
                        bool             isInput           = false;

                        if (inputAttribute != null)
                        {
                            showBackingValue  = inputAttribute.backingValue;
                            connectionType    = inputAttribute.connectionType;
                            typeConstraint    = inputAttribute.typeConstraint;
                            isDynamicPortList = inputAttribute.dynamicPortList;
                            isInput           = true;
                        }
                        else if (outputAttribute != null)
                        {
                            showBackingValue  = outputAttribute.backingValue;
                            connectionType    = outputAttribute.connectionType;
                            typeConstraint    = outputAttribute.typeConstraint;
                            isDynamicPortList = outputAttribute.dynamicPortList;
                            isInput           = false;
                        }

                        // The port didn't exist... let's just make it exist again?
                        if (port == null)
                        {
                            Node.UpdatePorts();
                            port = Node.GetPort(info.PropertyName);
                        }

                        var portInfo = InspectorPropertyInfo.CreateValue(
                            $"{info.PropertyName}:port",
                            0,
                            Property.ValueEntry.SerializationBackend,
                            new GetterSetter <TValue, NodePort>(
                                ( ref TValue owner ) => port,
                                (ref TValue owner, NodePort value) => { }
                                )
                            , new HideInInspector()
                            );

                        var nodePortInfo = new NodePortInfo(
                            portInfo,
                            info,
                            baseFieldName,
                            info.TypeOfValue,
                            Property.Tree.WeakTargets.FirstOrDefault() as Node,                             // Needed?
                            showBackingValue,
                            connectionType,
                            typeConstraint,
                            isDynamicPortList,
                            false,
                            isInput,
                            true
                            );

                        propertyToNodeProperty[info.PropertyName]     = portInfo.PropertyName;
                        nameToNodePropertyInfo[portInfo.PropertyName] = nodePortInfo;

                        if (isDynamicPortList)
                        {
                            var listDrawerAttributes = info.GetAttribute <ListDrawerSettingsAttribute>();
                            if (listDrawerAttributes == null)
                            {
                                listDrawerAttributes = new ListDrawerSettingsAttribute();
                                info.GetEditableAttributesList().Add(listDrawerAttributes);
                            }

                            listDrawerAttributes.Expanded   = true;
                            listDrawerAttributes.ShowPaging = false;
                        }

                        infos.Insert(i, portInfo);
                        ++i;                         // Skip the next entry
                    }
                }

                if (displayDynamicPortsAttribute != null)
                {
                    // If I find any dynamic ports that were not covered here then add them as well
                    // This should include anything that wouldn't be directly related to the ports I *did* find
                    foreach (var port in Node.Ports)
                    {
                        if (port.IsDynamic)
                        {
                            // If is likely to be an automatically added port?
                            if (IsManagedPort(port.fieldName))
                            {
                                continue;
                            }

                            // No one claimed it?
                            var nodePortInfo = CreateLooseDynamicPortInfo(port, out var info, out var portInfo, displayDynamicPortsAttribute);

                            propertyToNodeProperty[info.PropertyName]     = portInfo.PropertyName;
                            nameToNodePropertyInfo[portInfo.PropertyName] = nodePortInfo;

                            infos.Add(info);
                            infos.Add(portInfo);
                        }
                    }
                }
            }

            for (int i = 0; i < this.processors.Count; i++)
            {
                ProcessedMemberPropertyResolverExtensions.ProcessingOwnerType = typeof(TValue);
                this.processors[i].ProcessMemberProperties(infos);
            }

            EditorApplication.update -= Update;
            if (displayDynamicPortsAttribute != null)
            {
                EditorApplication.update += Update;
            }

            knownPortKeys.Clear();
            knownPortKeys.AddRange(Node.Ports.Select(x => x.fieldName));
            return(InspectorPropertyInfoUtility.BuildPropertyGroupsAndFinalize(this.Property, typeof(TValue), infos, includeSpeciallySerializedMembers));
        }
Exemplo n.º 22
0
 /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple)
 {
     this.backingValue   = backingValue;
     this.connectionType = connectionType;
 }
Exemplo n.º 23
0
 /// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple)
 {
     this.backingValue   = backingValue;
     this.connectionType = connectionType;
 }
Exemplo n.º 24
0
 public NodePort AddPort(string fieldName,
                         IEnumerable <Type> types,
                         PortIO direction,
                         ConnectionType connectionType     = ConnectionType.Multiple,
                         ShowBackingValue showBackingValue = ShowBackingValue.Always) => null;
Exemplo n.º 25
0
 public NodePort AddPort(string fieldName, IEnumerable <Type> types, PortIO direction,
                         ConnectionType connectionType     = ConnectionType.Multiple,
                         ShowBackingValue showBackingValue = ShowBackingValue.Always, bool distinctValue = false)
 {
     return(null);
 }
Exemplo n.º 26
0
 /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutput(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never)
 {
     this.backingValue = backingValue;
 }
Exemplo n.º 27
0
 /// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInput(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected)
 {
     this.backingValue = backingValue;
 }