示例#1
0
        protected override void Initialize()
        {
            this.backend = this.Property.ValueEntry.SerializationBackend;

            if (!ChildInfos.ContainsKey(backend))
            {
                ChildInfos[backend] = InspectorPropertyInfoUtility.GetDefaultPropertiesForType(this.Property, typeof(EditableKeyValuePair <TKey, TValue>), false);
            }
        }
        protected override InspectorPropertyInfo[] GetPropertyInfos()
        {
            this.targetType = this.ValueEntry.TypeOfValue;
            var members = targetType.GetAllMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            var infos   = new List <InspectorPropertyInfo>();

            this.allowObsoleteMembers = this.Property.Context.GetGlobal("ALLOW_OBSOLETE_STATIC_MEMBERS", false);

            foreach (var member in members.Where(Filter).OrderBy(Order))
            {
                var attributes = new List <Attribute>();
                InspectorPropertyInfoUtility.ProcessAttributes(this.Property, member, attributes);

                if (member is MethodInfo && !attributes.HasAttribute <ButtonAttribute>() && !attributes.HasAttribute <OnInspectorGUIAttribute>())
                {
                    attributes.Add(new ButtonAttribute(ButtonSizes.Medium));
                }

                var info = InspectorPropertyInfo.CreateForMember(member, true, SerializationBackend.None, attributes);

                InspectorPropertyInfo previousPropertyWithName = null;
                int previousPropertyIndex = -1;

                for (int j = 0; j < infos.Count; j++)
                {
                    if (infos[j].PropertyName == info.PropertyName)
                    {
                        previousPropertyIndex    = j;
                        previousPropertyWithName = infos[j];
                        break;
                    }
                }

                if (previousPropertyWithName != null)
                {
                    bool createAlias = true;

                    if (member.SignaturesAreEqual(previousPropertyWithName.GetMemberInfo()))
                    {
                        createAlias = false;
                        infos.RemoveAt(previousPropertyIndex);
                    }

                    if (createAlias)
                    {
                        var alias = InspectorPropertyInfoUtility.GetPrivateMemberAlias(previousPropertyWithName.GetMemberInfo(), previousPropertyWithName.TypeOfOwner.GetNiceName(), " -> ");
                        infos[previousPropertyIndex] = InspectorPropertyInfo.CreateForMember(alias, true, SerializationBackend.None, attributes);
                    }
                }

                infos.Add(info);
            }

            return(InspectorPropertyInfoUtility.BuildPropertyGroupsAndFinalize(this.Property, targetType, infos, false));
        }
示例#3
0
        public static InspectorPropertyInfo CreateForMember(InspectorProperty parentProperty, MemberInfo member, bool allowEditable, params Attribute[] attributes)
        {
            var list = new List <Attribute>(attributes.Length);

            for (int i = 0; i < attributes.Length; i++)
            {
                list.Add(attributes[i]);
            }

            return(CreateForMember(member, allowEditable, InspectorPropertyInfoUtility.GetSerializationBackend(parentProperty, member), list));
        }
示例#4
0
        public static void AddProcessedMember(this IList <InspectorPropertyInfo> infos, InspectorProperty parentProperty, MemberInfo member, bool allowEditable = true, SerializationBackend backend = SerializationBackend.None, params Attribute[] attributes)
        {
            var list = new List <Attribute>();

            if (attributes != null)
            {
                list.AddRange(attributes);
            }
            InspectorPropertyInfoUtility.ProcessAttributes(parentProperty, member, list);
            infos.Add(InspectorPropertyInfo.CreateForMember(member, allowEditable, backend, list));
        }
        protected override InspectorPropertyInfo[] GetPropertyInfos()
        {
            if (this.processors == null)
            {
                this.processors = OdinPropertyProcessorLocator.GetMemberProcessors(this.Property);
            }

            var includeSpeciallySerializedMembers = typeof(T).IsDefined <ShowOdinSerializedPropertiesInInspectorAttribute>(true);
            var infos = InspectorPropertyInfoUtility.CreateMemberProperties(this.Property, typeof(T), includeSpeciallySerializedMembers);

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

            return(InspectorPropertyInfoUtility.BuildPropertyGroupsAndFinalize(this.Property, typeof(T), infos, includeSpeciallySerializedMembers));
        }
示例#6
0
        protected override 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(T), includeSpeciallySerializedMembers);

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

            return(InspectorPropertyInfoUtility.BuildPropertyGroupsAndFinalize(this.Property, typeof(T), infos, includeSpeciallySerializedMembers));
        }
示例#7
0
        public static void AddProcessedMember(this IList <InspectorPropertyInfo> infos, InspectorProperty parentProperty, string name, bool allowEditable = true, SerializationBackend backend = SerializationBackend.None, params Attribute[] attributes)
        {
            var type = ProcessingOwnerType;

            type = (parentProperty.ValueEntry != null) ? parentProperty.ValueEntry.TypeOfValue : ProcessingOwnerType;

            var members = type.GetMember(name, MemberTypes.Field | MemberTypes.Method | MemberTypes.Property, Flags.AllMembers);

            if (members.Length == 0 || members.Length > 1)
            {
                throw new ArgumentException("Could not find precisely 1 member on type '" + type.GetNiceName() + "' with name '" + name + "'; found " + members.Length + " members.");
            }

            var list = new List <Attribute>();

            if (attributes != null)
            {
                list.AddRange(attributes);
            }
            InspectorPropertyInfoUtility.ProcessAttributes(parentProperty, members[0], list);
            infos.Add(InspectorPropertyInfo.CreateForMember(members[0], allowEditable, backend, list));
        }
示例#8
0
 public static InspectorPropertyInfo CreateForMember(InspectorProperty parentProperty, MemberInfo member, bool allowEditable, IEnumerable <Attribute> attributes)
 {
     return(CreateForMember(member, allowEditable, InspectorPropertyInfoUtility.GetSerializationBackend(parentProperty, member), attributes.ToList()));
 }
        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));
        }