Ejemplo n.º 1
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE && DEBUG_BUILD_MEMBERS
            Debug.Log(ToString() + ".DoBuildMembers called with invocationList " + StringUtils.ToString(invocationList));
                        #endif

            int count = invocationList.Length;

            if (count == 0)
            {
                DrawerArrayPool.Resize(ref members, 1);
                members[0] = NullToggleDrawer.Create(AddNewItemToInvocationList, InspectorPreferences.Styles.AddButton, this, ReadOnly);
            }
            else
            {
                DrawerArrayPool.Resize(ref members, count);

                var type = Type;
                for (int n = count - 1; n >= 0; n--)
                {
                    var invocationMember = invocationList[n];
                    members[n] = DelegateItemDrawer.Create(invocationMember, type, this, GUIContentPool.Create("Delegate #" + StringUtils.ToString(n + 1)), ReadOnly);
                    members[n].OnKeyboardInputBeingGiven += OnMemberKeyboardInputBeingGiven;
                }
            }
        }
Ejemplo n.º 2
0
        public void RebuildIntructionsInChildren()
        {
            DisposeChildren();
            AddComponentMenuItem[] values;
            if (activeItem == null)
            {
                values = AddComponentMenuItems.GetFiltered(FilterString);
            }
            else
            {
                values = activeItem.children;
            }

            int count = values.Length;

            DrawerArrayPool.Resize(ref members, count);

            for (int n = 0; n < count; n++)
            {
                members[n] = AddComponentMenuItemDrawer.Create(values[n]);
            }
            UpdateContentRect();

            SetScrollPos(0f, false);
            SetSelectedMember(0, false);
            UpdateVisibleMembers();
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            bool readOnly = memberInfo != null && !memberInfo.CanWrite;

            if (readOnly)
            {
                DrawerArrayPool.Resize(ref members, 0);
            }
            else
            {
                DrawerArrayPool.Resize(ref members, 2);

                var min = TimeSpan.MinValue;
                var max = TimeSpan.MaxValue;

                var group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Days / Hours"), ReadOnly);
                {
                    var groupMembers = DrawerArrayPool.Create(2);

                    var groupMember = ClampedIntDrawer.Create(Days, min.Days, max.Days, null, group, GUIContentPool.Create("D"), ReadOnly);
                    groupMember.OnValueChanged += SetDays;
                    groupMembers[0]             = groupMember;

                    groupMember = ClampedIntDrawer.Create(Hours, MinHours, MaxHours, null, group, GUIContentPool.Create("H"), ReadOnly);
                    groupMember.OnValueChanged       += SetHours;
                    groupMember.OverrideValidateValue = ValidateHours;
                    groupMembers[1] = groupMember;

                    group.SetMembers(groupMembers, true);
                    members[0] = group;
                }

                group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Minutes / Seconds"), ReadOnly);
                {
                    var groupMembers = DrawerArrayPool.Create(2);

                    var groupMember = ClampedIntDrawer.Create(Minutes, MinMinutes, MaxMinutes, null, group, GUIContentPool.Create("M"), ReadOnly);
                    groupMember.OnValueChanged       += SetMinutes;
                    groupMember.OverrideValidateValue = ValidateMinutes;
                    groupMembers[0] = groupMember;

                    var secondsMember = ClampedFloatDrawer.Create(SecondsWithFractions, MinSeconds, MaxSeconds, null, group, GUIContentPool.Create("S"), ReadOnly);
                    secondsMember.OnValueChanged       += SetSeconds;
                    secondsMember.OverrideValidateValue = ValidateSeconds;
                    groupMembers[1] = secondsMember;

                    group.SetMembers(groupMembers, true);
                    members[1] = group;
                }
            }
        }
Ejemplo n.º 5
0
        public void UpdateVisibleMembers()
        {
            GUI.changed = true;

            int count = lastVisibleIndex - firstVisibleIndex + 1;

            DrawerArrayPool.Resize(ref visibleMembers, count);
            for (int n = count - 1; n >= 0; n--)
            {
                var member = members[firstVisibleIndex + n];
                visibleMembers[n] = member;

                visibleMembersHaveConflicts[n] = AddComponentUtility.HasConflictingMembers(member.Type, target);
            }
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            int count = memberBuildList.Count;

            var genericTypeArguments = Value;

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

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

            DrawerArrayPool.Resize(ref members, count);
            for (int n = count - 1; n >= 0; n--)
            {
                var            argumentMemberInfo = memberBuildList[0];
                var            type = argumentMemberInfo.Type;
                var            baseTypeConstraints = type.GetGenericParameterConstraints();
                TypeConstraint typeCategoryConstraint;
                var            specialConstraintMask = type.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
                if ((specialConstraintMask & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
                {
                    typeCategoryConstraint = TypeConstraint.Class;
                }
                else if ((specialConstraintMask & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
                {
                    typeCategoryConstraint = TypeConstraint.Struct;
                }
                else
                {
                    typeCategoryConstraint = TypeConstraint.None;
                }

                if (baseTypeConstraints.Length > 0)
                {
                    members[n] = ConstraintedTypeDrawer.Create(type, baseTypeConstraints, typeCategoryConstraint, argumentMemberInfo, this, GUIContent.none, ReadOnly);
                }
                else
                {
                    members[n] = TypeDrawer.Create(type, argumentMemberInfo, this, GUIContent.none, ReadOnly);
                }
            }
        }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            int count = genericArguments.Length;

            drawInSingleRow = count == 1;

            DrawerArrayPool.Resize(ref members, count);

            if (count == 1)
            {
                var genericArgument = genericArguments[0];
                label.text    = GetLabel(genericArgument);
                label.tooltip = "Generic Argument";
                members[0]    = TypeDrawer.Create(GetDefaultValue(genericArgument), null, this, GUIContentPool.Empty(), false);
            }
            else
            {
                for (int n = count - 1; n >= 0; n--)
                {
                    var    genericArgument = genericArguments[n];
                    string labelText       = GetLabel(genericArgument);
                    string tooltip         = string.Concat("Generic Argument ", StringUtils.ToString(n + 1), "/", StringUtils.ToString(count));
                    members[n] = TypeDrawer.Create(GetDefaultValue(genericArgument), null, this, GUIContentPool.Create(labelText, tooltip), false);
                }
            }

                        #if DEV_MODE
            try
            {
                Debug.Log(ToString() + ".RebuildIntructionsInChildren() - now has " + members.Length + " members:\n" + StringUtils.ToString(members));
            }
            catch (Exception e)            //had a bug where even trying to access "this" resulted in a null reference exception
            {
                Debug.LogError("MethodDrawer.RebuildIntructionsInChildren() " + e);
                return;
            }

            for (int n = 0; n < members.Length; n++)
            {
                Debug.Log(GetType().Name + " Created #" + n + " " + members[n].GetType().Name);
            }
                        #endif
        }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
            if (parent == null)
            {
                return;
            }

                        #if UNITY_EDITOR
            DrawerArrayPool.Resize(ref members, 2);
            var scriptReference = ScriptReferenceDrawer.Create(monoScript, this, monoScript != null);
            scriptReference.OnValueChanged += SetMonoScript;
            members[0] = scriptReference;
            int index = 1;
                        #else
            int index = 0;
                        #endif

            DrawerArrayPool.Resize(ref members, index + 1);

            members[index] = BoxDrawer.Create(this, GUIContentPool.Create(GetWarningMessage()), MessageType.Warning, ReadOnly);
        }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
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
        }
Ejemplo n.º 12
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
            if (DebugMode)
            {
                base.DoBuildMembers();
                return;
            }

            DrawerArrayPool.Resize(ref members, 3);

            bool usingLocalSpace = UsingLocalSpace;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(memberBuildList.Count == (usingLocalSpace ? 3 : 2));
                        #endif

            var labels         = Preferences.labels;
            var firstTransform = (Transform)Target;
            members[0] = PositionDrawer.Create(usingLocalSpace ? firstTransform.localPosition : firstTransform.position, memberBuildList[0], this, labels.Position, ReadOnly);
            members[1] = RotationDrawer.Create(usingLocalSpace ? firstTransform.localEulerAngles : firstTransform.eulerAngles, memberBuildList[1], this, labels.Rotation, ReadOnly);
            var scaleMember = ScaleDrawer.Create(usingLocalSpace ? firstTransform.localScale : firstTransform.lossyScale, memberBuildList[2], this, labels.Scale, ReadOnly);
            members[2] = scaleMember;
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        public override void UpdateVisibleMembers()
        {
            if (!DrawInSingleRow && !Unfolded)
            {
                if (DrawToggleNullButton && members[0].ShouldShowInInspector)
                {
                    if (visibleMembers.Length != 1)
                    {
                        DrawerArrayPool.Resize(ref visibleMembers, 1);
                        visibleMembers[0] = members[0];
                        OnVisibleMembersChanged();
                        OnChildLayoutChanged();
                    }
                                        #if DEV_MODE && DEBUG_UPDATE_VISIBLE_MEMBERS
                    Debug.Log(ToString() + ".UpdateVisibleMembers() - " + visibleMembers.Length + " of " + members.Length + " now visible\nvisibleMembers=" + StringUtils.ToString(visibleMembers) + "\nmembers=" + StringUtils.ToString(members) + "\nUnfolded=" + Unfolded + ", MembersAreVisible=" + MembersAreVisible);
                                        #endif
                    return;
                }

                if (visibleMembers.Length != 0)
                {
                    DrawerArrayPool.Resize(ref visibleMembers, 0);
                    OnVisibleMembersChanged();
                    OnChildLayoutChanged();
                }
                                #if DEV_MODE && DEBUG_UPDATE_VISIBLE_MEMBERS
                Debug.Log(ToString() + ".UpdateVisibleMembers() - " + visibleMembers.Length + " of " + members.Length + " now visible\nvisibleMembers=" + StringUtils.ToString(visibleMembers) + "\nmembers=" + StringUtils.ToString(members) + "\nUnfolded=" + Unfolded + ", MembersAreVisible=" + MembersAreVisible);
                                #endif
                return;
            }

            base.UpdateVisibleMembers();

                        #if DEV_MODE && DEBUG_UPDATE_VISIBLE_MEMBERS
            Debug.Log(ToString() + ".UpdateVisibleMembers() - " + visibleMembers.Length + " of " + members.Length + " now visible\nvisibleMembers=" + StringUtils.ToString(visibleMembers) + "\nmembers=" + StringUtils.ToString(members) + "\nUnfolded=" + Unfolded + ", MembersAreVisible=" + MembersAreVisible + ", DrawInSingleRow=" + DrawInSingleRow + ", DrawToggleNullButton=" + DrawToggleNullButton);
                        #endif
        }
Ejemplo n.º 14
0
        /// <inheritdoc cref="IDrawer.Dispose" />
        public override void Dispose()
        {
            inactive = true;

            ParentDrawerUtility.OnDisposing(Inspector, this);

            cachedValuesNeedUpdating = false;

                        #if ENABLE_SPREADING
            lastUpdateCachedValuesMemberIndex = -1;
                        #endif

            if (memberBuildState == MemberBuildState.MembersBuilt)
            {
                DisposeMembers();
            }

            DrawerArrayPool.Resize(ref members, 0);
            DrawerArrayPool.Resize(ref visibleMembers, 0);
            updateCachedValuesFor.Clear();

            memberBuildState = MemberBuildState.Unstarted;

            memberBuildList.Clear();

            assumeVisibleMembersChangedDuringNextUpdateVisibleMembers = true;

            labelLastDrawPosition.y      = -100f;
            labelLastDrawPosition.width  = 0f;
            labelLastDrawPosition.height = 0f;
            bodyLastDrawPosition.y       = -100f;
            bodyLastDrawPosition.width   = 0f;
            bodyLastDrawPosition.height  = 0f;

            base.Dispose();
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            var value = Value;

            if (value == null)
            {
                DrawerArrayPool.Resize(ref members, 2);
                members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly);
                members[1] = ObjectReferenceDrawer.Create(null, Types.UnityObject, this, GUIContent.none, true, false, ReadOnly);
            }
            else
            {
                var    target    = value.Target;
                bool   hasTarget = target != null;
                Object unityObject;
                bool   isUnityObject;
                bool   isAnonymous;
                string methodName;
                Type   targetType;
                int    methodIndex;
                var    method = value.Method;

                if (hasTarget)
                {
                    targetType = target.GetType();

                    UpdateMethodOptions(targetType, true);

                    unityObject   = target as Object;
                    isUnityObject = unityObject != null;

                    methodName  = method.Name;
                    isAnonymous = methodName[0] == '<';

                    if (isAnonymous)
                    {
                        string methodOrigin = methodName.Substring(1, methodName.IndexOf('>') - 1);
                        methodName = string.Concat("Anonymous Method (", methodOrigin, ")");
                    }

                    methodIndex = Array.IndexOf(methodOptionNames, methodName);
                    if (methodIndex == -1)
                    {
                        methodOptions     = methodOptions.InsertAt(0, method);
                        methodOptionNames = methodOptionNames.InsertAt(0, methodName);
                        methodIndex       = 0;
                    }
                }
                else
                {
                    methodIndex = 0;

                    if (method == null)
                    {
                        targetType    = null;
                        methodName    = "{ }";
                        unityObject   = null;
                        isUnityObject = false;
                        isAnonymous   = false;

                        ArrayPool <MethodInfo> .Resize(ref methodOptions, 1);

                        methodOptions[0] = method;
                        ArrayPool <string> .Resize(ref methodOptionNames, 1);

                        methodOptionNames[0] = methodName;
                    }
                    else
                    {
                        targetType = method.ReflectedType;

                        UpdateMethodOptions(targetType, false);

                        methodName    = method.Name;
                        unityObject   = null;
                        isUnityObject = false;
                        isAnonymous   = methodName[0] == '<';

                        if (isAnonymous)
                        {
                            string methodOrigin = methodName.Substring(1, methodName.IndexOf('>') - 1);
                            methodName = string.Concat("Anonymous Method (", methodOrigin, ")");
                        }

                        methodIndex = Array.IndexOf(methodOptionNames, methodName);
                        if (methodIndex == -1)
                        {
                            methodOptions     = methodOptions.InsertAt(0, method);
                            methodOptionNames = methodOptionNames.InsertAt(0, methodName);
                            methodIndex       = 0;
                        }
                    }
                }

                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(methodOptions.Length == methodOptionNames.Length);
                                #endif

                                #if DEV_MODE
                Debug.Log(Msg(ToString() + ".DoBuildMembers with target=", target, ", type=", targetType, ", isUnityObject=", isUnityObject, ", methodName=", methodName, ", isAnonymous=", isAnonymous + ", methodNames=", StringUtils.ToString(methodOptionNames)));
                                #endif

                if (isUnityObject)
                {
                    DrawerArrayPool.Resize(ref members, 2);
                    members[0] = ObjectReferenceDrawer.Create(unityObject, Types.UnityObject, this, GUIContentPool.Empty(), true, false, ReadOnly);
                    members[1] = PopupMenuDrawer.Create(methodIndex, methodOptionNames, null, this, GUIContentPool.Empty(), ReadOnly);
                }
                else
                {
                    DrawerArrayPool.Resize(ref members, 3);
                    members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly);
                    members[1] = TypeDrawer.Create(targetType, null, this, GUIContentPool.Empty(), ReadOnly);
                    members[2] = PopupMenuDrawer.Create(methodIndex, methodOptionNames, null, this, GUIContentPool.Empty(), ReadOnly);
                }
            }
        }
Ejemplo n.º 16
0
 /// <inheritdoc />
 protected override void DoBuildMembers()
 {
     DrawerArrayPool.Resize(ref members, 1);
     members[0] = ObjectReferenceDrawer.Create(Value, Types.MonoScript, this, GUIContent.none, false, false, ReadOnly);
 }
Ejemplo n.º 17
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            if (ReadOnly)
            {
                DrawerArrayPool.Resize(ref members, 0);
            }
            else
            {
                DrawerArrayPool.Resize(ref members, 2);

                var value = Value;
                asString = StringUtils.TimeToString(value);
                int   year   = value.Year;
                int   month  = value.Month;
                int   day    = value.Day;
                int   hour   = value.Hour;
                int   minute = value.Minute;
                float second = value.Second + value.Millisecond * 0.001f;

                var min = DateTime.MinValue;
                var max = DateTime.MaxValue;

                var group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Date"), false);
                {
                    var groupMembers = DrawerArrayPool.Create(3);

                    var groupMember = ClampedIntDrawer.Create(year, min.Year, max.Year, null, group, GUIContentPool.Create("Y"), false);
                    groupMember.OnValueChanged       += SetYear;
                    groupMember.OverrideValidateValue = ValidateYear;
                    groupMember.overrideReset         = ResetToOne;
                    groupMembers[YearMemberIndex]     = groupMember;

                    groupMember = ClampedIntDrawer.Create(month, min.Month, max.Month, null, group, GUIContentPool.Create("M"), false);
                    groupMember.OnValueChanged       += SetMonth;
                    groupMember.OverrideValidateValue = ValidateMonth;
                    groupMember.overrideReset         = ResetToOne;
                    groupMembers[MonthMemberIndex]    = groupMember;

                    groupMember = ClampedIntDrawer.Create(day, min.Day, max.Day, null, group, GUIContentPool.Create("D"), false);
                    groupMember.OnValueChanged       += SetDay;
                    groupMember.OverrideValidateValue = ValidateDay;
                    groupMember.overrideReset         = ResetToOne;
                    groupMembers[DayMemberIndex]      = groupMember;

                    group.SetMembers(groupMembers, true);
                    members[0] = group;
                }

                group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Time"), false);
                {
                    var groupMembers = DrawerArrayPool.Create(3);

                    var groupMember = ClampedIntDrawer.Create(hour, 0, 23, null, group, GUIContentPool.Create("H"), false);
                    groupMember.OnValueChanged       += SetHour;
                    groupMember.OverrideValidateValue = ValidateHour;
                    groupMembers[HourMemberIndex]     = groupMember;

                    groupMember = ClampedIntDrawer.Create(minute, 0, 59, null, group, GUIContentPool.Create("M"), false);
                    groupMember.OnValueChanged       += SetMinute;
                    groupMember.OverrideValidateValue = ValidateMinute;
                    groupMembers[MinuteMemberIndex]   = groupMember;

                    var secondsMember = ClampedFloatDrawer.Create(second, 0f, 60f - float.Epsilon, null, group, GUIContentPool.Create("S"), false);
                    secondsMember.OnValueChanged       += SetSeconds;
                    secondsMember.OverrideValidateValue = ValidateSecond;
                    groupMembers[SecondMemberIndex]     = secondsMember;

                    group.SetMembers(groupMembers, true);
                    members[1] = group;
                }
            }
        }
Ejemplo n.º 18
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE && DEBUG_BUILD_MEMBERS
            Debug.Log(StringUtils.ToColorizedString(ToString(), ".DoBuildMembers called with memberBuildList=", memberBuildList, ", IsNull = ", IsNull, ", CanBeUnityObject=", CanBeUnityObject, ", DrawToggleNullButton=", DrawToggleNullButton, ", memberInfo=", memberInfo, ", memberInfo.Data=", (memberInfo == null ? "n/a" : StringUtils.ToString(memberInfo.Data))));
                        #endif

            var typeForValue = TypeForValue;

            if (typeForValue == null)
            {
                if (CanBeUnityObject)
                {
                    var referenceField = ObjectReferenceDrawer.Create(null, memberInfo, GetTypeForObjectReferenceField(), this, GUIContent.none, AllowSceneObjects(), false, ReadOnly);
                    if (DrawToggleNullButton)
                    {
                        DrawerArrayPool.Resize(ref members, 2);
                        members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly);
                        members[1] = referenceField;
                    }
                    else
                    {
                        DrawerArrayPool.Resize(ref members, 1);
                        members[0] = referenceField;
                    }
                }
                else if (DrawToggleNullButton)
                {
                    DrawerArrayPool.Resize(ref members, 1);
                    members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly);
                }
                else
                {
                    DrawerArrayPool.Resize(ref members, 1);
                    members[0] = ReadOnlyTextDrawer.Create("null", null, this, GUIContent.none);
                }
            }
            else
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Assert(typeForValue != null, ToString(), ".BuildMembers was called with isNull=false but with userSelectedType=", null, ".\nDrawInSingleRow=", DrawInSingleRow, ", Value=", Value, ", Value.Type=", StringUtils.TypeToString(Value));
                Assert(!typeForValue.IsAbstract, ToString(), ".BuildMembers was called with isNull=false but with userSelectedType ", userSelectedType, " IsAbstract=" + true + ".\nDrawInSingleRow=", DrawInSingleRow, ", Value=", Value, ", Value.Type=", StringUtils.TypeToString(Value));
                                #endif

                var valueDrawer = BuildDrawerForValue(typeForValue);

                                #if DEV_MODE && PI_ASSERTATIONS
                Assert(valueDrawer.GetType() != GetType());
                                #endif

                valueDrawer.OnValueChanged += (changed, setValue) => SetValue(setValue);
                if (DrawToggleNullButton)
                {
                    DrawerArrayPool.Resize(ref members, 2);
                    members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly);
                    members[1] = valueDrawer;
                }
                else
                {
                    DrawerArrayPool.Resize(ref members, 1);
                    members[0] = valueDrawer;
                }

                                #if DRAW_VALUE_IN_SINGLE_ROW_IF_POSSIBLE
                if (DrawerUtility.CanDrawInSingleRow(valueDrawer))
                {
                    valueDrawer.Label = GUIContentPool.Empty();
                }
                                #endif
            }
        }
Ejemplo n.º 19
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE
            Debug.Log(ToString() + ".DoBuildMembers");
                        #endif

            int categoryCount = categorizedBuildList.Count;

            int newMemberCount = categoryCount;

            bool includeAddComponentButton = ShouldIncludeAddComponentButton();
            if (includeAddComponentButton)
            {
                newMemberCount++;
            }

            if (componentsOnlyOnSomeObjectsFound)
            {
                newMemberCount++;
            }

            DrawerArrayPool.Resize(ref members, newMemberCount);

            int index    = 0;
            var readOnly = ReadOnly;
            foreach (var categoryAndComponents in categorizedBuildList)
            {
                var category            = categoryAndComponents.Key;
                var categoryComponents  = categoryAndComponents.Value;
                int categoryMemberCount = categoryComponents.Count;

                if (category.Length == 0)
                {
                    int increaseMemberCount = categoryMemberCount - 1;
                    if (increaseMemberCount > 0)
                    {
                        newMemberCount += increaseMemberCount;
                        DrawerArrayPool.Resize(ref members, newMemberCount);
                    }

                    for (int n = 0; n < categoryMemberCount; n++)
                    {
                        var memberComponents = categoryComponents[n];
                        var componentDrawer  = DrawerProvider.GetForComponents(inspector, memberComponents, this);
                        members[index] = componentDrawer;
                        index++;
                    }
                }
                else
                {
                    var categoryDrawer = CategorizedComponentsDrawer.Create(this, GUIContentPool.Create(category));
                    var setMembers     = DrawerArrayPool.Create(categoryMemberCount);

                    for (int n = 0; n < categoryMemberCount; n++)
                    {
                        var memberComponents = categoryComponents[n];
                        var componentDrawer  = DrawerProvider.GetForComponents(inspector, memberComponents, categoryDrawer);
                        setMembers[n] = componentDrawer;
                    }

                    categoryDrawer.SetMembers(setMembers, true);
                    members[index] = categoryDrawer;
                    index++;
                }
            }

            if (componentsOnlyOnSomeObjectsFound)
            {
                members[index] = GameObjectBoxDrawer.Create(this, GUIContentPool.Create("Components found only on some selected objects can't be multi-edited."));
                index++;
            }

            if (includeAddComponentButton)
            {
                members[index] = AddComponentButtonDrawer.Create(this, inspector);
            }
        }
Ejemplo n.º 20
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;
                }
            }
        }