示例#1
0
        protected virtual void OnEnable()
        {
            if (_networkManager == null)
            {
                _networkManager = MPNetworkManager.singleton.gameObject.GetComponent <MPNetworkManager>();
            }

            if (_menuUI == null)
            {
                _menuUI = MainMenuUI.Instance;
            }

            //Reset pages
            _currentPage  = 0;
            _previousPage = 0;

            ClearUi();

            //Disable NO SERVER FOUND error message
            _noServerFound.SetActive(false);

            _nextRefreshTime = Time.time;

            //Subscribe to network events
            if (_networkManager != null)
            {
                _networkManager.clientDisconnected += OnDisconnect;
                _networkManager.clientError        += OnError;
                _networkManager.serverError        += OnError;
                _networkManager.matchDropped       += OnDrop;
            }
        }
示例#2
0
        public void Init(MPNetworkPlayer player)
        {
            Debug.LogFormat("Initializing lobby player - Ready {0}", player.Ready);
            this._mpNetworkPlayer = player;
            if (player != null)
            {
                player.SyncVarsChanged += OnNetworkPlayerSyncvarChanged;
            }

            _netManager = MPNetworkManager.singleton.gameObject.GetComponent <MPNetworkManager>(); //TanksNetworkManager.s_Instance;
            if (_netManager != null)
            {
                _netManager.playerJoined += PlayerJoined;
                _netManager.playerLeft   += PlayerLeft;
            }

            _readyLabel.gameObject.SetActive(false);
            _waitingLabel.gameObject.SetActive(false);
            _readyButton.gameObject.SetActive(true);
            _readyButton.interactable = _netManager.hasSufficientPlayers;

            if (_netManager.gameType == NetworkGameType.SinglePlayer)
            {
                return;
            }

            MainMenuUI mainMenu = MainMenuUI.Instance;

            mainMenu.playerList.AddPlayer(this);
            mainMenu.playerList.DisplayDirectServerWarning(player.isServer && _netManager.matchMaker == null);

            if (player.hasAuthority)
            {
                SetupLocalPlayer();
            }
            else
            {
                SetupRemotePlayer();
            }

            UpdateValues();
        }
        //Fired when player clicks join
        private void JoinMatch(NetworkID networkId)
        {
            MainMenuUI menuUi = MainMenuUI.Instance;

            //menuUi.ShowConnectingModal(true);

            _netManager.JoinMatchmakingGame(networkId, (success, matchInfo) =>
            {
                //Failure flow
                if (!success)
                {
                    menuUi.ShowInfoPopup("Failed to join game.", null);
                }
                //Success flow
                else
                {
                    menuUi.HideInfoPopup();
                    menuUi.ShowInfoPopup("Entering lobby...");
                    _netManager.gameModeUpdated += menuUi.ShowLobbyPanelForConnection;
                }
            });
        }
示例#4
0
 protected virtual void Start()
 {
     _menuUi     = MainMenuUI.Instance;
     _netManager = MPNetworkManager.singleton.gameObject.GetComponent <MPNetworkManager>();
 }
 protected virtual void OnEnable()
 {
     //Get fresh references to controllers
     _netManager = MPNetworkManager.singleton.gameObject.GetComponent <MPNetworkManager>();
     _menuUi     = MainMenuUI.Instance;
 }