Support => NGUI 3 Support => Topic started by: bionicnacho on January 28, 2013, 02:35:42 PM
Title: Making buttons in-script
Post by: bionicnacho on January 28, 2013, 02:35:42 PM
Hello!
I am doing game saving and i got stuck on something.
I can save the game just fine. So i have a list of all the game saves. I want a window to open game. It would list all of the saved games and let me click on them to open it.
With unity's default GUI, i would use
for(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName]){
if(GUILayout.Button(sg.Caption)){
sg.Load();
Time.timeScale=1;
}
}
How could i do something like this with NGUI?
What i thought i could do was make the "for" make new buttons (like the unity gui).
Title: Re: Making buttons in-script
Post by: ArenMook on January 28, 2013, 02:43:22 PM
Create a button for how a single saved game entry would look like, save it as a prefab, and NGUITools.AddChild-instantiate it at run-time as many times as you want. For added ease-of-use, add it as a child of a game object that has a UIGrid on it. It will reposition the children automatically for you, acting as a GUILayout.
Title: Re: Making buttons in-script
Post by: bionicnacho on January 28, 2013, 02:49:59 PM
Is there any document that shows how to use NGUITools.AddChild?
I have no idea on how to use that.
Title: Re: Making buttons in-script
Post by: bionicnacho on January 29, 2013, 05:52:25 PM
-bump-
Title: Re: Making buttons in-script
Post by: ArenMook on January 29, 2013, 05:53:26 PM
Serious?
NGUITools.AddChild(parent, prefab).
Title: Re: Making buttons in-script
Post by: bionicnacho on January 29, 2013, 05:54:23 PM
Well, i'm sorry for asking! I'm new to this NGUI stuff.
Title: Re: Making buttons in-script
Post by: ArenMook on January 29, 2013, 05:58:20 PM
Rule of thumb... try using something you're trying to figure out, then post a question if you don't understand it.
Especially for really simple stuff like this. You could have at least looked at the function by going to its definition.
/// <summary>
/// Instantiate an object and add it to the specified parent.