Support => NGUI 3 Support => Topic started by: travisschau on January 03, 2014, 01:22:29 AM
Title: NGUITools.AddChild and still anchor to screen edges? (Multiple UIRoots?)
Post by: travisschau on January 03, 2014, 01:22:29 AM
Hi, I'm using the NGUITools.AddChild() method to dynamically create dialogs from my resources folder within NGUI. The problem is that some of those dialogs need to anchor to the edges of the screen, which I only know how to do by setting the anchors to UIRoot. I can't do that when I'm creating a prefab of a single dialog, since the prefab can't store a reference to my UIRoot instance.
My workaround right now is to intsantiate an entirely new UIRoot prefab with my anchor-requiring dialog embedded in it. This seems hacky to me though, and I'm pretty sure it's causing some touch-event problems I'm having. There must be a better way.
What's the right way to deal with this?
thanks so much,
-Travis
Title: Re: NGUITools.AddChild and still anchor to screen edges? (Multiple UIRoots?)
Post by: scapegoat57 on January 03, 2014, 03:09:37 AM
The way I get around instantiating prefabs with anchors is by having an inactive instance of the prefab in the scene and calling Instantiate with that. The only draw back is that the copy is inactive, so you have to add SetActive(true) after your Instantiate call.
Title: Re: NGUITools.AddChild and still anchor to screen edges? (Multiple UIRoots?)
Post by: ArenMook on January 03, 2014, 03:51:26 AM
Title: Re: NGUITools.AddChild and still anchor to screen edges? (Multiple UIRoots?)
Post by: travisschau on January 04, 2014, 12:29:00 PM
Thanks for the replies.
@ArenMook, that's what I wanted to do originally, but I can't seem to find a method called "SetAnchor" anywhere in NGUI. Searching only showed ResetAnchors() in UIRect.
As you say, my original thought was to do something like...