示例#1
0
        public void OnData(int connectionId, int channelId, int receiveSize)
        {
            GameStatics.OnlineSession.NetBuffer.SeekZero();
            NetworkMessageID msgId = (NetworkMessageID)GameStatics.OnlineSession.NetBuffer.ReadInt();

            switch (msgId)
            {
            case (NetworkMessageID.PlayerRegistration):
                PlayerRegistrationMsg prm = new PlayerRegistrationMsg();
                prm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandlePlayerRegistrationMsg(ref prm, connectionId);
                break;

            case (NetworkMessageID.PlayerAdd):
                PlayerAddMsg pam = new PlayerAddMsg();
                pam.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandlePlayerAddMsg(ref pam, connectionId);
                break;

            case (NetworkMessageID.SceneLoading):
                SceneLoadingMsg lsm = new SceneLoadingMsg();
                lsm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleLoadSceneMsg(ref lsm);
                break;
            }
        }
示例#2
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);
        }
示例#3
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();
            }
        }
示例#4
0
 private void HandleLoadSceneMsg(ref SceneLoadingMsg msg, int connectionId)
 {
     if (GameStatics.OnlineSession.Mode == OnlineSessionMode.Server)
     {
         // Confirm client is in same scene, and send a synchronization message
         if (msg.SceneName == SceneManager.GetActiveScene().name)
         {
             TickSyncMsg tsm = new TickSyncMsg();
             tsm.Tick      = SimulationSystem.PresentTick;
             tsm.Timestamp = GameStatics.OnlineSession.GetTimestamp();
             tsm.Serialize(GameStatics.OnlineSession.NetBuffer);
             GameStatics.OnlineSession.SendBufferToConnection(connectionId, OnlineSession.ReliableSequencedChannelId);
         }
     }
     else if (GameStatics.OnlineSession.Mode == OnlineSessionMode.Client)
     {
         SceneManager.LoadScene(msg.SceneName);
     }
 }
示例#5
0
        public void OnData(int connectionId, int channelId, int receiveSize, int msgId)
        {
            NetworkMessageID iMsgId = (NetworkMessageID)msgId;

            switch (iMsgId)
            {
            case (NetworkMessageID.SceneLoading):
                SceneLoadingMsg slm = new SceneLoadingMsg();
                slm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleLoadSceneMsg(ref slm, connectionId);
                break;

            case (NetworkMessageID.TickSync):
                TickSyncMsg tsm = new TickSyncMsg();
                tsm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleTickSyncMsg(ref tsm, connectionId);
                break;

            case (NetworkMessageID.SimpleEvent):
                SimpleEventMsg sem = new SimpleEventMsg();
                sem.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleSimpleEventMsg(connectionId, sem.Event);
                break;

            case (NetworkMessageID.SpawnPlayer):
                SpawnPlayerMsg spm = new SpawnPlayerMsg();
                spm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleSpawnPlayerMsg(ref spm, connectionId);
                break;

            case (NetworkMessageID.SpawnCharacter):
                SpawnCharacterMsg scm = new SpawnCharacterMsg();
                scm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleSpawnCharacterMsg(ref scm);
                break;

            case (NetworkMessageID.LazerHit):
                LazerFireMsg lhm = new LazerFireMsg();
                lhm.Deserialize(GameStatics.OnlineSession.NetBuffer);
                HandleLazerFireMsg(ref lhm);
                break;
            }
        }
示例#6
0
 private void HandleLoadSceneMsg(ref SceneLoadingMsg msg)
 {
     SceneManager.LoadScene(msg.SceneName);
 }