Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: sonicviz on May 24, 2012, 01:10:50 AM

Title: Color tags not working in v2.0.7
Post by: sonicviz on May 24, 2012, 01:10:50 AM
Hi,
Did something change in the latest version?
I have a bunch of labels with color tags ex: [95d0fc]Blow notes are Blue    and now they are not working, the tag text is showing up on screen.

?

ty!
Title: Re: Color tags not working in v2.0.7
Post by: dlewis on May 24, 2012, 01:41:21 AM
Make sure that the encoding option is ticked in the UILabel properties.
Title: Re: Color tags not working in v2.0.7
Post by: sonicviz on May 24, 2012, 01:52:14 AM
It is, always has been. No effect. Worked before, upgraded, now it shows the tags.
Strange thing is it's only doing it in some cases.

arrrrrrrrrrghhhhhhhhhhh

EDIT:
Ok, for some reason the new version is turning of encode on some labels. It's set to encode in the editor, but now when I run it's turning it off.

Edit2:
Solved! Problem appears to be something related to a change in the typewriter effect. Had it on a couple of labels, worked fine before. Encode is checked.
Now when I run the encode it being turned off. Disabled the tyrpewriter effect and color tags are now showing correct.
For now removing the typewriter effect.

ty!
Title: Re: Color tags not working in v2.0.7
Post by: ArenMook on May 24, 2012, 10:11:01 AM
Typewriter effect doesn't work with the encoded colors, which is why it gets disabled. It's just an example script, you can modify it to make it work with encoded colors if you need that behavior.
Title: Re: Color tags not working in v2.0.7
Post by: Komikus on October 06, 2012, 06:22:17 PM
I realize this topis was not adressed in a while but if anyone needs it here's the typewriter script with color encoding support.
Had to do it for a project so I thought I'd share.

  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Trivial script that fills the label's contents gradually, as if someone was typing.
  5. /// </summary>
  6.  
  7. [RequireComponent(typeof(UILabel))]
  8. [AddComponentMenu("NGUI/Examples/Typewriter Effect")]
  9. public class TypewriterEffect : IgnoreTimeScale
  10. {
  11.         public int charsPerSecond = 40;
  12.  
  13.         UILabel mLabel;
  14.         string mText;
  15.         int mOffset = 0;
  16.         float mNextChar = 0f;
  17.  
  18.         void Update ()
  19.         {
  20.                 if (mLabel == null)
  21.                 {
  22.                         mLabel = GetComponent<UILabel>();
  23.                         //mLabel.supportEncoding = false;
  24.                         mLabel.symbolStyle = UIFont.SymbolStyle.None;
  25.                         mText = mLabel.font.WrapText(mLabel.text, mLabel.lineWidth / mLabel.cachedTransform.localScale.x, mLabel.maxLineCount, false, UIFont.SymbolStyle.None);
  26.                 }
  27.  
  28.                 if (mOffset < mText.Length)
  29.                 {
  30.                         if (mNextChar <= Time.realtimeSinceStartup )
  31.                         {
  32.                                 charsPerSecond = Mathf.Max(1, charsPerSecond);
  33.  
  34.                                 // Periods and end-of-line characters should pause for a longer time.
  35.                                 float delay = 1f / charsPerSecond;
  36.                                 char c = mText[mOffset];
  37.                                 if (c == '.' || c == '\n' || c == '!' || c == '?') delay *= 4f;
  38.  
  39.                                 mNextChar = Time.realtimeSinceStartup  + delay;
  40.                                 //if (mText.Substring(mOffset,1)==" ") mOffset+=2;     
  41.                                 if (mText.Substring(mOffset, 1)=="[") {
  42.                                         if (mText.Substring(mOffset,2)!="[-") {
  43.                                                 mOffset+=8;
  44.                                         } else {
  45.                                                 mOffset+=4;
  46.                                         }
  47.                                 }
  48.                                 mLabel.text = mText.Substring(0, ++mOffset);
  49.                         }
  50.                 }
  51.                 else Destroy(this);
  52.         }
  53. }
Title: Re: Color tags not working in v2.0.7
Post by: laurentl on April 30, 2013, 02:09:38 AM
Thanks Komikus.
Title: Re: Color tags not working in v2.0.7
Post by: kalgor on September 04, 2013, 02:41:24 PM
Here's a contribution...  I made a simple enhancement to add a callback when the effect was finished.  I had a need to notify another object it was finished to keep some things synchronous.

  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Trivial script that fills the label's contents gradually, as if someone was typing.
  5. /// </summary>
  6.  
  7. [RequireComponent(typeof(UILabel))]
  8. [AddComponentMenu("NGUI/Examples/Typewriter Effect")]
  9. public class TypewriterEffect : IgnoreTimeScale
  10. {
  11.         public GameObject eventListener;
  12.     public int charsPerSecond = 40;
  13.  
  14.     UILabel mLabel;
  15.     string mText;
  16.     int mOffset = 0;
  17.     float mNextChar = 0f;
  18.  
  19.     void Update ()
  20.     {
  21.         if (mLabel == null)
  22.         {
  23.             mLabel = GetComponent<UILabel>();
  24.             //mLabel.supportEncoding = false;
  25.             mLabel.symbolStyle = UIFont.SymbolStyle.None;
  26.             mText = mLabel.font.WrapText(mLabel.text, mLabel.lineWidth / mLabel.cachedTransform.localScale.x, mLabel.maxLineCount, false, UIFont.SymbolStyle.None);
  27.         }
  28.  
  29.         if (mOffset < mText.Length)
  30.         {
  31.             if (mNextChar <= Time.realtimeSinceStartup )
  32.             {
  33.                 charsPerSecond = Mathf.Max(1, charsPerSecond);
  34.  
  35.                 // Periods and end-of-line characters should pause for a longer time.
  36.                 float delay = 1f / charsPerSecond;
  37.                 char c = mText[mOffset];
  38.                 if (c == '.' || c == '\n' || c == '!' || c == '?') delay *= 4f;
  39.  
  40.                 mNextChar = Time.realtimeSinceStartup  + delay;
  41.                 //if (mText.Substring(mOffset,1)==" ") mOffset+=2;     
  42.                 if (mText.Substring(mOffset, 1)=="[") {
  43.                     if (mText.Substring(mOffset,2)!="[-") {
  44.                         mOffset+=8;
  45.                     } else {
  46.                         mOffset+=4;
  47.                     }
  48.                 }
  49.                 mLabel.text = mText.Substring(0, ++mOffset);
  50.             }
  51.         }
  52.         else {
  53.                         if(eventListener) {
  54.                                 eventListener.SendMessage("OnTypewriterDone", SendMessageOptions.DontRequireReceiver);
  55.                         }
  56.                        
  57.                         Destroy(this);
  58.                 }
  59.     }
  60. }
  61.  
Title: Re: Color tags not working in v2.0.7
Post by: Eskinto on January 14, 2014, 07:04:06 PM
Updated the typewriter script for NGUI 3 and up with encoding support, for older versions use the ones above! hope this helps  ;)

  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Trivial script that fills the label's contents gradually, as if someone was typing.
  5. /// </summary>
  6.  
  7. [RequireComponent(typeof(UILabel))]
  8. [AddComponentMenu("NGUI/Examples/Typewriter Effect")]
  9. public class TypewriterEffect : MonoBehaviour
  10. {
  11.         public int charsPerSecond = 40;
  12.         UILabel mLabel;
  13.         string mText;
  14.         int mOffset = 0;
  15.         float mNextChar = 0f;
  16.  
  17.         void Update ()
  18.         {
  19.                 if (mLabel == null) {
  20.                         mLabel = GetComponent<UILabel> ();
  21. //                      mLabel.supportEncoding = false;
  22.                         mLabel.symbolStyle = NGUIText.SymbolStyle.None;
  23.                         mText = mLabel.processedText;
  24.                 }
  25.  
  26.                 if (mOffset < mText.Length) {
  27.                         if (mNextChar <= RealTime.time) {
  28.                                 charsPerSecond = Mathf.Max (1, charsPerSecond);
  29.                                
  30.                                 // Periods and end-of-line characters should pause for a longer time.
  31.                                 float delay = 1f / charsPerSecond;
  32.                                 char c = mText [mOffset];
  33.                                 if (c == '.' || c == '\n' || c == '!' || c == '?')
  34.                                         delay *= 4f;
  35.                                
  36.                                 mNextChar = RealTime.time + delay;
  37.                                 //if (mText.Substring(mOffset,1)==" ") mOffset+=2;     
  38.                                 if (mText.Substring(mOffset, 1)=="[") {
  39.                                         if (mText.Substring(mOffset,2)!="[-") {
  40.                                                 mOffset+=8;
  41.                                         } else {
  42.                                                 mOffset+=2;
  43.                                         }
  44.                                 }
  45.                                 mLabel.text = mText.Substring (0, ++mOffset);
  46.                         }
  47.                 } else
  48.                         Destroy (this);
  49.         }
  50. }
  51.  
Title: Re: Color tags not working in v2.0.7
Post by: ArenMook on January 14, 2014, 07:04:36 PM
Nice, thanks!