There are a couple of different ways to approach this problem. The simplest is to break your sentence into words and do the layout yourself.
- Create and EZGUI Label (SpriteText) game object with the font, character size, character spacing and the like setup.
- Break your title or sentence into individual words.
- For each word, Instantiate() a copy of your Label, set the text and position the text leaving space between between the words.
Here is some starter code:
public class SptxLayout : MonoBehaviour {
public GameObject goParent;
public GameObject goSptxPrefab;
public Vector3 v3Position;
private string stLayout = "This is a title with some stuff in it";
private Vector3 v3ExampleAnchor;
void Start () {
float fSpaceWidth;
SpriteText sptx = goSptxPrefab.GetComponent();
sptx.Text = " ";
fSpaceWidth = sptx.TotalWidth;
string[] arst = stLayout.Split (new char[] {' '});
for (int i = 0; i < arst.Length; i++) {
GameObject go = (GameObject)Instantiate (goSptxPrefab);
go.transform.parent = goParent.transform;
go.transform.localPosition = v3Position;
sptx = go.GetComponent();
sptx.Text = arst[i];
if (arst[i] == "stuff") {
v3ExampleAnchor = v3Position;
v3ExampleAnchor.x += sptx.TotalWidth / 2.0f;
}
v3Position.x = v3Position.x + sptx.TotalWidth + fSpaceWidth;
}
}
}
With this code, you now have individual SpriteText objects for each word which you can disable the renderer to hide. Note the calculation here assume you've set Anchor property in the SpriteText to MiddleLeft. The v3ExampleAnchor will be in local coordinates to the parent. This is where you will show your icon.
I'm not sure how you are using the PackedSprite. But for things like this, I typically build a base PackedSprite that has all the icons/images in a single animation. Then at runtime, I set the frame in the animation to the one I want to show. It makes keeping track of things easier.
↧