So I am just getting started with NGUI. I made a little test class:
public class TestUI : MonoBehaviour
{
UISprite[] sprites;
GameObject[] GOs;
public GameObject panel;
public UIAtlas uiatlas;
void Start()
{
sprites
= new UISprite
[1];
GOs
[0] = new GameObject
("testLabel"); sprites[0] = GOs[0].AddComponent<UISprite>();
GOs[0].transform.parent = panel.transform;
sprites[0].atlas = uiatlas;
sprites[0].sprite = sprites[0].atlas.GetSprite("TestIcon");
}
}
TestUI is currently placed on a new gameobject in the scene.
panel is the NGUI panel in the scene.
uiatlas references the UI Atlas prefab.
There are several defined sprites in the atlas.
TestIcon was the 3rd or 4th defined.
When I set the transform.parent for the GO, the sprite becomes sprite index 0, aka NOT "TestIcon".
If I set the parent AFTER the sprite assignment I get the same outcome. If I don't set the GO's parent at all, the sprite assignment does work.
So, what am I doing wrong? How can I programmatically create UI sprites?