Author Topic: NGUI and Server List  (Read 2850 times)

bratchan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
NGUI and Server List
« on: March 04, 2014, 11:09:53 AM »
I have been banging my head against a wall for a while. I hope someone might be able to help out with my issue. I’m still new to NGUI and I also have been working in javascript.

I am creating a Muliplayer game and need to get menus to work with NGUI. I have it all working find with the GUI system in unity, I just wanted it to easier to style and such.

I have hosting menu to work fine, you can connect to the server and its all good, its for the joining players where I have the issue at. I have NGUI populating a grid with a label and a button so you can click to join that server.

I can’t figure out how to get the host information for that certain server so you can connect to it.

This is the code i have for populating the list.
  1. for (var element in data)
  2.                 {
  3.                
  4.                         Debug.Log("loadElement");
  5.                         var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
  6.  
  7.                        
  8.                         Debug.Log(element);
  9.                
  10.                        
  11.                         NGUITools.AddChild(serverTable, serverItem);
  12.                         serverItem.GetComponent(UILabel).text = name;
  13.                         serverItem.name = rr.ToString();
  14.                         //Debug.Log(serverItem.name);
  15.                         Debug.Log(serverItem.GetComponent(UILabel).text);
  16.                        
  17.                         NGUITools.AddChild(serverTable, serverButton);
  18.                        
  19.                          //(serverButton as serverButtonRunner).myInfo = element;
  20.                          
  21.                          serverButton.GetComponent(serverButtonRunner).myInfo = "hbhhhh";
  22.                        
  23.                        
  24.                         //yield WaitForSeconds (.5);
  25.                         serverTable.GetComponent(UIGrid).Reposition();
  26.                  
  27.                                 Debug.Log("Connecting...");    
  28.                                
  29.                                 serverButton.SendMessage("receiveMessage", element, SendMessageOptions.DontRequireReceiver);   
  30.                        
  31.                         //create BTN here and the onclick
  32.                         //NGUITools.addChild();
  33.                         rr ++;
  34.                        
  35.                         //Network.Connect(element);


This is all the fail code i have on my button that hasn’t worked.
  1. var targetScript;
  2.  
  3. private var server:String;
  4.  
  5. public var myInfo;
  6.  
  7. function Awake () {
  8. //finds the script that runs the menu
  9.         var gameScript = GameObject.Find("menuRunner");
  10.        
  11.         targetScript = gameScript.GetComponent(menuRunner).serverInformation;
  12.         //Debug.Log(gameScript.GetComponent(menuRunner).serverInformation);
  13.         //targetScript = targetScript.ToString();
  14.  
  15. }//end of awake
  16.  
  17. //doesn't work
  18. function receiveMessage(passInfo){
  19.  
  20.         //testInfo = passInfo;
  21.        
  22.         //Network.Connect(testInfo);
  23.         //no output
  24.         Debug.Log("workihghfdfhjkhfhfghjkhfdfghjng");
  25.  
  26. }//end of test
  27.  
  28. function OnClick(){
  29. Debug.Log(targetScript);
  30.         Debug.Log("clck");
  31.         //this doesn't work
  32.         //Network.Connect(targetScript);
  33.         //Debug.Log("Connecting...");  
  34.  
  35. }//end of onclick

Anything or suggestions would be grateful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and Server List
« Reply #1 on: March 05, 2014, 08:06:41 AM »
Quote
NGUITools.AddChild(serverTable, serverItem);
serverItem.GetComponent(UILabel).text = name;
Should be:
Quote
GameObject go = NGUITools.AddChild(serverTable, serverItem);
go.GetComponent(UILabel).text = name;

bratchan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: NGUI and Server List
« Reply #2 on: March 05, 2014, 12:04:55 PM »
Ok, that isn't the issue i have the labels displaying but thanks for the better way of doing that.

I need help figure out when button is clicked grab that host data and connect with it. I'm having issues passing that data along with the buttons.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and Server List
« Reply #3 on: March 06, 2014, 11:27:28 AM »
You can retrieve the caller using UIButton.current. It points to the button that triggered the function. From there you can GetComponent<> with your data if you like.