示例#1
0
        protected override void OnMessage(MessageEventArgs e)
        {
            // Debug.Log("PlayerInput: " + e.Data);
            var playerInput = JsonUtility.FromJson <PlayerInput>(e.Data);

            WSServerState.SetPlayerInput(playerInput);
        }
示例#2
0
    void InitNetwork()
    {
        WSServerState.Reset();

        if (DebugStandalone)
        {
            WSServer.Stop();
            WSServerState.Reset();
            WSClient.Disconnect();
            WSClientState.Reset();
            WSServer.StartFake();
            WSClient.ConnectFake();
        }
        else if (IsClient)
        {
            WSServer.Stop();
            WSServerState.Reset();
            WSClient.Connect();
        }
        else
        {
            WSClient.Disconnect();
            WSClientState.Reset();
            if (!WSServer.IsRunning)
            {
                WSServer.Start();
            }
        }
    }
示例#3
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var deviceId = int.Parse(e.Data);

            Debug.Log("Join: " + deviceId);
            WSServerState.AddJoinPlayer(deviceId);
        }
示例#4
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var deviceId = int.Parse(e.Data);

            Debug.Log("Leave: " + deviceId);
            WSServerState.RemovePlayer(deviceId);
            if (GameManagerScript.GameState == 2)
            {
                GameManagerScript.ResetServer = true;
            }
        }
示例#5
0
    public static void Join()
    {
        if (Init.DebugStandalone)
        {
            WSServerState.AddJoinPlayer(WSConfig.DeviceId);
            return;
        }

        if (_join == null)
        {
            Debug.LogError("Not yet connected");
            return;
        }

        _join.Send(WSConfig.DeviceId.ToString());
    }
示例#6
0
    public static void UpdatePlayerInput(PlayerInput playerInput)
    {
        if (Init.DebugStandalone)
        {
            WSServerState.SetPlayerInput(playerInput);
            return;
        }

        if (_updatePlayerInput == null)
        {
            Debug.LogError("Not yet connected");
            return;
        }

        var json = JsonUtility.ToJson(playerInput);

        _updatePlayerInput.Send(json);
    }
示例#7
0
    public static void Leave()
    {
        WSClientState.Reset();

        if (Init.DebugStandalone)
        {
            WSServerState.RemovePlayer(WSConfig.DeviceId);
            return;
        }

        if (_leave == null)
        {
            Debug.LogError("Not yet connected");
            return;
        }

        _leave.Send(WSConfig.DeviceId.ToString());
    }
示例#8
0
    //판넬 키는 부분
    void Update()
    {
        ScoreView.Set(Score.P1Score, Score.P2Score);
        TimerView.Set((int)ServerGameTime);

        if (GameState == 0)
        {
            if (Players.ContainsKey(WSConfig.DeviceId))
            {
                ReadyButton.SetActive(false);
            }

            if (Init.DebugStandalone)
            {
                GameStart();
            }
            else if (Players.Count >= 2)
            {
                WSClient.Join();
                ReadyPanel.SetActive(false);
                Invoke("GameStart", 0.5f);
            }
            else
            {
                ReadyPanel.SetActive(true);
            }
        }
        else if (GameState == 1)
        {
            if (ServerGameTime < 0.0f || Score.P1Score == 10 || Score.P2Score == 10)
            {
                var maybeMyTeam = MyTeam;
                int myTeam      = 0;
                if (maybeMyTeam.HasValue)
                {
                    myTeam = maybeMyTeam.Value;
                }
                else
                {
                    Debug.LogError("My player not found");
                    myTeam = 0;
                }

                GameState = 2;
                var meWinState = 0;
                ResultPanel.SetActive(true);
                if (Score.P1Score > Score.P2Score)
                {
                    ManWin.SetActive(true);
                    GirlLose.SetActive(true);
                    meWinState = (myTeam == 0) ? 1 : -1;
                }
                else if (Score.P1Score == Score.P2Score)
                {
                    ManLose.SetActive(true);
                    GirlLose.SetActive(true);
                    meWinState = 0;
                }
                else
                {
                    ManLose.SetActive(true);
                    GirlWin.SetActive(true);
                    meWinState = (myTeam == 0) ? -1 : 1;
                }

                if (meWinState == 1)
                {
                    WinButton.SetActive(true);
                }
                if (meWinState == 0)
                {
                    DrawButton.SetActive(true);
                }
                if (meWinState == -1)
                {
                    LoseButton.SetActive(true);
                }
            }
        }

        if (ResetServer && WSServer.IsRunning)
        {
            ResetServer = false;
            if (WSServerState.JoinedPlayers.Count < 2)
            {
                WSServerState.Reset();
            }
            SceneManager.LoadScene("main");
        }
    }
示例#9
0
 protected void SetServerState(WSServerState serverState)
 {
     this.serverState = serverState;
 }