Created
June 18, 2023 12:49
-
-
Save paulhayes/6b37e245d80b0a4f9b37ca2ee0af365c to your computer and use it in GitHub Desktop.
Check for fixed IP local server, and if not found, connect to default online photon settings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using Photon.Pun; | |
using Photon.Realtime; | |
using UnityEngine; | |
public class LocalOrOnlinePhotonConnect : MonoBehaviour, IConnectionCallbacks | |
{ | |
[SerializeField] ServerSettings photonOnlineSettings; | |
[SerializeField] Photon.Realtime.AppSettings photonOfflineSettings; | |
void Start() | |
{ | |
StartCoroutine(ConnectCheckForLocalServer()); | |
} | |
IEnumerator ConnectCheckForLocalServer() | |
{ | |
PhotonNetwork.AddCallbackTarget( this ); | |
var ping = new Ping(photonOfflineSettings.Server); | |
float timeout = 1f; | |
while(!ping.isDone && timeout>0){ | |
yield return null; | |
timeout-=Time.unscaledDeltaTime; | |
} | |
Debug.Log($"isDone {ping.isDone} time={ping.time}"); | |
//PhotonNetwork.ConnectToMaster(); | |
PhotonNetwork.ConnectUsingSettings(ping.isDone ? photonOfflineSettings : photonOnlineSettings.AppSettings); | |
} | |
public void OnConnected() | |
{ | |
Debug.Log("Connect To Server"); | |
} | |
public void OnConnectedToMaster() | |
{ | |
Debug.Log("On Connected To Master"); | |
} | |
public void OnCustomAuthenticationFailed(string debugMessage) | |
{ | |
Debug.Log($"OnCustomAuthenticationFailed {debugMessage}"); | |
} | |
public void OnCustomAuthenticationResponse(Dictionary<string, object> data) | |
{ | |
} | |
public void OnDisconnected(DisconnectCause cause) | |
{ | |
Debug.Log($"OnDisconnected {cause}"); | |
} | |
public void OnRegionListReceived(RegionHandler regionHandler) | |
{ | |
Debug.Log($"OnRegionListReceived {regionHandler.BestRegion}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment