• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wooolly · May 12, 2018 at 02:07 PM · guieditorattributeproperty drawer

Multiple attributes

Hello!

I'm currently working on adding some additional attributes to Unity to display messages when I need to. The messages work nicely, and I'm able to display the original property as it's supposed to be below the message. So for example, this: Image of two attributes used on a single property However, it always shows the property as it would be by default, and doesn't seem to support multiple attributes. Take the below example... Image of 2 properties, one with a message prop, and other just as slider Here, I have two properties, both have the slider attribute, but only the one without a message works - the other has defaulted back to being a regular integer box! Here is my code of the properties...

     [SerializeField]
     [Error("This is an error message")]
     private Camera cam = null; 


     // Movement speed
     [SerializeField]
     [Range(10f, 200f, order = 0)]
     [Warning("This is a warning message", order = 1)] 
     private float rotationSpeed = 60f;

     [SerializeField]
     [Range(10f, 200f)]
     private float zoomSpeed = 100f;

I'm using the optional order attribute because I thought if it drew the scroller first it may work, but nope. And here is my code for the property drawer...

 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
             
     // Begin
     EditorGUI.BeginProperty(position, label, property);
     // Add message
     position.height = GetPropertyHeight(property, label) / NUM_ROWS;
     MessageAttribute attr = attribute as MessageAttribute;
     EditorGUI.HelpBox(position, attr.text, attr.messageType);
     // Add original editor contents
     position.y = position.y + GetPropertyHeight(property, label) / NUM_ROWS;
     GUIContent newLabel = new GUIContent("");
     GUIContent[] subLabels = { newLabel };
     EditorGUI.MultiPropertyField(position, subLabels, property, label);
     // End
     EditorGUI.EndProperty();
             
 }

I'm using MultiPropertyField as that's the simplest way I found of recreating the original inspector element. I'd really like for it to become a slider, any help is much appreciated!

doubleattr2.png (3.4 kB)
doubleattr.png (2.3 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · May 13, 2018 at 09:22 PM 1
Share

I've dabbled a lot with this in the past. It's a shame after many years Unity still lack this basic editor functionality. If you want to stick with Unity's, maybe write a custom property that supports all your property needs. So it would support an info message, slider, etc. All in one attribute class, and then in your drawer, you figure what fields are being used in the attribute and draw things accordingly. Does that make sense? If you don't want to stick to Unity, check out VFW. It's old but it still works.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

169 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Min Attribute Not Working on Custom Property Drawer 0 Answers

EditorGUI elements require minimum size of 24px? 0 Answers

How do I prevent "Argument Exception: Getting control 1's position in a group with only 1 controls when doing repaint" in OnGUI function of my CustomPropertyDrawer? 2 Answers

Playmaker editor won't show Please Help 1 Answer

Are there any Editor fields which are Drag and Drop? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges