I've been using the demo version of NGUI for about a year, and I finally bought the license for the full version today. While most of it makes a lot of sense, I'm not sure I understand the "correct" way to do things when creating things programmatically.
I think I'm calling NGUITools.AddChild incorrectly in some circumstances. If I call it like this:
NGUITools
.AddChild(uiRoot,
new GameObject
("Test"));
it works like I expect, it creates a basic GameObject (although it does add "(Clone)" to the name, which is irksome but fixable).
However, when I try to instantiate an actual prefab, like so:
NGUITools.AddChild(uiRoot, Instantiate(Resources.Load("Prefabs/MyPrefab")));
then MyPrefab(Clone) is instantiated in the hierarchy root, and 'New Game Object' is created as a child of uiRoot.
Thinking that I'd done it wrong and that maybe the prefab needs to be pre-instantiated, I tried:
NGUITools.AddChild(uiRoot, (GameObject)UnityEngine.Object.Instantiate(Resources.Load("Prefabs/MyPrefab")));
but that creates MyPrefab(Clone) in the hierarchy root, and MyPrefab(Clone)(Clone) as a child of uiRoot.
At this point I took a look at the actual code of AddChild, and saw that it actually calls GameObject.Instantiate on line 386. So I tried this:
NGUITools.AddChild(uiRoot, Resources.Load("Prefabs/MyPrefab"));
which creates 'New Game Object' as a child of uiRoot, but it's just a basic GameObject with no components, meshes, etc.
At this point I'm at a loss, the code of AddChild isn't especially complex, so it has to be with my call, right?