Author Topic: GUI to NGUI  (Read 2831 times)

wana7262

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
GUI to NGUI
« on: August 03, 2014, 02:58:53 AM »
Hi all, i am trying to convert Unity's GUI to NGUI but stuck...!!! i want to show list of available servers in game using NGUI but unable to convert and display it on scrollview items
here is the script
  1. function OnGUI()
  2. {
  3. //      set up scaling
  4.     var rx : float = Screen.width / native_width;
  5.     var ry : float = Screen.height / native_height;
  6.     GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
  7.  
  8.  
  9. //      if(GUI.Button(RefreshR, "refresh",Buttonzs)){
  10. //              Debug.Log("Requesting Masterserver list from: " + ServerName);
  11. //              MasterServer.RequestHostList(ServerName);
  12. //      }
  13.         GUI.skin = mySkin;
  14.         GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
  15.         scrollPosition = GUI.BeginScrollView (ScrollR,scrollPosition, ScrollW);
  16.         //GUI.BeginGroup (GroupArea);
  17.         //GUILayout.BeginArea(AreaR,"", "");
  18.         //GUILayout.Label("available servers",Lay);
  19.                 for (var match : HostData in MasterServer.PollHostList())
  20.                 {
  21.                         GUILayout.BeginHorizontal("Box");
  22.                        
  23.                         GUILayout.Label (match.gameName,Lay);
  24.                         GUILayout.Space(5);
  25.                         GUILayout.Label (curMapName,Lay);
  26.                         Debug.Log(match.ToString());
  27.                         if(GUILayout.Button ("Connect",Buttonzs))
  28.                         {
  29.                                 Network.Connect(match);
  30.                         }
  31.                         GUILayout.EndHorizontal();
  32.                 }
  33.                
  34.                 //GUILayout.EndArea();
  35.                 //GUI.EndGroup();
  36.                 GUI.EndScrollView ();
  37. }

Thanks in Advance

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GUI to NGUI
« Reply #1 on: August 03, 2014, 09:58:23 AM »
You can't convert Unity's GUI to NGUI. They are fundamentally different UI systems that have nothing in common with each other. You're better off by starting from scratch with NGUI, and everything you learned about Unity's GUI is only going to harm you here.

Create a set of widgets that would represent your server row entry -- background, labels, etc. Save it as a prefab. You will then instantiate this prefab inside a scroll view (likely as a child of a UIGrid object for easy alignment), and then you will be changing values on the instantiated object -- such as text within labels.