Adding a dropdown menu
I can't seem to find a straightforward tutorial for this, but I have people playing my game from all over the world. I need to be able to allow them to pick their region from a dropdown menu. I have read several posts, but I don't know what to do.
Comments
-
Clients get their region list from the Name Server. Your code can access it via the
RegionHandler
, which is provided in the callbackOnRegionListReceived
. It has a list of regions you can use. Turn this into a dropdown. If a user selects a different region thanPhotonNetwork.CloudRegion
, disconnect andPhotonNetwork.ConnectToRegion(string region)
.0 -
I am trying to add the dropdown to an asset on the asset store and I have the following code. I can't seem to get it to connect. I used a debug.log and could see that the dropdown was responding, but after disconnecting and selecting a region it just goes back to US.
void Start() { PhotonNetwork.AutomaticallySyncScene = true; loadNow = false; rooms = new List<RoomInfo>(); autoReconnect = true; dropdown.onValueChanged.AddListener(delegate { DropdownValueChanged(dropdown); }); // Do connection loop: StartCoroutine(Reconnection()); } private void DropdownValueChanged(Dropdown dropdown) { PhotonNetwork.Disconnect(); switch (dropdown.value) { case 0: PhotonNetwork.ConnectToRegion("US"); break; case 1: PhotonNetwork.ConnectToRegion("CA"); break; default: throw new ArgumentException(nameof(dropdown.value)); } } // This will automatically connect the client to the server every 2 seconds if not connected: IEnumerator Reconnection(){ while(autoReconnect){ yield return new WaitForSeconds(2f); if (!PhotonNetwork.IsConnected || PhotonNetwork.NetworkClientState == ClientState.ConnectingToMasterServer){ PhotonNetwork.ConnectUsingSettings(); PhotonNetwork.GameVersion = gameVersion; //PhotonNetwork.ConnectToRegion("US") } } }
0