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 PartyBoat · Aug 12, 2016 at 05:12 PM · editoreditorguiunits

Is it possible to write text inside of textboxes for editable values in the inspector?

Hello everyone, I've got a really simple question that is probably best explained by this picture:

alt text

As you can see this is an example from Bolt, but it's used in a special settings window (plus I don't have source code). I was simply wondering if this is something I could do for editable values on my game object components. I would really love to be able to specify the units of my variables, it would really help me keep things readable.

Thanks!

boltsettingsquestion.png (51.2 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

1 Reply

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

Answer by PartyBoat · Aug 14, 2016 at 01:41 AM

Looks like the possible solutions to this problem are way more work then I want to spend on this tiny feature. However, I did run into the TooltipAtrribute and HeaderAttribute, and I think I'll probably be using one or the other for the same purpose. It's a little less sexy, but it gets the job done in one line of code. Here is an example of usage for those interested:

 [Tooltip("Units: m/s")]
 public float velocity = 0f;


Edit: Here is the real answer

So I guess I was just being lazy but someone on the Unity subreddit was kind enough to post a fully working solution and it's super simple. First you have to add two scripts to your project "AdditionalTextAttribute" and "AdditionalTextDrawer". In AdditionalTextAttribute.cs put this:

 using UnityEngine;
 
 public class AdditionalTextAttribute : PropertyAttribute
 {
 
     public readonly string Text;
     public AdditionalTextAttribute(string text)
     {
         Text = text + " ";
     }
 }

In AdditionalTextDrawer.cs put this:

 using UnityEditor;
 using UnityEngine;
 
 /*
  * Usage: simply put a Attribute in front of your variables like this:
  *
  *     [AdditionalText("m/s")]
  *     public float velocity = 20f;
  * 
  * Use at own risk for variables that are not rendered in text fields (you'll might get multiple texts over each other)
  */
 
 [CustomPropertyDrawer(typeof(AdditionalTextAttribute))]
 public class AdditionalTextDrawer : PropertyDrawer
 {
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
         EditorGUI.PropertyField(position, property, label);
 
         var style = new GUIStyle(EditorStyles.label);
         style.alignment = TextAnchor.MiddleRight;
         style.normal.textColor = Color.gray;

         var attrib = attribute as AdditionalTextAttribute;
         GUI.Label(position, attrib.Text, style);
     }
 }

Then you can write code like the following anywhere in your project to get text inside of the property text field:

 [AdditionalText("m/s^2")]
 public float acceleration = 20f;

Looks great just like the reference image I gave! here is the github page for the original solution given to me, basically all I did was remove the namespace usage to make it even easier to throw into a project.

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

59 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

Related Questions

Initialising List array for use in a custom Editor 1 Answer

Print to status bar. 0 Answers

How do I set the current script as the selection in the project view? 1 Answer

SceneView.onSceneGUIDelegate GUI sorting problem 1 Answer

How to combine two buttons in one. Editor window 2 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