Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 TheThe · Jan 27, 2015 at 08:37 PM · propertydrawer

Unity Property Drawer - Making more space

I have a problem creating my custom GUI layout. I don't know how to make more space for my labels so they don't get on each other like here

alt text

I saw this post but it didn't help me. http://answers.unity3d.com/questions/542901/property-drawer-and-children.html

My code for Property Drawer is here:

using UnityEngine; using UnityEditor; using System.Collections;

[CustomPropertyDrawer(typeof(Level))] public class LevelType : PropertyDrawer {

 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 
 {
     EditorGUI.BeginProperty(position, label, property);
     EditorGUIUtility.LookLikeControls();
     int indent = EditorGUI.indentLevel;
     EditorGUI.indentLevel = 0;
     
     Rect w1 = new Rect(position.x, position.y, 50, position.height);
     Rect w2 = new Rect(position.x+60, position.y, 25, position.height);
     EditorGUI.LabelField(w1, "Health", GUIStyle.none);
     EditorGUI.PropertyField(w2, property.FindPropertyRelative ("Balls"), GUIContent.none);

     Rect w3 = new Rect(position.x, position.y+30, 50, position.height);
     Rect w4 = new Rect(position.x+60, position.y+30, 25, position.height);
     EditorGUI.LabelField(w3, "Mana", GUIStyle.none);
     EditorGUI.PropertyField(w4, property.FindPropertyRelative ("Balls"), GUIContent.none);


     EditorGUI.EndProperty();
     
     
 }

}

as2.png (11.7 kB)
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

2 Replies

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

Answer by GameVortex · Jan 27, 2015 at 09:58 PM

You need to overwrite the GetPropertyHeight function and return the height you want it to use.

Comment
Add comment · Show 3 · 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 TheThe · Jan 27, 2015 at 10:56 PM 0
Share

and how can I do that?

avatar image GameVortex · Jan 28, 2015 at 07:04 AM 0
Share

What do you mean? I linked you the scripting documentation on GetPropertyHeight. What specifically do you have problems figuring out?

avatar image TheThe · Feb 02, 2015 at 11:53 AM 0
Share

I just didn't know how to write it in code, this was a problem. But after some searches I've managed to do it right. Thanks!

 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     return 50.0f;
 }
avatar image
2

Answer by toomasio · Apr 20, 2018 at 06:59 AM

Some code to help with this. Kinda a hack way of doing it but it works.

 //need to set field amount manually if you add more fields
     private int fieldAmount = 4;
     private float fieldSize = 16;
     private float padding = 2;
 
     public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     {
         //set the height of the drawer by the field size and padding
         return (fieldSize * fieldAmount)+(padding * fieldAmount);
     }
 
     // Draw the property inside the given rect
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
 
         //divide all field heights by the field amount..then minus the padding
         position.height /= fieldAmount; position.height -= padding;
 
         // Using BeginProperty / EndProperty on the parent property means that
         // prefab override logic works on the entire property.
         EditorGUI.BeginProperty(position, label, property);
         
         //first field of the drawer
         EditorGUI.PropertyField(position,data);
 
         position.y += fieldSize + padding; //offset position.y by field size
         savedData.id = EditorGUI.IntField(position, savedData.id);
 
         position.y += fieldSize + padding;
         savedData.id = EditorGUI.IntField(position, savedData.id);
 
         position.y += fieldSize + padding;
         savedData.id = EditorGUI.IntField(position, savedData.id);
 
 
         EditorGUI.EndProperty();
     }
Comment
Add comment · 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

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

21 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

Related Questions

property drawer for enum + two other attributes 2 Answers

Material doesn't have a color property '_Color' 4 Answers

How do I expose class properties (not fields) in C#? 7 Answers

Callling a variable and setting values only once, not every frame. 3 Answers

Can I add global properties to all classes? Like Behaviour.enabled but Behaviour.myOwnThing? 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