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
3
Question by vexe · Feb 18, 2014 at 09:08 AM · guitexttextfield

Change the color of a label font that's using an EditorStyle.textField style?

Hello,

I have a custom object field which essentially calls GUILayout(field, EditorStyles.textField) to get some resemblance to an object field. However, I'm not being able to change the color of text that's been displayed.

 public static void DraggableLabeledObjectField(string label, string field, Object value, bool ping, float labelWidth, GUIStyle style = null)
 {
     CustomLabelWidthBlock(labelWidth, () =>
     {
         EditorGUILayout.PrefixLabel(label);
         GUILayout.Label(field, style ?? EditorStyles.textField);
         var labelRect = GUILayoutUtility.GetLastRect();
         GUIHelper.RegisterFieldForDrag(labelRect, value);
         if (ping) {
             EditorGUIUtility.AddCursorRect(labelRect, MouseCursor.Zoom);
             if (GUI.Button(labelRect, "", GUIStyle.none))
                 Utils.PingObject(value);
         }
     });
 }

I tried GUI.contentColor it didn't do anything for some reason. I figured, I'm not passing in a GUIContent to my GUILayout.Label call so I changed the first parameter from field to new GUIContent(field), it didn't budge.

You'll notice that I'm using a null-coalescing operator, that's cause I tried to pass in GUIStyles:

 StateFieldLabel = new GUIStyle(EditorStyles.textField)
 {
     normal = new GUIStyleState()
     {
         textColor = Color.green
     }
 };

That did change the color, but I didn't get a textField, all I got is just a normal label.

Here's what the fields look like:

alt text

Any ideas?

Thanks!

Blockquote

macrowindow.png (18.3 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
7
Best Answer

Answer by MakeCodeNow · Feb 19, 2014 at 07:42 AM

Just make a new GUIStyle and pass in your base Editor style into the constructer. Then, set the .normal.textColor of your new GUIStyle to whatever color you want. Finally, pass that GUIStyle into whatever GUIfunctions you want to have text drawn in that color.

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 vexe · Feb 19, 2014 at 09:51 AM 0
Share

Sorry but, have you not read my question? I mentioned that I did do that but I only got the color to change without getting the textField style (i.e. I got just a colored label, not a textField with colored content).

avatar image Jamora · Feb 19, 2014 at 11:17 AM 3
Share

$$anonymous$$akeCodeNow is correct, here's what he's saying in code:

         GUIStyle s = new GUIStyle(EditorStyles.textField);
         s.normal.textColor = Color.green;
 
         GUILayout.Label("fda34",s);

Which, for me, shows a green text within an unfocusable textfield.

avatar image vexe · Feb 19, 2014 at 01:29 PM 0
Share

Right. It seems that I shouldn't have created a new 'normal'

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

Disable left/right cursor movement in TextField when pressing up/down arrow keys 0 Answers

Attach Text data to gameobjects by player 0 Answers

Avoid auto device capitalization for textfields on mobile 1 Answer

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

gui text button dont work 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