Пример #1
0
    public IEnumerator WaitForServerCommands(int port)
    {
        roomPort = port;
        //to jest odpowiedzialne za poruszanie graczem
        //wysylasz swoj ruch i konczysz polaczenie
        //udpClient.SendRequestPlayerMove(playerMove, 58278);
        //laczysz sie z serwerem i sluchasz wiadomosci

        Debug.Log("<color=lime>START LISTENING</color>");
        udpClient = new UdpManager();
        udpClient.Connect(port);
        while (true)
        {
            string data = udpClient.waitForMessages(port);

            // data analysis
            if (data.Length > 0)
            {
                Debug.Log("<color=orange>Data acquired: '" + data + "'</color>");

                if (data.Contains("playerList"))    // player list
                {
                    Debug.Log("<color=orange>Acquired player list!</color>");
                    MainMenuController.Instance.RefreshPlayerNames(ResponseHandler.getArrayFromString(data));
                }
                else if (data.Contains("roomStart"))    // start game
                {
                    Debug.Log("Start game");
                    online = true;
                    MainMenuController.Instance.StartGame();
                }
                else if (data.Contains("ENDOFTURN"))
                {
                    Debug.Log("END OF TURN");
                    GameController.Instance.TurnEndedButtonPressed();
                }
            }

            yield return(null);

            //jak jakas przyjdzie mozesz dac break i znow SendRequestPlayerMove z twoim ruchem
        }
    }