public override void ProcessMemberProperties(List <InspectorPropertyInfo> infos)
        {
            if (!NodeEditor.InNodeEditor)
            {
                return;
            }

            // Remove excluded properties
            string[] excludes = { "m_Script", "graph", "position", "folded", "ports" };
            foreach (var exclude in excludes)
            {
                infos.Remove(infos.Find(exclude));
            }

            if (Property.GetAttribute <ShowNameInNodeEditorAttribute>() != null)
            {
                var nameProperty = InspectorPropertyInfo.CreateValue(
                    "name",
                    0,
                    Property.ValueEntry.SerializationBackend,
                    new GetterSetter <TNode, string>(
                        ( ref TNode node ) => node.name,
                        (ref TNode node, string value) =>
                {
                    Undo.RegisterFullObjectHierarchyUndo(node, "Set node name");
                    node.name = value;
                }
                        ),
                    new Sirenix.OdinInspector.DelayedPropertyAttribute()
                    );
                infos.Insert(0, nameProperty);
            }
        }
Пример #2
0
        public override void ProcessMemberProperties(List <InspectorPropertyInfo> infos)
        {
            if (NodeEditor.InNodeEditor)
            {
                return;
            }

            if (Property.GetAttribute <ShowFoldButtonsAttribute>() != null)
            {
                var unfoldAllProperty = InspectorPropertyInfo.CreateForDelegate(
                    "unfoldAllNodes",
                    0,
                    typeof(TNodeGraph),
                    unfoldAll,
                    new ButtonGroupAttribute(FOLDBUTTON_GROUP)
                    );
                infos.Insert(0, unfoldAllProperty);
                var foldAllProperty = InspectorPropertyInfo.CreateForDelegate(
                    "foldAllNodes",
                    0,
                    typeof(TNodeGraph),
                    foldAll,
                    new ButtonGroupAttribute(FOLDBUTTON_GROUP)
                    );
                infos.Insert(0, foldAllProperty);
            }
        }
        public override void ProcessMemberProperties(List <InspectorPropertyInfo> infos)
        {
            if (NodeEditor.InNodeEditor)
            {
                return;
            }

            if (Property.GetAttribute <ShowNameInInspectorAttribute>() != null)
            {
                var nameProperty = InspectorPropertyInfo.CreateValue(
                    "name",
                    0,
                    Property.ValueEntry.SerializationBackend,
                    new GetterSetter <TNode, string>(
                        ( ref TNode node ) => node.name,
                        (ref TNode node, string value) =>
                {
                    Undo.RegisterFullObjectHierarchyUndo(node, "Set node name");
                    node.name = value;
                }
                        ),
                    new Sirenix.OdinInspector.DelayedPropertyAttribute()
                    );
                infos.Insert(0, nameProperty);
            }
        }
Пример #4
0
        protected override void Initialize()
        {
            // Port is already resolved for the base
            var parent = Property.ParentValueProperty;

            if (parent == null)
            {
                parent = Property.Tree.SecretRootProperty;
            }

            portResolver = parent.ChildResolver as INodePortResolver;
            nodePortInfo = portResolver.GetNodePortInfo(Property.Name);

            UpdateDynamicPorts();

            fakeListInfo = InspectorPropertyInfo.CreateValue(
                NodePropertyPort.NodePortListPropertyName,
                0,
                Property.ValueEntry.SerializationBackend,
                new GetterSetter <TValue, List <TValue> >(
                    GetDynamicPorts,
                    (ref TValue owner, List <TValue> value) => { }
                    ),
                Property.Attributes
                .Where(x =>
                       x is ListDrawerSettingsAttribute ||
                       x is NodePortAttribute ||
                       x is ShowDrawerChainAttribute ||
                       x is ShowPropertyResolverAttribute
                       )
                );
        }
 public override void ProcessMemberProperties(List <InspectorPropertyInfo> propertyInfos)
 {
     for (int i = propertyInfos.Count - 1; i >= 0; --i)
     {
         InspectorPropertyInfo p = propertyInfos[i];
         if (p.GetAttribute <HideOutsideNodeEditorAttribute>() != null)
         {
             propertyInfos.RemoveAt(i);
         }
     }
 }
 protected override InspectorPropertyInfo[] GetPropertyInfos()
 {
     return(new InspectorPropertyInfo[] {
         InspectorPropertyInfo.CreateValue("x", 0, this.Property.ValueEntry.SerializationBackend,
                                           new GetterSetter <Vector2Int, int>(
                                               getter: (ref Vector2Int vec) => vec.x,
                                               setter: (ref Vector2Int vec, int value) => vec.x = value)),
         InspectorPropertyInfo.CreateValue("y", 0, this.Property.ValueEntry.SerializationBackend,
                                           new GetterSetter <Vector2Int, int>(
                                               getter: (ref Vector2Int vec) => vec.y,
                                               setter: (ref Vector2Int vec, int value) => vec.y = value)),
     });
 }
Пример #7
0
        protected InspectorPropertyInfo GetInfoForPortAtIndex(int index)
        {
            InspectorPropertyInfo childPortInfo;

            if (!childPortInfos.TryGetValue(index, out childPortInfo))
            {
                InspectorPropertyInfo sourceChildInfo = base.GetChildInfo(index);

                string   portName = $"{nodePortInfo.BaseFieldName} {index}";
                Node     node     = nodePortInfo.Node;
                NodePort port     = node.GetPort(portName);

                childPortInfo = InspectorPropertyInfo.CreateValue(
                    $"{CollectionResolverUtilities.DefaultIndexToChildName( index )}:port",
                    0,
                    Property.ValueEntry.SerializationBackend,
                    new GetterSetter <TList, NodePort>(
                        ( ref TList owner ) => port,
                        (ref TList owner, NodePort value) => { }
                        )
                    , new HideInInspector()
                    );

                var childNodePortInfo = new NodePortInfo(
                    childPortInfo,
                    sourceChildInfo,
                    portName,
                    typeof(TElement),
                    node,                     // Needed?
                    nodePortInfo.ShowBackingValue,
                    nodePortInfo.ConnectionType,
                    nodePortInfo.TypeConstraint,
                    nodePortInfo.IsDynamicPortList,
                    true,
                    nodePortInfo.IsInput,
                    noDataResolver == null
                    );

                propertyToNodeProperty[sourceChildInfo.PropertyName] = childPortInfo.PropertyName;
                nameToNodePropertyInfo[childPortInfo.PropertyName]   = childNodePortInfo;

                childPortInfos[index] = childPortInfo;
            }
            return(childPortInfo);
        }
Пример #8
0
        public override void ProcessMemberProperties(List <InspectorPropertyInfo> memberInfos)
        {
            var refAttribute  = GetClassDefinedRequireComponent(base.Property);
            var refObject     = (base.Property.Tree.WeakTargets[0] as MonoBehaviour).gameObject;
            var requiredTypes = refAttribute.RequiredTypes;
            var typesLength   = requiredTypes.Length;
            var myMessage     = refAttribute.Message;

            // Check if Types exist
            var isMissingType = false;

            typeNames.Clear();
            for (int i = 0; i < typesLength; i++)
            {
                if (refObject.GetComponent(requiredTypes[i]) == null)
                {
                    typeNames.Add(requiredTypes[i].Name);
                    isMissingType = true;
                }
            }

            // Build string
            if (isMissingType)
            {
                myMessage.Clear();
                myMessage = (typesLength == 1) ? new StringBuilder("Requires component: ") : new StringBuilder("Requires Components: ");

                var stringLength = typeNames.Count;
                for (int i = 0; i < stringLength - 1; i++)
                {
                    myMessage.AppendFormat("{0}  |   ", typeNames[i]);
                }
                myMessage.AppendFormat("{0}.", typeNames[stringLength - 1]);

                InspectorPropertyInfo item = InspectorPropertyInfo.CreateForMember(RequireComponentWarningProcessor.InjectedMemberInfo, false, SerializationBackend.None, new Attribute[]
                {
                    new OnInspectorGUIAttribute(),
                    new InfoBoxAttribute(myMessage.ToString(), InfoMessageType.Error, null),
                    new PropertyOrderAttribute(-100000)
                });
                memberInfos.Insert(0, item);
            }
        }
        public NodePortInfo CreateLooseDynamicPortInfo(NodePort port, out InspectorPropertyInfo info, out InspectorPropertyInfo portInfo, params Attribute[] attributes)
        {
            info = InspectorPropertyInfo.CreateValue(
                port.fieldName,
                1,
                Property.ValueEntry.SerializationBackend,
                new GetterSetter <TValue, int>(
                    ( ref TValue owner ) => 0,
                    (ref TValue owner, int value) => { }
                    ),
                attributes
                );

            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()
                );

            // Create a fake property and a fake node
            NodePortInfo nodePortInfo = new NodePortInfo(
                portInfo,
                info,
                port.fieldName,
                port.ValueType,
                Property.Tree.WeakTargets.FirstOrDefault() as Node,                 // Needed?
                ShowBackingValue.Never,
                port.connectionType,
                port.typeConstraint,
                false,
                true,
                port.IsInput,
                false
                );

            return(nodePortInfo);
        }
    public override void ProcessMemberProperties(List <InspectorPropertyInfo> propertyInfos)
    {
        var val = (BetterEventEntry)this.Property.ValueEntry.WeakSmartValue;

        if (val.Delegate == null)
        {
            return;
        }
        if (val.Delegate.Method == null)
        {
            return;
        }

        var ps = val.Delegate.Method.GetParameters();

        for (int i = 0; i < ps.Length; i++)
        {
            var p = ps[i];
            var getterSetterType = typeof(ArrayIndexGetterSetter <>).MakeGenericType(p.ParameterType);
            var getterSetter     = Activator.CreateInstance(getterSetterType, new object[] { this.Property, i }) as IValueGetterSetter;
            var info             = InspectorPropertyInfo.CreateValue(p.Name, i, SerializationBackend.Odin, getterSetter);
            propertyInfos.Add(info);
        }
    }
 public virtual bool ChildPropertyRequiresRefresh(int index, InspectorPropertyInfo info)
 {
     return(this.GetChildInfo(index) != info);
 }
        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));
        }