コード例 #1
0
        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();
        }
コード例 #2
0
 /*Internal methods*/
 void SingletonCheck()
 {
     //singleton feature
     if (singleton == null)
     {
         singleton = this;
     }
     else if (singleton != this)
     {
         Destroy(gameObject);
     }
 }
コード例 #3
0
ファイル: PTTableTop.cs プロジェクト: BlokParty/WarGame
        //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());
            }
        }
コード例 #4
0
        IEnumerator Rule()
        {
            //Setup PTManager
            PTManager.Initialize(false);

            yield return(Connect());

            while (true)
            {
                yield return(Store());

                yield return(Game());
            }
        }
コード例 #5
0
ファイル: PTTableTop.cs プロジェクト: BlokParty/WarGame
        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));
        }
コード例 #6
0
ファイル: PTDiscovery.cs プロジェクト: BlokParty/WarGame
        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);
            }
        }