/// <summary>
        /// Given a non-abstract explicitly chosen type, returns the drawer for the value of the drawer using said type.
        /// </summary>
        /// <param name="typeForValue"> Type of value. </param>
        /// <returns> Drawer instance to use for the value. </returns>
        protected virtual IDrawer BuildDrawerForValue(Type typeForValue)
        {
                        #if DEV_MODE && DEBUG_DRAW_IN_SINGLE_ROW
            Debug.Log("BuildDrawerForValue(" + typeForValue.Name + ") called with DrawInSingleRow=" + DrawInSingleRow + ", CanDrawInSingleRow(" + typeForValue.Name + ")=" + DrawerUtility.CanDrawInSingleRow(typeForValue, DebugMode) + ", CanDrawMultipleControlsOfTypeInSingleRow(" + typeForValue.Name + ")=" + DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(typeForValue));
                        #endif

                        #if DEV_MODE
            Debug.Assert(typeForValue != null);
            Debug.Assert(!typeForValue.IsGenericTypeDefinition);
                        #endif

            if (typeForValue.IsUnityObject())
            {
                return(ObjectReferenceDrawer.Create(Value as Object, memberInfo, GetTypeForObjectReferenceField(), this, GUIContent.none, AllowSceneObjects(), false, ReadOnly));
            }

            var label = GUIContentPool.Create(StringUtils.SplitPascalCaseToWords(StringUtils.ToStringSansNamespace(typeForValue)));

            // infinite loop danger!
            if (memberInfo != null && typeForValue == memberInfo.Type)
            {
                                #if DEV_MODE
                Debug.LogError("Infinite loop! typeForValue " + StringUtils.ToString(typeForValue) + " same as Type! instanceType=" + StringUtils.ToString(instanceType) + ", userSelectedType=" + StringUtils.ToString(userSelectedType));
                                #endif
                return(ReadOnlyTextDrawer.Create(StringUtils.ToString(Value), memberInfo, this, label));
            }

            return(BuildDrawerForValue(typeForValue, Value, memberInfo, this, label, ReadOnly));
        }
예제 #2
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="value"> The starting cached value of the drawer. </param>
        /// <param name="memberInfo"> LinkedMemberInfo for the field, property or parameter that the drawer represents. Can be null. </param>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="label"> The prefix label. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static ReadOnlyTextDrawer Create(string value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label = null)
        {
            ReadOnlyTextDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new ReadOnlyTextDrawer();
            }
            result.Setup(value, typeof(string), memberInfo, parent, label, true);
            result.LateSetup();
            return(result);
        }
예제 #3
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
            }
        }