Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Unity editor GUI, how to prevent "passthrough"/"clickthrough" etc? 0 Answers

Get Mouse Events with EditorWindow 3 Answers

Getting GUI.skin in editor script changed entire Unity Editor GUI 1 Answer

Objects in hearachy change order for no reason 7 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges