示例#1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, RequiredAttribute attribute, GUIContent label)
        {
            if (property.ValueEntry.BaseValueType.IsValueType)
            {
                AllEditorGUI.ErrorMessageBox("Value types cannot be null, and thus cannot be marked as required.");
                return;
            }

            // Message context.
            PropertyContext <StringMemberHelper> context = null;

            if (attribute.ErrorMessage != null)
            {
                context = property.Context.Get <StringMemberHelper>(this, "ErrorMessage", (StringMemberHelper)null);
                if (context.Value == null)
                {
                    context.Value = new StringMemberHelper(property.ParentType, attribute.ErrorMessage);
                }

                if (context.Value.ErrorMessage != null)
                {
                    AllEditorGUI.ErrorMessageBox(context.Value.ErrorMessage);
                }
            }

            var isMissing = CheckIsMissing(property);

            if (isMissing)
            {
                string msg = attribute.ErrorMessage != null?context.Value.GetString(property) : (property.NiceName + " is required.");

                if (attribute.MessageType == InfoMessageType.Warning)
                {
                    AllEditorGUI.WarningMessageBox(msg);
                }
                else if (attribute.MessageType == InfoMessageType.Error)
                {
                    AllEditorGUI.ErrorMessageBox(msg);
                }
                else
                {
                    EditorGUILayout.HelpBox(msg, (MessageType)attribute.MessageType);
                }
            }

            var key = UniqueDrawerKey.Create(property, this);

            AllEditorGUI.BeginShakeableGroup(key);
            this.CallNextDrawer(property, label);
            AllEditorGUI.EndShakeableGroup(key);

            if (!isMissing && CheckIsMissing(property))
            {
                AllEditorGUI.StartShakingGroup(key);
            }
        }