Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Firedan1176 · Feb 10, 2015 at 02:20 AM · inspectorcustom-inspectorserializedproperty

Property Drawers confusion

I've been trying to adapt a snippet of code from the live training tutorials in the property drawers one to use it. This is what I'm using:

     public static void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
         EditorGUI.BeginProperty (position, label, property);
         position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID(FocusType.Passive), label);
         var indent = EditorGUI.indentLevel;
         EditorGUI.indentLevel = 0;
 
         Rect amountRect = new Rect(position.x, position.y, 30, position.height);
         Rect unitRect = new Rect(position.x + 35, position.y, 50, position.height);
         Rect nameRect = new Rect(position.x + 90, position.y, position.width - 90, position.height);
 
         EditorGUI.PropertyField (amountRect, property.FindPropertyRelative("count"), GUIContent.none);
         EditorGUI.PropertyField (unitRect, property.FindPropertyRelative("rate"), GUIContent.none);
         EditorGUI.PropertyField (nameRect, property.FindPropertyRelative("health"), GUIContent.none);
 
         EditorGUI.indentLevel = indent;
 
         EditorGUI.EndProperty ();
 
     }
 

I basically want a somewhat array-looking thing but I'm having trouble understanding what the values for the OnGUI function in my snippet are and how they are getting assigned. In the video, it doesn't show that the rect position, the serialized property, or the guicontent are used. I'm not sure what it's asking for the serialized property.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by VesuvianPrime · Feb 10, 2015 at 02:30 AM

The inputs match up to EditorGUI.PropertyField

http://docs.unity3d.com/ScriptReference/EditorGUI.PropertyField.html

Internally Unity uses reflection to determine that it will draw your PropertyAttribute with the associated PropertyDrawer.

Unless using custom editor, Unity will automatically pass a position rect the width of the inspector and a single line height, the field name as a GUIContent label, and the serialized field as a SerializedProperty.

Comment
Add comment · Show 2 · Share
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 Firedan1176 · Feb 10, 2015 at 02:45 AM 0
Share

Okay well I am using a custom editor (and so is Buckner in the tutorial) so how would I go about getting it to work?

avatar image VesuvianPrime · Feb 10, 2015 at 03:20 AM 0
Share

I recommend following this tutorial: http://catlikecoding.com/unity/tutorials/editor/star/

SerializedProperty is a headache to learn to use at first because it goes against everything good in OOP.

That tutorial was the first thing I read that really made me understand SerializedProperty.

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

20 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

Related Questions

How to change inspector with non-Monobehaviour objects ? 1 Answer

Cannot convert serializedObject to float 1 Answer

Implementing a 2D array as a field on a ScriptableObject? 1 Answer

Creating a custom inspector utilizing a list of class instances with serialization? 1 Answer

Edit existing editor inspector? 1 Answer


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