Пример #1
0
        public void OnStartGameButton()
        {
            SceneLoadingMsg lsm = new SceneLoadingMsg();

            lsm.SceneName = GameStatics.GameData.GameSceneName;
            lsm.Serialize(GameStatics.OnlineSession.NetBuffer);
            GameStatics.OnlineSession.SendBufferToAllClients(OnlineSession.ReliableSequencedChannelId);

            SceneManager.LoadScene(GameStatics.GameData.GameSceneName);
        }
Пример #2
0
        private void Awake()
        {
            GameStatics.GameManager = this;

            InitializeSubsystems();

            // Create the simulation system
            int snapshotsCapacity = Mathf.CeilToInt((0.001f * (float)GameStatics.OnlineSession.ConnectionConfig.DisconnectTimeout) / Time.fixedDeltaTime);

            SimulationSystem = new SimulationSystem <MyPlayerController, MyPlayerCommands, MyWorldSnapshot>();
            SimulationSystem.Initialize(
                this,
                GameStatics.OnlineSession,
                MaxLocalPlayers,
                MaxPlayers,
                Mathf.RoundToInt(MaxPlayers * 1.5f),
                snapshotsCapacity);

            // Build ConnectionInfos
            if (GameStatics.OnlineSession.Mode == OnlineSessionMode.Server)
            {
                foreach (ClientConnection conn in GameStatics.OnlineSession.ClientConnections)
                {
                    ConnectionInfo ci = new ConnectionInfo();
                    ci.ConnectionId = conn.ConnectionId;
                    ConnectionInfos.Add(ci);
                }
            }

            // If client, notify server the scene is loaded
            if (GameStatics.OnlineSession.Mode == OnlineSessionMode.Client)
            {
                SceneLoadingMsg lsm = new SceneLoadingMsg();
                lsm.SceneName = SceneManager.GetActiveScene().name;
                lsm.Serialize(GameStatics.OnlineSession.NetBuffer);
                GameStatics.OnlineSession.SendBufferToServer(OnlineSession.ReliableSequencedChannelId);
            }

            // If server with no connections, initiate game now
            if (GameStatics.OnlineSession.Mode == OnlineSessionMode.Server && ConnectionInfos.Count <= 0)
            {
                OnReadyToInitiateGame();
            }
        }