Ejemplo n.º 1
0
    public void OnJoinedRoom()
    {
        OnFinishFinalize  = null;
        OnFinishFinalize += () =>
        {
            _resultHudController.gameObject.SetActive(false);
            PhotonNetwork.LeaveRoom();
        };

        OnChangeGameSequence  = null;
        OnChangeGameSequence += (GameSequence newGameSequence) =>
        {
            switch (newGameSequence)
            {
            case GameSequence.GameStart:
                LocalInitialize();
                break;

            case GameSequence.Battle:

                // RPC通信による初期化はプレイヤーが揃ってから行う
                _playerBarController.RpcRename(newObjName: $"Player{_playerIndex}Bar");
                _playerController.RpcRename(newObjName: $"Player{_playerIndex}Controller");
                _playerController.RpcInitialize(
                    myBar: _playerBarController
                    , myGoal: _playerGoalList[_playerIndex],
                    playerId: _playerIndex);

                _playerController.OnAddPoint += currentPoint =>
                {
                    _ballController.RpcEnableCollision(false);
                    _ballController.RpcSetCanMove(false);

                    if (currentPoint >= _winRequiredVictoryNum)
                    {
                        OnGameEnd?.Invoke();
                    }

                    RpcApplyPlayerPointHudText(point: currentPoint, playerId: _playerIndex);
                };

                RpcApplyPlayerPointHudText(point: 0, playerId: _playerController.PlayerId);
                _ballController.LocalInitialize();
                OnBattleStart?.Invoke();
                break;

            case GameSequence.GameEnd:
                Debug.Log("Game End");
                _ballController.RpcSetCanMove(false);
                break;
            }
        };

        Room room = PhotonNetwork.room;

        _playerIndex = room.PlayerCount - 1;

        if (room.PlayerCount == room.MaxPlayers)
        {
            var cp = room.CustomProperties;
            cp["WaitPlayer"] = false;
            room.SetCustomProperties(cp);
        }

        LocalShowResultHud(false);
        LocalSetGameSequence((int)GameSequence.GameStart);
    }