コード例 #1
0
        /// <summary>
        /// Sets up the drawer so that it is ready to be used.
        /// LateSetup should be called right after this.
        /// </summary>
        /// <param name="setStyle"> GUIStyle inside which to draw members. </param>
        /// <param name="indentLevel"> How many levels of indentation to add when drawing members. </param>
        /// <param name="setDrawHeader"> Should the prefix label header be drawn for the dataset. </param>
        /// <param name="setValue"> The initial cached value of the drawers. </param>
        /// <param name="setValueType"> Type constraint for the value. </param>
        /// <param name="setMemberInfo"> LinkedMemberInfo for the field or property that these drawers represent. </param>
        /// <param name="setParent"> Drawer whose member these Drawer are. Can be null. </param>
        /// <param name="setLabel"> The label (name) of the field. Can be null. </param>
        /// <param name="setReadOnly"> True if Drawer should be read only. </param>
        private void Setup(GUIStyle setStyle, int indentLevel, bool setDrawHeader, object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            style               = new GUIStyle(setStyle);
            style.fixedHeight   = 0f;
            style.fixedWidth    = 0f;
            style.stretchHeight = true;
            style.stretchWidth  = true;

            appendIndentLevel = indentLevel;
            drawHeader        = setDrawHeader;

            if (setValueType == null)
            {
                                #if DEV_MODE
                Debug.LogWarning(GetType().Name + ".Setup called with null setValueType");
                                #endif
                setValueType = DrawerUtility.GetType(setMemberInfo, setValue);
            }

            // This is an important step, because parent is referenced by DebugMode
            parent          = setParent;
            drawInSingleRow = DrawerUtility.CanDrawInSingleRow(setValueType, DebugMode);

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);

                        #if DEV_MODE && DEBUG_DRAW_IN_SINGLE_ROW
            if (drawInSingleRow)
            {
                Debug.Log(Msg(ToString(setLabel, setMemberInfo) + ".Setup with drawInSingleRow=", drawInSingleRow, ", type=", setValueType, ", DebugMode=", DebugMode));
            }
                        #endif
        }
コード例 #2
0
        private void Setup(ParameterInfo[] setParameterInfos, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE
            if (setReadOnly)
            {
                Debug.LogWarning(StringUtils.ToColorizedString(ToString(), ".Setup - readonly=", true, ". Really don't allow editing parameter value? This is usually desired even for read-only properties."));
            }
                        #endif

            parameterInfos  = setParameterInfos;
            drawInSingleRow = parameterInfos.Length == 1 && DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(parameterInfos[0].ParameterType);

            if (setLabel == null)
            {
                setLabel = GUIContentPool.Create("Parameters");
            }

            int count    = parameterInfos.Length;
            var setValue = ArrayPool <object> .Create(count);

            for (int n = count - 1; n >= 0; n--)
            {
                setValue[n] = ParameterValues.GetValue(parameterInfos[n]);
            }

            // always set readonly to false to fix issue where
            // parameters of read-only indexer Properties could not be modified
            base.Setup(setValue, typeof(object[]), setMemberInfo, setParent, setLabel, setReadOnly);
        }
コード例 #3
0
        private void UpdateDrawInSingleRow()
        {
            bool setDrawInSingleRow;

            if (IsNull)
            {
                setDrawInSingleRow = true;
            }
                        #if DRAW_VALUE_IN_SINGLE_ROW_IF_POSSIBLE
            else if (memberBuildState == MemberBuildState.MembersBuilt)
            {
                setDrawInSingleRow = DrawerUtility.CanDrawInSingleRow(ValueDrawer);
            }
            else if (memberBuildState == MemberBuildState.BuildListGenerated)
            {
                setDrawInSingleRow = DrawerUtility.CanDrawInSingleRow(instanceType, DebugMode);
            }
                        #else
            else if (memberBuildState != MemberBuildState.Unstarted)
            {
                setDrawInSingleRow = DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(instanceType);
            }
                        #endif
            else
            {
                setDrawInSingleRow = true;
            }

            if (setDrawInSingleRow != drawInSingleRow)
            {
                                #if DEV_MODE && DEBUG_UPDATE_DRAW_IN_SINGLE_ROW
                Debug.Log(Msg(ToString(), ".drawInSingleRow = ", setDrawInSingleRow, " (was: ", drawInSingleRow, ") with IsNull=", IsNull, ", memberBuildState = ", memberBuildState, ", instanceType=", instanceType));
                                #endif

                drawInSingleRow = setDrawInSingleRow;

                UpdatePrefixDrawer();

                if (DrawInSingleRow)
                {
                    if (inactive)
                    {
                        SetUnfoldedInstantly(true);
                    }
                    else
                    {
                        SetUnfolded(true);
                    }
                }

                UpdateVisibleMembers();
            }
            else if (prefixLabelDrawer == null)
            {
                                #if DEV_MODE
                Debug.LogError("This null check was needed!");
                                #endif
                UpdatePrefixDrawer();
            }
        }
コード例 #4
0
ファイル: Array3DDrawer.cs プロジェクト: JackBetts/TrafficCop
 /// <inheritdoc />
 public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
                 #if DEV_MODE && PI_ASSERTATIONS
     Debug.Assert(DrawerUtility.GetType(setMemberInfo, setValue).GetArrayRank() == 3);
                 #endif
     Setup(setValue as Array, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
 }
コード例 #5
0
 /// <inheritdoc />
 public override float GetOptimalPrefixLabelWidth(int indentLevel)
 {
     if (HasUnappliedChanges)
     {
         return(Mathf.Max(80f, DrawerUtility.GetOptimalPrefixLabelWidth(indentLevel, label, true)));
     }
     return(Mathf.Max(71f, DrawerUtility.GetOptimalPrefixLabelWidth(indentLevel, label)));
 }
コード例 #6
0
 /// <summary>
 /// Sets up the drawer so that it is ready to be used.
 /// LateSetup should be called right after this.
 /// </summary>
 /// <param name="setKeyType"> The type of the key used in the dictionary. Can not be null. </param>
 /// <param name="setValidateKey"> Function used for validating the current key value set up in the add button. Can be null. </param>
 /// <param name="setOnAddButtonClicked"> Delegate called when the add button is clicked. Can be null. </param>
 /// <param name="setMemberInfo"> LinkedMemberInfo for the field or property that these drawers represent. </param>
 /// <param name="setParent"> Drawer whose member these Drawer are. Can not be null. </param>
 /// <param name="setLabel"> The label (name) of the field. Can be null. </param>
 /// <param name="setReadOnly"> True if Drawer should be read only. </param>
 private void Setup([NotNull] Type setKeyType, [CanBeNull] Func <object[], bool> setValidateKey, [CanBeNull] Action setOnAddButtonClicked, [CanBeNull] LinkedMemberInfo setMemberInfo, [NotNull] IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
     keyType            = setKeyType;
     drawInSingleRow    = DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(keyType);
     validateKey        = setValidateKey;
     onAddButtonClicked = setOnAddButtonClicked;
     base.Setup(keyType.DefaultValue(), keyType, setMemberInfo, setParent, setLabel, setReadOnly);
 }
コード例 #7
0
        /// <inheritdoc/>
        protected override void Setup(Enum setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(DrawerUtility.GetType(setMemberInfo, setValue) != Types.Enum, "Fields of exact type Enum should use AnyEnumDrawer, not EnumDrawer!");
                        #endif

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
            hasFlagsAttribute = Type.IsDefined(Types.FlagsAttribute, false);
        }
コード例 #8
0
        /// <inheritdoc/>
        public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var type = DrawerUtility.GetType(setMemberInfo, setValue);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(type != null);
            Debug.Assert(setValue != null || setMemberInfo != null);
                        #endif

            Setup(setValue, setMemberInfo, Nullable.GetUnderlyingType(type), setParent, setLabel, setReadOnly);
        }
コード例 #9
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>
        /// <param name="setReadOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static GradientDrawer Create(Gradient value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool setReadOnly)
        {
            GradientDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new GradientDrawer();
            }
            result.Setup(value, DrawerUtility.GetType(memberInfo, value), memberInfo, parent, label, setReadOnly);
            result.LateSetup();
            return(result);
        }
コード例 #10
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="methodInfo"> LinkedMemberInfo of the method that the drawer represent. If represents an anonymous method, leave null. </param>
        /// <param name="parent"> The parent drawer of this member. Can be null. </param>
        /// <param name="label"> The label. </param>
        /// <param name="setReadOnly"> True if control should be read only. </param>
        /// <returns> The newly-created instance. </returns>
        public static DelegateDrawer Create([CanBeNull] MulticastDelegate value, [CanBeNull] LinkedMemberInfo methodInfo, IParentDrawer parent, GUIContent label, bool setReadOnly)
        {
            DelegateDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new DelegateDrawer();
            }
            result.Setup(value, DrawerUtility.GetType(methodInfo, value), methodInfo, parent, label, setReadOnly);
            result.LateSetup();
            return(result);
        }
コード例 #11
0
ファイル: AnyEnumDrawer.cs プロジェクト: JackBetts/TrafficCop
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="value"> The initial cached value of the drawer. </param>
        /// <param name="memberInfo"> LinkedMemberInfo for the class member that the created 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>
        /// <param name="readOnly"> True if drawer should be read only. </param>
        /// <returns> The drawer instance, ready to be used. </returns>
        public static AnyEnumDrawer Create(object value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            AnyEnumDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new AnyEnumDrawer();
            }
            result.Setup(value, DrawerUtility.GetType(memberInfo, value), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
コード例 #12
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="style"> GUIStyle inside which to draw members. </param>
        /// <param name="appendIndentLevel"> How many levels of indentation to add when drawing members. </param>
        /// <param name="drawHeader"> Should the prefix label header be drawn for the dataset. </param>
        /// <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>
        /// <param name="readOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static StyledDataSetDrawer Create(GUIStyle style, int appendIndentLevel, bool drawHeader, object value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            StyledDataSetDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new StyledDataSetDrawer();
            }
            result.Setup(style, appendIndentLevel, drawHeader, value, DrawerUtility.GetType(memberInfo, value), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
コード例 #13
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="keyType"> The type of the keys in the dictionary. </param>
        /// <param name="valueType"> The type of the values in the dictionary. </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>
        /// <param name="readOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static DictionaryEntryDrawer Create(DictionaryEntry value, Type keyType, Type valueType, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly, Func <int, object[], bool> validateKey)
        {
            DictionaryEntryDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new DictionaryEntryDrawer();
            }
            result.Setup(value, DrawerUtility.GetType(memberInfo, value), keyType, valueType, memberInfo, parent, label, readOnly, validateKey);
            result.LateSetup();
            return(result);
        }
コード例 #14
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="list"> 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>
        /// <param name="readOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static ListDrawer <T> Create(IList <T> list, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            ListDrawer <T> result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new ListDrawer <T>();
            }
            result.Setup(list, DrawerUtility.GetType(memberInfo, list), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
コード例 #15
0
        /// <inheritdoc />
        public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var array = setValue as Array;

                        #if DEV_MODE && PI_ASSERTATIONS
            var type = DrawerUtility.GetType(setMemberInfo, array);
            Debug.Assert(type != null, "ArrayDrawer - failed to figure out type from value / member info.");
            var typeFullName = type.FullName;
            Debug.Assert(type.IsArray, typeFullName + " not an array.");
            Debug.Assert(type.GetArrayRank() == 1, typeFullName + " array rank not 1.");
                        #endif
            Setup(array, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
        }
コード例 #16
0
        /// <inheritdoc />
        public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var type = DrawerUtility.GetType(setMemberInfo, setValue);

            if (type.IsArray)
            {
                Setup(setValue as ParameterInfo[], setMemberInfo, setParent, setLabel, setReadOnly);
            }
            else
            {
                Setup(ArrayPool <ParameterInfo> .CreateWithContent(setValue as ParameterInfo), setMemberInfo, setParent, setLabel, setReadOnly);
            }
        }
コード例 #17
0
        private void Setup(object setValue, [CanBeNull] UnityEditor.PropertyDrawer setDrawerInstance, [NotNull] Type drawerType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerType != null);
                        #endif

            if (setDrawerInstance == null)
            {
                setDrawerInstance = (UnityEditor.PropertyDrawer)drawerType.CreateInstance();
            }
            drawerInstance = setDrawerInstance;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerInstance != null, "Failed to create PropertyDrawer instance of type " + StringUtils.ToString(drawerType) + " for field of type " + StringUtils.ToString(DrawerUtility.GetType(setMemberInfo, setValue)) + " and attribute " + StringUtils.TypeToString(setMemberInfo == null ? null : setMemberInfo.GetAttribute <PropertyAttribute>()));
                        #endif

            memberInfo = setMemberInfo;

            var serializedProperty = SerializedProperty;
            if (serializedProperty != null)
            {
                // This is not fool-proof, because e.g. a custom property might use a foldout drawer
                // but could not figure out a better solution yet
                usesFoldout = serializedProperty.isArray;
            }
            else
            {
                usesFoldout = false;
            }

            var attField = drawerType.GetField("m_Attribute", BindingFlags.Instance | BindingFlags.NonPublic);

            if (setMemberInfo != null)
            {
                var atts = setMemberInfo.GetAttributes(Types.PropertyAttribute);
                if (atts.Length > 0)
                {
                    attField.SetValue(drawerInstance, atts[0]);
                }

                attField = drawerType.GetField("m_FieldInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                attField.SetValue(drawerInstance, setMemberInfo.FieldInfo);
            }
            else
            {
                Debug.LogError("PropertyDrawerDrawer(\"" + (setLabel != null ? setLabel.text : "") + "\").Setup(" + drawerType.Name + ") - fieldInfo was null (parent=" + StringUtils.ToString(setParent) + ")");
            }

            base.Setup(setValue, DrawerUtility.GetType(setMemberInfo, setValue), setMemberInfo, setParent, setLabel, setReadOnly);
        }
コード例 #18
0
        /// <inheritdoc />
        protected override void Setup(Type[] setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            memberInfo       = setMemberInfo;
            genericArguments = setMemberInfo.MethodInfo.GetGenericArguments();

            drawInSingleRow = genericArguments.Length == 1 && DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(genericArguments[0]);

            if (setLabel == null)
            {
                setLabel = GUIContentPool.Create("Generics");
            }

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
        }
コード例 #19
0
        private void Setup(DictionaryEntry setValue, Type setValueType, Type entryKeyType, Type entryValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly, [CanBeNull] Func <int, object[], bool> setValidateKey)
        {
            keyType     = entryKeyType;
            valueType   = entryValueType;
            validateKey = setValidateKey == null ? ValidateNotNull : setValidateKey;

            drawInSingleRow = DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(entryKeyType) && DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(entryValueType);


            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);

                        #if DEV_MODE && DEBUG_SETUP
            Debug.Log("DictionaryEntryDrawer<" + StringUtils.ToString(keyType) + "," + StringUtils.ToString(valueType) + "> created with drawInSingleRow=" + StringUtils.ToColorizedString(drawInSingleRow) + ", value=" + StringUtils.ToString(Value));
                        #endif
        }
コード例 #20
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="array"> 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>
        /// <param name="readOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static Array2DDrawer Create(Array array, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            Array2DDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new Array2DDrawer();
            }
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(DrawerUtility.GetType(memberInfo, array).GetArrayRank() == 2);
                        #endif
            result.Setup(array, DrawerUtility.GetType(memberInfo, array), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
コード例 #21
0
        public static ICollectionDrawer Create(Array value, LinkedMemberInfo memberInfo, [CanBeNull] IParentDrawer parent, GUIContent label, bool readOnly)
        {
            if (value == null)
            {
                                #if DEV_MODE
                Debug.Assert(memberInfo != null, "Array.Create - both value and memberInfo null!");
                                #endif

                value = memberInfo.DefaultValue() as Array;
                if (value == null)
                {
                                        #if DEV_MODE
                    Debug.LogError("Array.Create(" + memberInfo + ") of type " + StringUtils.ToString(memberInfo.Type) + ": value was null and memberInfo.DefaultValue() returned null!");
                                        #endif
                    return(null);
                }

                if (memberInfo.CanWrite)
                {
                    memberInfo.SetValue(value);
                }
            }

            switch (value.Rank)
            {
            case 1:
                break;

            case 2:
                return(Array2DDrawer.Create(value, memberInfo, parent, label, readOnly));

            case 3:
                return(Array3DDrawer.Create(value, memberInfo, parent, label, readOnly));

            default:
                return(null);
            }

            ArrayDrawer result;
            if (!DrawerPool.TryGet(out result))
            {
                result = new ArrayDrawer();
            }
            result.Setup(value, DrawerUtility.GetType(memberInfo, value), memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
コード例 #22
0
        /// <inheritdoc />
        public override bool DrawBody(Rect position)
        {
            HandleDrawHintIcon(position);

            DrawDragBarIfReorderable();

            var guiChangedWas = GUI.changed;

            GUI.changed = false;
            bool       guiChanged;
            bool       mixedContent            = MixedContent;
            const char valueDuringMixedContent = '\0';
            var        valueWas = mixedContent ? valueDuringMixedContent : Value;
            char       setValue;

            DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, memberInfo == null ? false : memberInfo.MixedContent);
            {
                setValue   = DrawControlVisuals(controlLastDrawPosition, valueWas);
                guiChanged = GUI.changed;
            }
            DrawerUtility.EndInputField();

            if (guiChanged)
            {
                                #if DEV_MODE && DEBUG_VALUE_CHANGED
                var e = Event.current;
                Debug.Log(StringUtils.ToColorizedString(ToString(), " DrawControlVisuals GUI.changed detected! valueWas=", valueWas, ", setValue=", setValue, " EditingTextField =", DrawGUI.EditingTextField, ", Event type=", e.type, ", rawType=", e.type, ", isKey=", e.isKey, ", isMouse=", e.isMouse, ", keyCode=", e.keyCode, ", character=", StringUtils.ToString(e.character)));
                                #endif

                if (ReadOnly)
                {
                    return(false);
                }

                if (!valueWas.Equals(setValue))
                {
                                        #if DEV_MODE && DEBUG_VALUE_CHANGED
                    Debug.Log(ToString() + " DrawControlVisuals changed value from " + valueWas + " to" + setValue);
                                        #endif

                    Value = setValue;
                    return(true);
                }
            }

            return(false);
        }
コード例 #23
0
        /// <inheritdoc />
        public override bool DrawBody(Rect position)
        {
                        #if SAFE_MODE
            if (label == null)
            {
                Debug.LogError("DrawBody with null label called for " + ToString() + " with parent " + (parent == null ? "null" : parent.ToString()));
                return(false);
            }
                        #endif

            HandleDrawHintIcon(position);

            DrawDragBarIfReorderable();

                        #if DEV_MODE && DEBUG_NULL_FIELD_INFO
            if (fieldInfo == null)
            {
                Debug.LogWarning(GetType().Name + ".DrawBody() - fieldInfo was null!");
            }
                        #endif

            var valueWas = Value;

            DrawDragBarIfReorderable();

            DrawerUtility.BeginFocusableField(this, controlId, ref focusField, MixedContent);
            var setValue = DrawControlVisuals(position, valueWas);
            DrawerUtility.EndFocusableField();

            if (setValue == null)
            {
                if (valueWas == null)
                {
                    return(false);
                }
                Value = default(TValue);
                return(true);
            }

            if (!setValue.Equals(valueWas))
            {
                Value = setValue;
                return(true);
            }

            return(false);
        }
コード例 #24
0
        private void Setup(object setValue, [CanBeNull] object attribute, [CanBeNull] UnityEditor.PropertyDrawer setDrawerInstance, [NotNull] Type drawerType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerType != null);
                        #endif

            if (setDrawerInstance == null)
            {
                setDrawerInstance = (UnityEditor.PropertyDrawer)drawerType.CreateInstance();
            }
            drawerInstance = setDrawerInstance;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerInstance != null, "Failed to create PropertyDrawer instance of type " + StringUtils.ToString(drawerType) + " for field of type " + StringUtils.ToString(DrawerUtility.GetType(setMemberInfo, setValue)) + " and attribute " + StringUtils.TypeToString(setMemberInfo == null ? null : setMemberInfo.GetAttribute <PropertyAttribute>()));
                        #endif

            memberInfo = setMemberInfo;

            var attField = drawerType.GetField("m_Attribute", BindingFlags.Instance | BindingFlags.NonPublic);

            if (setMemberInfo != null)
            {
                if (attribute != null)
                {
                                        #if DEV_MODE && DEBUG_ENABLED
                    Debug.Log("Setting field " + drawerType.Name + ".m_Attribute value to " + StringUtils.TypeToString(attribute));
                                        #endif

                    attField.SetValue(drawerInstance, attribute);
                }

                attField = drawerType.GetField("m_FieldInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                attField.SetValue(drawerInstance, setMemberInfo.FieldInfo);
            }
            else
            {
                Debug.LogError("PropertyDrawerDrawer(\"" + (setLabel != null ? setLabel.text : "") + "\").Setup(" + drawerType.Name + ") - fieldInfo was null (parent=" + StringUtils.ToString(setParent) + ")");
            }

            base.Setup(setValue, DrawerUtility.GetType(setMemberInfo, setValue), setMemberInfo, setParent, setLabel, setReadOnly);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(SerializedProperty != null, StringUtils.ToColorizedString(GetDevInfo()));
                        #endif
        }
コード例 #25
0
        public static new MethodButtonDrawer Create([NotNull] LinkedMemberInfo methodInfo, [CanBeNull] IParentDrawer parent, GUIContent label, bool setReadOnly)
        {
                        #if GENERIC_METHODS_NOT_SUPPORTED
            if (fieldInfo.MethodInfo.IsGenericMethod)
            {
                return(null);
            }
                        #endif

            MethodButtonDrawer result;
            if (!DrawerPool.TryGet(out result))
            {
                result = new MethodButtonDrawer();
            }
            result.Setup(null, DrawerUtility.GetType <object>(methodInfo, null), methodInfo, parent, label, setReadOnly);
            result.LateSetup();
            return(result);
        }
コード例 #26
0
        /// <inheritdoc />
        public override bool DrawBody(Rect position)
        {
            HandleDrawHintIcon(position);

            DrawDragBarIfReorderable();

            var guiChangedWas = GUI.changed;

            GUI.changed = false;
            bool   changed;
            string valueWas = Value;
            string setValue;

            DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, MixedContent);
            {
                setValue = DrawControlVisuals(controlLastDrawPosition, valueWas);
                changed  = GUI.changed;
            }
            DrawerUtility.EndInputField();

            if (changed)
            {
                                #if DEV_MODE && DEBUG_VALUE_CHANGED
                Debug.Log(ToString() + " DrawControlVisuals GUI.changed detected! EditingTextField=" + DrawGUI.EditingTextField);
                                #endif

                // When MixedContent is true and GUI.changed becomes true during DrawControlVisuals, we assume
                // that the value has been changed by the user, even if valueWas equals the new value. This is because it is possible that
                // the user happens to enters a value that happens to match that of the passed cached value, in which case
                // if we only used an ValuesAreEqual, it would return false, and the values of all targets would not get unified.
                if (!ReadOnly && (MixedContent || !string.Equals(valueWas, setValue)))
                {
                                        #if DEV_MODE && DEBUG_VALUE_CHANGED
                    Debug.Log(ToString() + " DrawControlVisuals changed value from " + StringUtils.ToString(setValue) + " to " + StringUtils.ToString(valueWas));
                                        #endif

                    Value = setValue;
                    return(true);
                }
            }
            GUI.changed = guiChangedWas;
            return(false);
        }
コード例 #27
0
        /// <inheritdoc />
        protected override void Setup(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            if (setValueType == null)
            {
                                #if DEV_MODE
                Debug.LogWarning(GetType().Name + ".Setup called with setValueType=null");
                                #endif
                setValueType = DrawerUtility.GetType(setMemberInfo, setValue);
            }
            var types     = setValueType.GetGenericArguments();
            var keyType   = types[0];
            var valueType = types[1];
            drawInSingleRow = DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(keyType) && DrawerUtility.CanDrawMultipleControlsOfTypeInSingleRow(valueType);

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);

                        #if DEV_MODE && DEBUG_SETUP
            Debug.Log(StringUtils.ToColorizedString("ReadOnly=", ReadOnly));
                        #endif
        }
コード例 #28
0
        public IDrawer FindDrawer(LinkedMemberInfo memberInfo)
        {
            if (memberInfo == null)
            {
                return(null);
            }

            var obj = memberInfo.UnityObject;

            if (obj == null)
            {
                return(null);
            }

            var objDrawer = FindDrawer(obj);

            if (objDrawer != null)
            {
                return(DrawerUtility.FindFieldDrawerInMembers(memberInfo, objDrawer));
            }
            return(null);
        }
コード例 #29
0
        /// <inheritdoc />
        protected override void Setup(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            if (allDelegateTypes == null)
            {
                allDelegateTypes = TypeExtensions.GetExtendingNonUnityObjectClassTypes(Types.MulticastDelegate, true);
            }

            if (setValueType == null)
            {
                                #if DEV_MODE
                Debug.LogError(GetType().Name + ".Setup called with setValueType null");
                                #endif

                setValueType = DrawerUtility.GetType(setMemberInfo, setValue);
                if (!typeof(Delegate).IsAssignableFrom(setValueType))
                {
                    setValueType = typeof(MulticastDelegate);
                }
            }

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);
        }
コード例 #30
0
        /// <inheritdoc/>
        public sealed override bool DrawBody(Rect position)
        {
            HandleDrawHintIcon(position);
            DrawDragBarIfReorderable();

            var valueWas = Value;
            var setValue = valueWas;

            if (HasNumberField)
            {
                DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, MixedContent);
                setValue = DrawNumberFieldVisuals(NumberFieldPosition, setValue);
                DrawerUtility.EndInputField();
            }

            sliderID = GUIUtility.GetControlID(FocusType.Keyboard);
            DrawerUtility.BeginFocusableField(this, sliderID, ref focusSlider, MixedContent);
            {
                if (DrawGUI.EditingTextField)
                {
                    DrawControlVisuals(SliderPosition, setValue);
                }
                else
                {
                    setValue = DrawControlVisuals(SliderPosition, setValue);
                }
            }
            DrawerUtility.EndFocusableField();

            if (!setValue.Equals(valueWas))
            {
                Value = setValue;
                return(true);
            }

            return(false);
        }