public static void Initialize(bool isTabletop) { //Create a game object for instance if there was no one if (singleton == null) { GameObject ptManager = new GameObject(); singleton = ptManager.AddComponent <PTManager>(); } //Start nearby session finder singleton.ResetNetworkoDiscovery(); //Start server or client if (isTabletop) { singleton.StartServer(); } else { singleton.StartClient(); } //Clear players fields players.Clear(); nearbySessions.Clear(); }
/*Internal methods*/ void SingletonCheck() { //singleton feature if (singleton == null) { singleton = this; } else if (singleton != this) { Destroy(gameObject); } }
//Connect private IEnumerator Connect() { //Setup PTManager PTManager.Initialize(true); //Start accepting players, wait until player num reached the min requirement yield return(Ready()); //Display all players if (autoCreatePlayer) { yield return(DisplayPlayers()); } }
IEnumerator Rule() { //Setup PTManager PTManager.Initialize(false); yield return(Connect()); while (true) { yield return(Store()); yield return(Game()); } }
private IEnumerator Ready() { canvasConnect.gameObject.SetActive(true); print(PTManager.singleton); yield return(new WaitUntil(() => { foreach (PTPlayer player in PTManager.Players) { if (!PTManager.isReady(player)) { return false; } } return true; })); yield return(new WaitUntil(() => !canvasConnect.gameObject.activeSelf)); }
public override void OnReceivedBroadcast(string fromAddress, string data) { //Corner case if (PTManager.singleton == null) { return; } //Get the new session by received broadcast data string serverAddress = fromAddress.Contains("::ffff:") ? fromAddress.Substring(7) : fromAddress; try { //New the PTBroadcastMessage //print(data); PTSession session = PTSession.FromJson(data); //print(session); session.ip = serverAddress; //invoke DiscoveredSession on PTHandHeld if (PTManager.OnBroadcastReceieved != null) { PTManager.OnBroadcastReceieved(session); } } catch (ArgumentException e) { Debug.LogError(e); } catch (Exception) { //Debug.LogError("Unknown Error: OnReceivedBroadcast: " + data); } }