Search Unity

NetworkManagerHUD source

Discussion in 'Multiplayer' started by seanr, Jun 14, 2015.

  1. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    The NetworkManagerHUD is a good example of how to use the match maker system, including callbacks, and how to drive the NetworkManger from a UI. The NetworkManagerHUD doesnt use any internal functionality, just the public APIs.

    (this was posted to the beta forum earlier. reposting here).
     

    Attached Files:

  2. smitsc

    smitsc

    Joined:
    Mar 4, 2014
    Posts:
    4
    Is there a new 5.2 UI Canvas version ?
     
  3. Miscellaneous

    Miscellaneous

    Joined:
    Sep 24, 2013
    Posts:
    53
    Any link to C# source code for NetworkManager ? (would help understanding unet)
     
    yahya_bo, K0Kos and wdruryzynga like this.
  4. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Just add all the GUI bits that would usually be GUI buttons etc. and create new UI buttons and text fields by using 'using UnityEngine.UI'
     
  5. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    This doesn't work on 5.4, api is changed.

    Can you give the updated version or is there a detailed info about how to write custom network manager, matchmaking system and it's hud?

    Thanks
     
  6. Deleted User

    Deleted User

    Guest

  7. Di_o

    Di_o

    Joined:
    May 10, 2016
    Posts:
    62

    Unity 5.4 doens't support the scipt like this anymore. Any chance to get the sourcecode to the new NetworkManagerHUD?
     
  8. Deleted User

    Deleted User

    Guest

    Justice0Juic3, laurachen and Di_o like this.
  9. bpaivalefou

    bpaivalefou

    Joined:
    Feb 5, 2016
    Posts:
    1
    Thank you so much !
     
  10. aaronfranke

    aaronfranke

    Joined:
    Jan 23, 2017
    Posts:
    20
    seanr, I found a bug in your code.

    if (NetworkServer.active && NetworkClient.active)
    {
    if (Input.GetKeyDown(KeyCode.X))
    {
    manager.StopHost();​
    }​
    }

    When connected as a client, it still says "Stop (X)", however, pressing X does not disconnect because the above code checks for both client and server being enabled. It should probably replaced with "NetworkServer.active || NetworkClient.active" as it is in the OnGUI method:

    if (NetworkServer.active || NetworkClient.active)
    {
    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
    {
    manager.StopHost();​
    }
    ypos += spacing;​
    }
     
  11. veereshkumbar

    veereshkumbar

    Joined:
    Aug 24, 2017
    Posts:
    4
    may i get a new custom NetworkManagerHUD.cs for new version of unity
     
  12. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Which parts of the NetworkManager class are free? I know Matchmaker costs money, but what about StartHost / StopHost, and that general namespace? Not asking because I'm a cheapskate, but I'm doing a game for a client (as in, other person, not as in networking) and fees aren't an option for me for this.

    And ditto previous poster; OnGUI is antiquated and I'm surprised tutorial examples are still using it, though I suppose making prefabs and passing them around isn't easy.
     
  13. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109
    Anyone have an idea why Unity wouldnt just add a 'size' field, rather than us all having to write a custom UI?
     
    AiDev123, Dwemerman and amit-chai like this.
  14. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109
    Hi there, thanks for this insightful comment. Its helped me a bit but I am still struggling. Would you be kind enough to post a working example for me to work through and intergrate into my basic game please?

    I am half way through making a 2 player racing game but the online setup i have requires the user to put in their external IP and set up their own port forwarding
     
  15. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Okay, what about NetworkDiscovery? I'm guessing...well, hoping that's free. That's the only way I can implement free LAN-based multiplayer functionality without forcing everyone to type in the host's IP address.
     
  16. Deleted User

    Deleted User

    Guest

    Kurius and megabrobro like this.
  17. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109

    I hope so too. But because I am very new to networking in general its proving to be a real minefield of information
     
  18. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109

    Thank you for posting this! I will read through now and try to inwardly digest it.

    Please can you help me with a quick description exactly what that script is there to do? Thanks so much!!!

    EDIT: Sorry I just seen the 'Overview' lol. I will read through that also. I am really hoping this is for what I need it to be :)
     
  19. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109

    THANK YOU VERY MUCH!! I have not yet worked through your code so I cannot yet say it has helped me (yet!) , but I defintely think making my own netmanager HUD will help me understand more about the network manager in total.

    ONE THING: I have noticed straight off the bat (just by skimreading the code) that your lines:
    netManager.networkAddress = "192.168.11.101";
    netManager.networkPort = 7777;

    Them lines seem to input the address and port directly to the network manager -- but how would this make it so that the user didnt have to input the IP/port (and also forward the port)?? what if the user was on IP 192.168.0.10 and port was 7778?


    Also, where are 'ButHostTxt' and 'hostID' declared? I get error "..does not exist in current context"
     
    Last edited: Dec 4, 2017
  20. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109
    Excellent , thank you . That was how i understood it. Its not quite what I was originally after, but an yway to get an online game functioning is what i was needing. I'm now working on some other stuff to learn, but soon will go back to the multiplayer games i started and will use your code. Thanks again
     
  21. Paden

    Paden

    Joined:
    Sep 13, 2013
    Posts:
    13
    Hey!

    I'm very new to network programming with Unity and have a few questions regarding your approach. I managed to get it working (have a server and clients connecting to said server), however there doesn't seem to be a callback that is successfully called when a client chooses to disconnect from the server (via netClient.Disconnect();). I thought that DisconnectRequest in ClientController would be called, but it doesn't seem to be (if I'm the client at least).

    I'm also wondering if there is an alternative to hard-coding the IP address you want to connect to, like some sort of way to scan for open servers on your network?

    I was trying to use the built in tools but I want to have more control as I'm not really creating a typical "multiplayer game."

    Thanks!
     
  22. jose-araujo

    jose-araujo

    Joined:
    Nov 17, 2016
    Posts:
    34
    Hi @JWLewis777, I was trying to use a bit of your code in my application and for some reason, I get an error saying that the NetworkManager does not have a definition of networkAdress, networkPort, neither the StartClient(). I defined the network manager in the same way as you did, and also have enabled the UnityEngine.Networking. Any idea what could be going wrong?

    UPDATE: Found the problem... I had defined a "NetworkManager" class in another script inside the same project which screwed up things...
     
    Last edited: Mar 6, 2018
  23. jose-araujo

    jose-araujo

    Joined:
    Nov 17, 2016
    Posts:
    34
    Hi @JWLewis777, I attached the server script to a game object and created the network manager game object and attached the "network manager" component that one can find in the network list. When I run it, I get the output "NullReferenceException: object reference not set to an instance of an object" when I call any "netManager.XYZ" step. I added the network manager game object as the "netManager" in the server script game object but I get the same output error. Any ideas of what I could be doing wrong?