NetworkingPeer.ConnectToNameServer C# (CSharp) Method

ConnectToNameServer() public method

Connects to the NameServer for Photon Cloud, where a region and server list can be obtained.
public ConnectToNameServer ( ) : bool
return bool
    public bool ConnectToNameServer()
    {
        if (PhotonHandler.AppQuits)
        {
            Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
            return false;
        }

        IsUsingNameServer = true;
        this.CloudRegion = CloudRegionCode.none;

        if (this.State == global::PeerState.ConnectedToNameServer)
        {
            return true;
        }

        string address = this.NameServerAddress;
        if (!base.Connect(address, "ns"))
        {
            return false;
        }

        this.State = global::PeerState.ConnectingToNameServer;
        return true;
    }

Usage Example

Exemplo n.º 1
0
    public static bool ConnectToBestCloudServer(string gameVersion)
    {
        if (PhotonServerSettings == null)
        {
            Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: PhotonServerSettings");
            return(false);
        }

        if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
        {
            return(ConnectUsingSettings(gameVersion));
        }

        networkingPeer.IsInitialConnect = true;
        networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);
        var bestRegionCodeInPreferences = PhotonHandler.BestRegionCodeInPreferences;

        if (bestRegionCodeInPreferences != CloudRegionCode.none)
        {
            Debug.Log("Best region found in PlayerPrefs. Connecting to: " + bestRegionCodeInPreferences);
            return(networkingPeer.ConnectToRegionMaster(bestRegionCodeInPreferences));
        }

        return(networkingPeer.ConnectToNameServer());
    }
NetworkingPeer