Exemplo n.º 1
0
        private void RebuildResultDrawer()
        {
            if (inactive)
            {
                                #if DEV_MODE
                Debug.LogWarning("Ignoring RebuildResuiltDrawer because inactive");
                                #endif
                return;
            }

            if (!hasResult)
            {
                                #if DEV_MODE
                Debug.LogWarning("Ignoring RebuildResuiltDrawer because hasResult was false");
                                #endif
                return;
            }

                        #if DEV_MODE
            Debug.Log("RebuildResultDrawer from result: " + StringUtils.ToString(base.Value));
                        #endif

            ResultDrawer = DrawerProvider.GetForField(base.Value, Type, null, this, GUIContentPool.Create("Result"), ReadOnly);
            UpdateVisibleMembers();
            drawInSingleRow = GetDrawInSingleRowUpdated();
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE && DEBUG_BUILD_MEMBERS
            Debug.Log(Msg(ToString(), ".DoBuildMembers with hasResult=", hasResult, ", hasParameters=", hasParameters, ", isGeneric=", isGeneric));
                        #endif

            if (!hasResult && !hasParameters && !isGeneric)
            {
                DrawerArrayPool.Resize(ref members, 0);
            }
            else
            {
                int size = 0;
                if (hasResult)
                {
                    size++;
                }
                if (isGeneric)
                {
                    size++;
                }
                if (hasParameters)
                {
                    size++;
                }
                DrawerArrayPool.Resize(ref members, size);

                bool readOnly = ReadOnly;

                int index = 0;
                if (isGeneric)
                {
                    members[0] = GenericsDrawer.Create(memberInfo, this, GUIContentPool.Create("Generics"), readOnly);
                    index++;
                }

                if (hasParameters)
                {
                    members[index] = ParameterDrawer.Create(MethodInfo.GetParameters(), memberInfo, this, GUIContentPool.Create("Parameters"), readOnly);
                    index++;
                }

                if (hasResult)
                {
                    string tooltip = LinkedMemberInfo.TooltipDatabase.GetTooltipFromParent(MethodInfo.ReturnParameter, memberInfo, "Returns");
                    if (tooltip.Length == 0)
                    {
                        tooltip = "Value returned by method.";
                    }

                    var resultMemberInfo = resultMemberHierarchy.Get(null, typeof(MethodDrawer).GetField("result", BindingFlags.Instance | BindingFlags.NonPublic), LinkedMemberParent.ClassInstance, null);
                    members[index] = DrawerProvider.GetForField(result, Type, resultMemberInfo, this, GUIContentPool.Create("Result", tooltip), readOnly);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Given a non-abstract explicitly chosen type, returns the drawer for the value of the drawer using said type.
        /// </summary>
        /// <param name="setType"> Type of value. </param>
        /// <param name="setValue"> Initial value. Can be null. </param>
        /// <param name="setMemberInfo"> Linked member info for class member which the drawer represents. </param>
        /// <param name="setParent"> Parent for the drawer. </param>
        /// <param name="setLabel"> Label for the drawer. </param>
        /// <param name="setReadOnly"> If true drawer should be greted out and its value should not be editable. </param>
        /// <returns> Drawer instance to use for the value. </returns>
        protected virtual IDrawer BuildDrawerForValue(Type setType, [CanBeNull] object setValue, [CanBeNull] LinkedMemberInfo setMemberInfo, [NotNull] IParentDrawer setParent, [CanBeNull] GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(setType != null || setValue != null || setMemberInfo != null);
            Debug.Assert(setMemberInfo == memberInfo);
            Debug.Assert(setParent == this);
            Debug.Assert(setType != Type);
                        #endif

            return(DrawerProvider.GetForField(setValue, setType, setMemberInfo, setParent, setLabel, setReadOnly));
        }
Exemplo n.º 4
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
            Array.Resize(ref members, 2);

            var keyToAdd = DrawerProvider.GetForField(Value, keyType, null, this, GUIContent.none, ReadOnly);

            keyToAdd.OverrideValidateValue     = validateKey;
            keyToAdd.OnKeyboardInputBeingGiven = OnKeyDrawerKeyboardInputBeingGiven;
            members[0] = keyToAdd;
            var button = ButtonDrawer.Create("", onAddButtonClicked, this, InspectorPreferences.Styles.AddButton, ReadOnly);

            members[1] = button;
        }
Exemplo n.º 5
0
        public IDrawer GetDefaultDrawer()
        {
            GUIContent label;

            if (MemberInfo != null)
            {
                label = MemberInfo.GetLabel();
            }
            else if (fieldInfo != null)
            {
                label = new GUIContent(StringUtils.SplitPascalCaseToWords(fieldInfo.Name));
            }
            else
            {
                label = null;
            }

            return(DrawerProvider.GetForField(MemberInfo, parent, label, parent != null ? parent.ReadOnly : false));
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
            if (!hasResult && !hasParameters)
            {
                DrawerArrayPool.Resize(ref members, 0);
            }
            else
            {
                if (hasResult)
                {
                    ResultDrawer = DrawerProvider.GetForField(base.Value, Type, memberInfo, this, GUIContentPool.Create("Value"), ReadOnly);
                }

                if (hasParameters)
                {
                    IndexParameterDrawer = ParameterDrawer.Create(PropertyInfo.GetIndexParameters(), memberInfo, this, GUIContentPool.Create("Parameters"), false);
                }
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            DrawerArrayPool.Resize(ref members, 2);

            // Making key be read-only for now until code has been added to handle on-the-fly changing of keys gracefully.
            // E.g. all keys should use delayed text fields and be marked with NotNull (e.g. using a custom DrawerProvider).
            var keyInfo = memberBuildList[0];

            IDrawer keyMember;
            var     keyValue = keyInfo.GetValue(0);
            var     keyLabel = GUIContentPool.Create("K");
            //var keyIsReadOnly = ReadOnly;
            const bool keyIsReadOnly = true;

            if (keyType == Types.Int)
            {
                keyMember = DelayedIntDrawer.Create((int)keyValue, keyInfo, this, keyLabel, keyIsReadOnly);
            }
            else if (keyType == Types.String)
            {
                keyMember = TextDrawer.Create((string)keyValue, keyInfo, this, keyLabel, keyIsReadOnly, false, true);
            }
            else if (keyType == Types.Float)
            {
                keyMember = DelayedFloatDrawer.Create((float)keyValue, keyInfo, this, keyLabel, keyIsReadOnly);
            }
            else
            {
                keyMember = DrawerProvider.GetForField(keyValue, keyType, keyInfo, this, keyLabel, keyIsReadOnly);
            }

            keyMember.OverrideValidateValue = ValidateKey;

            members[0] = keyMember;
            var valueInfo   = memberBuildList[1];
            var valueMember = DrawerProvider.GetForField(valueInfo.GetValue(0), valueType, valueInfo, this, GUIContentPool.Create("V"), ReadOnly);

            members[1] = valueMember;
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            bool readOnly = ReadOnly;

            DrawerArrayPool.Resize(ref members, 2);

            var keyInfo = memberBuildList[0];

            members[0] = DrawerProvider.GetForField(keyInfo.GetValue(0), keyInfo.Type, keyInfo, this, GUIContentPool.Create("K"), readOnly);
            var valueInfo = memberBuildList[1];

            members[1] = DrawerProvider.GetForField(valueInfo.GetValue(0), valueInfo.Type, valueInfo, this, GUIContentPool.Create("V"), readOnly);

                        #if DEV_MODE && DEBUG_BUILD_MEMBERS
            Debug.Log(StringUtils.ToColorizedString(this + ".DoBuildMembers with readOnly=", readOnly, ", members[0].ReadOnly=", members[0].ReadOnly, ", members[1].ReadOnly=", members[1].ReadOnly));
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(members[0].ReadOnly == readOnly, StringUtils.ToColorizedString(this + " readOnly (", readOnly, ") != members[0].ReadOnly (", members[0].ReadOnly, ")"));
            Debug.Assert(members[1].ReadOnly == readOnly, StringUtils.ToColorizedString(this + " readOnly (", readOnly, ") != members[1].ReadOnly (", members[1].ReadOnly, ")"));
                        #endif
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            int count = memberBuildList.Count;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(count == parameterInfos.Length, "memberBuildList.Count=" + memberBuildList.Count + " != " + parameterInfos.Length);
                        #endif

                        #if DEV_MODE
            Debug.Log("ParameterDrawer.DoBuildMembers called with parameterInfos.Length=" + parameterInfos.Length + ", memberBuildList.Count=" + memberBuildList.Count + ", drawInSingleRow=" + drawInSingleRow);
                        #endif

            DrawerArrayPool.Resize(ref members, count);

            //If only has one parameter, can be drawn in a single row
            if (drawInSingleRow)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(memberBuildList.Count == 1);
                Debug.Assert(parameterInfos.Length == 1);
                                #endif

                var memberFieldInfo = memberBuildList[0];
                var parameterInfo   = memberFieldInfo.ParameterInfo;
                var type            = GetParameterTypeAndLabel(memberFieldInfo, ref label);

                var member = DrawerProvider.GetForField(ParameterValues.GetValue(parameterInfo), type, memberFieldInfo, this, GUIContent.none, ReadOnly);

                                #if DEV_MODE || SAFE_MODE
                if (member == null)
                {
                    Debug.LogError(ToString() + " Failed to create Drawer for member " + memberFieldInfo + " of type " + StringUtils.ToString(type) + ".\nparent=" + StringUtils.ToString(parent));
                    DrawerArrayPool.Resize(ref members, 0);
                    return;
                }
                                #endif

                //can't draw the member in a single row after all!
                if (!DrawerUtility.CanDrawInSingleRow(member))
                {
                    drawInSingleRow = false;
                    member.Dispose();
                    DoBuildMembers();
                    return;
                }

                members[0] = member;
            }
            else
            {
                for (int n = count - 1; n >= 0; n--)
                {
                    var memberFieldInfo = memberBuildList[n];
                    var parameterInfo   = memberFieldInfo.ParameterInfo;
                    var memberLabel     = GUIContentPool.Empty();
                    var type            = GetParameterTypeAndLabel(memberFieldInfo, ref memberLabel);
                    var member          = DrawerProvider.GetForField(ParameterValues.GetValue(parameterInfo), type, memberFieldInfo, this, memberLabel, ReadOnly);

                                        #if DEV_MODE || SAFE_MODE
                    if (member == null)
                    {
                        for (int d = count - 1; d > n; d--)
                        {
                            members[d].Dispose();
                        }
                        Debug.LogError(ToString() + " Failed to create Drawer for members[" + n + "] " + memberFieldInfo + " of type " + StringUtils.ToString(type) + ".\nparent=" + StringUtils.ToString(parent));
                        DrawerArrayPool.Resize(ref members, 0);
                        return;
                    }
                                        #endif

                    members[n] = member;
                }
            }
        }