Search Unity

Third Party Displaying connection status on a slider (PUN2)

Discussion in 'Multiplayer' started by Strafe_m, Oct 28, 2022.

  1. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Heya all,

    I had a question on, how can I display photon's connection status on a slider. I'd like to do this to implement something like.
    - On play button clicked, loading screen is displayed
    - Slider displays connection status
    - When connected to master, load menu etc

    I'm unsure if this is possible, if it is what I can use to make this possible.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Strafe_m likes this.
  3. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Thanks for your reply!
    Ok so I tried this

    Code (CSharp):
    1.         switch (PhotonNetwork.NetworkingClient.State)
    2.         {
    3.             case ClientState.ConnectingToNameServer:
    4.                 loadingBar.value = .12f;
    5.                 break;
    6.             case ClientState.ConnectedToNameServer:
    7.                 loadingBar.value = .25f;
    8.                 break;
    9.             case ClientState.Authenticating:
    10.                 loadingBar.value = .38f;
    11.                 break;
    12.             case ClientState.Authenticated:
    13.                 loadingBar.value = .52f;
    14.                 break;
    15.             case ClientState.ConnectingToMasterServer:
    16.                 loadingBar.value = .69f;
    17.                 break;
    18.             case ClientState.ConnectedToMasterServer:
    19.                 loadingBar.value = 1;
    20.                 break;
    21.  
    22.         }
    But it's not really accurate, like when it reaches authenticated, it goes back a bit and then gets to ConnectingToMasterServer value. Is there a better way of doing this?
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Authentication happens on the Name Server and others, so it's not a good indicator of progress, unless you also check the server it relates to. Skip both Auth* values.

    In general it's not that easy to estimate when the connection is fully setup. I would suggest to simply have some activity indicator.
     
  5. Strafe_m

    Strafe_m

    Joined:
    Oct 24, 2022
    Posts:
    72
    Thanks for that, I'll get rid of the auth values.
    I'm very much unsure about the activity indicator you mentioned so I'll need some explanation on that!
    Thanks!
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Activity indicator as in spinning wheel, moving dots or other. Just don't show a percentage of "work done" and instead show "activity in the background, please wait".
     
    Strafe_m likes this.