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
1
Question by gRntaus · Nov 15, 2013 at 08:51 AM · styletextarea

Apply style to specific string in text area?

Can this be done at all? I'm making a pseudo terminal and would like some highlighting on specific words if possible. I'm happy to apply a material to certain strings and add them to the text area rather than insert an entire string. Because of the complexities of doing this I only use one text area. I'd think multiple text areas would be out of the option.

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
0

Answer by brain56 · Nov 15, 2013 at 09:02 AM

No, that is not possible with the default text rendering facilities Unity 3D currently provides.

What you can do is use different text objects to render each part of the string with a different material. But I'd also recommend you take a look at third party Unity plug-ins for text. I would recommend *Toolkit 2D* and *NGUI*.

Comment
Add comment · Show 1 · 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 gRntaus · Nov 15, 2013 at 09:31 AM 0
Share

I'm looking for a free option preferably as I'll not be making revenue with this. Can I append text objects and strings into the same text area? If so ill likely be able to make that work.

avatar image
0

Answer by MrVerdoux · Nov 15, 2013 at 09:30 AM

I can only think of doing it by extending GUI methods to add a "sequential" GUI option or something like that, but in my opinion that is not a very good solution, only that I can´t think of anything else.

 using UnityEngine;
 using System;
 using System.Drawing;
 using System.Collections;
 using System.Collections.Generic;
 using System.Windows.Forms;
 
 public static class GUIExtension{
         public static void SequentialLabel(this GUI gui, Rect rect, List<StyledString> styledStrings){
             float recorredWidth = 0;
 
             for (int i=0; i<styledStrings.Count; i++){
                 Size stringSize = TextRenderer.MeasureText(styledStrings[i].text, styledStrings[i].style.Font.size);
 
                 GUI.Box(new Rect(rect.x + recorredWidth, rect.y, rect.width, rect.height), 
                         styledStrings[i].text, styledStrings[i].style);
 
                 recorredWidth += stringSize.width;
             }
         }
     }
 
     public class StyledString{
         public string text {get; private set;}
         public GUIStyle style {get; private set;}
 
         public StyledString(string text, GUIStyle style){
             this.text = text;
             this.style = style;
         }
     }

Note: I have a problem with autocompletion right now so probably the code needs fixing. Oh, and that is only for "one line" label, if you want more lines you will have to do a line end check.

Comment
Add comment · Show 4 · 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 gRntaus · Nov 15, 2013 at 09:46 AM 0
Share

Thanks I was unaware I could apply styles like that I'll see what I can come up with and post back. I'm not overly concerned about optimization or anything given the nature of the code.

avatar image MrVerdoux · Nov 15, 2013 at 09:58 AM 0
Share

The way to call it would be:

 GUI.SequentialLabel(new Rect(left,top,width,height),myStringList);

But again, I´m not very sure this would work...

avatar image gRntaus · Nov 15, 2013 at 11:47 AM 0
Share

Are you able to confirm what package Size is in? I've added the Windows.Forms dll to my project but I'm still getting a namespace Error for Size. EDIT: It's in drawing....

avatar image MrVerdoux · Nov 15, 2013 at 12:35 PM 0
Share

It is in System.Drawing

http://msdn.microsoft.com/en-us/library/system.drawing.size%28v=vs.110%29.aspx

EDIT: I didn´t see you edit, hahaha

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

19 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

Related Questions

Get height of TextArea when wordwrap is enabled? 1 Answer

GuiSkin textArea font size not working 1 Answer

How do I make a GUI text area fade in? 1 Answer

EditorGUILayout.TextArea text goes out of bounds 0 Answers

BeginVertical won't compile when no style is provided 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