I'm trying ways to implement a very primitive form of syntax coloring using NGUI, but can't figure out how to encode colors after changing the UILabel.text field from somewhere else.
What happens is that the coloring tags are added to the text in readable format, and the colors don't change at all.
On the NGUI side, there's just a root, camera and a single label. The label has a UILabel, UIInput and a custom UISyntaxHighlighter behaviour attached (see below).
Additionally, this is all using the latest version of NGUI.
Here's the code I'm experimenting with:
using UnityEngine;
using System.Collections;
public class UISyntaxHighlighter : MonoBehaviour
{
private UILabel label;
void Awake ()
{
label = GetComponent();
}
void Update ()
{
// Collect everything, separated by white space
string[] values = label.text.Split(' ');
// If no values are collected, early return
if ( values == null )
return;
// Parse through for marked words
for( int i = 0; i _ values.Length; ++i )
{
if ( values == "if" )
values = "[FF0000]" + "if" + "[-]";
}
label.text = string.Join( " ", values );
}
}