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
1
Question by $$anonymous$$ · Mar 27, 2018 at 05:11 PM · uiassettextmeshinputfield

Textmesh Pro Input Field Rich Text

I have a Textmesh pro Input field, that is using rich text tags. However, when the user edits the input, the tag doesn´t get removed but stays there. Do you have any advice? Thanks in advance

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Martin_Gonzalez · Mar 27, 2018 at 05:46 PM

I don't know if this is what you are looking for:

https://www.youtube.com/watch?v=BHUDw9vd-Pw

Comment
Add comment · Show 6 · 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 $$anonymous$$ · Mar 27, 2018 at 06:28 PM 0
Share

No, I have this text and when the user starts typing again, he doesn´t delete the word, but the tag. Do you know what I could do?

1.png (908 B)
avatar image $$anonymous$$ · Mar 27, 2018 at 07:36 PM 0
Share

@$$anonymous$$GDevelopmentsSt Do you have Andy idea ?

avatar image Martin_Gonzalez $$anonymous$$ · Mar 27, 2018 at 07:37 PM 0
Share

I didn't work with Text$$anonymous$$esh Pro. But i cannot understand what you want to achieve. Try to break it in different steps.

avatar image $$anonymous$$ Martin_Gonzalez · Mar 27, 2018 at 07:48 PM 0
Share

I have an Input field which has markup tags in it. Those are not shown, because they directly format my text. However if the user then deletes the last character of the word, he doesn’t delete it, but deletes the tag. This means the word isn’t formatted anymore and the tags are shown. Do you know what I mean?

Show more comments
avatar image
0

Answer by LilGames · Mar 27, 2018 at 08:05 PM

Don't use HTML mark-up in input fields (for the very reason you just experienced). If you want bold, assign a bold font to the field.

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 $$anonymous$$ · Mar 27, 2018 at 08:12 PM 0
Share

But then I can’t specify which words should be bold/italic/colored differently/underlined etc.

avatar image
0

Answer by aciusa · Dec 07, 2018 at 05:22 PM

You can overload the TMP_InputField Class, its not perfect but here is a caret based solution to get you going in the right direction. This solution fails if the user types a tag and is either backspace or delete focused, depending on which of the ending if block logic statements is constrained by lastShiftRight.

EDIT: Updated so it works with both delete and backspace keys as normal, users can still mess it up by typing in their own tag. This probably needs another layer of detection to wrap with and ignore for the string search.

  public class TagInputField : TMP_InputField {
     
     private int lastCaretPos = 0;
     
         private bool insideTag = false;
         private bool infrontTag = false;
         private bool behindTag = false;
         private bool ranFrame = false;
     
         private int lastOpen = 0;
         private int lastClose = 0;
         private int nextOpen = 0;
         private int nextClose = 0;
     
         private bool lastShiftRight = false;
     
     private void OnGUI()
 {
     if (isFocused) //&& Input.anyKey
     {
         try
         {
             lastOpen = text.LastIndexOf('<', selectionStringAnchorPosition - 1);
             lastClose = text.LastIndexOf('>', selectionStringAnchorPosition - 1);
             nextOpen = text.IndexOf('<', selectionStringAnchorPosition);
             nextClose = text.IndexOf('>', selectionStringAnchorPosition);
         }
         catch (System.ArgumentOutOfRangeException)
         {
             Debug.Log("end of text field");
         }

         if (lastOpen > lastClose || (nextClose < nextOpen && nextOpen != -1)) insideTag = true;
         else insideTag = false;

         if ((nextOpen - 1) == selectionStringAnchorPosition) behindTag = true;
         else behindTag = false;

         if ((lastClose + 1) == selectionStringAnchorPosition) infrontTag = true;
         else infrontTag = false;

         if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
         {
             if (insideTag) caretPosition += 1;
         }
         else if (Input.GetKey(KeyCode.LeftArrow))
         {
             lastShiftRight = false;
         }
         else if (Input.GetKey(KeyCode.RightArrow))
         {
             lastShiftRight = true;
         }

         if (Input.GetKey(KeyCode.Delete))
         {
             if (insideTag)
             {
                 DisableKey(KeyCode.Delete);
                 selectionStringAnchorPosition = nextClose + 1;
                 selectionStringFocusPosition = nextClose + 1;
             }
             lastShiftRight = true;
             //DisableKey(KeyCode.Delete);
         }
         if (Input.GetKey(KeyCode.Backspace))
         {
             if (insideTag)
             {
                 DisableKey(KeyCode.Backspace);
                 selectionStringAnchorPosition = lastOpen - 1;
                 selectionStringFocusPosition = lastOpen - 1;
             }
             if (infrontTag)
             {
                 DisableKey(KeyCode.Backspace);
                 selectionStringAnchorPosition = lastOpen;
                 selectionStringFocusPosition = lastOpen;
             }
             lastShiftRight = false;
         }

         

         if (infrontTag && !lastShiftRight) // && !Input.GetKey(KeyCode.RightArrow)
         {
             selectionStringAnchorPosition = lastOpen;
             selectionStringFocusPosition = lastOpen;
         }
         else if (insideTag && lastShiftRight)
         {
             selectionStringAnchorPosition = nextClose + 1;
             selectionStringFocusPosition = nextClose + 1;
         }
         else { lastShiftRight = false; }
     }
 }
     
     static void DisableKeys(KeyCode[] keys)
         {
             if (!Event.current.isKey)
             {
                 return;
             }
     
             foreach (KeyCode key in keys)
             {
                 if (Event.current.keyCode == key)
                 {
                     Event.current.Use();
                 }
             }
         }
     
         static void DisableKey(KeyCode key)
         {
             DisableKeys(new KeyCode[] { key });
         }
 }




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 aciusa · Dec 07, 2018 at 05:39 PM 0
Share

http://angryant.com/2009/09/07/i-bet-you-cant-type-an-a/ - credit for disable key script

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

132 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 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 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 do I change "return"/"submit" button to "search" in native android keyboard in TMP_InputField? 1 Answer

Text MeshPro Input field insert integer? 1 Answer

Allow TMP_InputField to show HTML Tags even Rich Tags are ENABLED. 0 Answers

Text Mesh Pro : Unable to use pull down menu inspite of Distance field 16 0 Answers

Why does my TMP inputfield text disappears when I rotate It, why using a world space camera 0 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