Author Topic: GUI vs NGUI  (Read 7161 times)

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
GUI vs NGUI
« on: December 16, 2013, 06:48:38 PM »
several source code using standard unity gui shows some instruction like this (the examples is in used in photon network)

 if (PhotonNetwork.GetRoomList().Length == 0)
        {
         //show some message to say that are'nt games ready
                       return
        }
        else
        {
         //nogame.SetActive(false);
         //countroom=1;
            //Room listing: simply call GetRoomList: no need to fetch/poll whatever!

// I NEED TO KNOW OF REALIZE THIS IN NGUI
           scrollPos = GUILayout.BeginScrollView(scrollPos);

            foreach (RoomInfo game in PhotonNetwork.GetRoomList())
            {
            GUILayout.BeginHorizontal();
            GUILayout.Label(game.name + " " + game.playerCount + "/" + game.maxPlayers);
            if (GUILayout.Button("JOIN"))
            {
               PhotonNetwork.JoinRoom(roomName);
               connect.gameObject.SetActive (false);
               p2.playername=PhotonNetwork.playerName;
               p2.confirmed=true;
               timerActive=true;
               gameman.isplayertwo=true;
               CallTimer();
               GameState stato=GameState.waitplayerone;
               GameObject maingame=GameObject.Find("GameManager");
               maingame.GetComponent<GameManager>().gameState = stato;
            }
            GUILayout.EndHorizontal();
               
            }
            GUILayout.EndScrollView();
        }

How can reproduce this part of gui with ngui?  i can use a scroll panel modified for my needs, but i want know if there are other solutions. Thanks for help.
« Last Edit: December 16, 2013, 07:01:09 PM by pcutile »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: GUI vs NGUI
« Reply #1 on: December 17, 2013, 03:14:11 AM »
Remember that the OnGUI and NGUI systems are fundamentally different in that OnGUI is re-made each time the OnGUI() is called, while NGUI elements persists until you change something.

This means that you can't just run stuff inside a OnGUI loop for NGUI, but have to run a different loop of your updating logic, that changes the persistent state of the UI.

Long story short, yes, you can recreate the behavior of the code you posted, but you have to do it in a slightly different way.

Does this help you?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GUI vs NGUI
« Reply #2 on: December 17, 2013, 12:16:46 PM »
Start by watching the tutorial videos, that would be my suggestion. As Nicki said, the two systems are completely different.

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
Re: GUI vs NGUI
« Reply #3 on: December 17, 2013, 02:08:54 PM »
dear friends, thanks for your suggestion but you have confirmed only what i already know.
It 's clear infact that systems are different ( and infact this is the problem!).
In photon network gui, showed buttons relative to open rooms are showed with an algoritm that update every time the gui (that is it use standard gui..in this case is the optimal and unique solution ).
So at this time , the only method that i can use is relative a closed set (that is i must predict the max number of roms that users can use). I explain better, i must define max number number of room available, so at first execution it will show nothing, and after at adding of a room, i must delete all ngui object and rewrite the correct on screen. At the end my problem is that the Ongui or Update or similar, will go crazy! (delete and rewrite inside a update or similar i saw).
This is reaaly bad because when want use in future server with several hundred of rooms (for example) i must create a GUI with hundred of button ready, or create it dinamically. But the real problem is that i can't update it with the same method of GUI.

kitgui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: GUI vs NGUI
« Reply #4 on: December 17, 2013, 02:53:31 PM »
It sounds as if you are concerned with dynamically creating a lot of gameobjects or pooling a lot of gameobjects that defines your maximum.

Both operations are quite small and efficient, and furthermore you can use co-routines to add them gradually rather than locking the thread until all are created, or a loading screen to hide the initial pooling.

NGUI uses persistent gameobjects as UI elements as you already know, so you should almost never be destroying and recreating them, and this isn't one of the rare scenarios in which you should. You can use events to change the state of your UI, or poll it on update, you don't need drawing code.
« Last Edit: December 17, 2013, 02:58:58 PM by kitgui »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GUI vs NGUI
« Reply #5 on: December 18, 2013, 12:42:16 PM »
Also, if you use TNet and not Photon, there are other examples that can help you get started. Starlink UI kit features a multiplayer setup -- direct connect, LAN, internet gameplay, server list, game selection, etc -- all using NGUI for visualization.