示例#1
0
        public void HandleSpawnCharacterMsg(ref SpawnCharacterMsg msg)
        {
            if (GameStatics.OnlineSession.Mode == OnlineSessionMode.Client)
            {
                MyCharacterController spawnedCharacter = Instantiate(GameStatics.GameData.CharacterPrefab);

                // Assign to player
                SimulationSystem.GetPlayerControllerWithId(msg.ForPlayerId).Character = spawnedCharacter;

                // if this is a local player's character, assign it to the local player
                bool hasOwnership = false;
                MyPlayerController forPlayer;
                if (SimulationSystem.RegisteredPlayerControllers.TryGetValue(msg.ForPlayerId, out forPlayer))
                {
                    if (forPlayer.GetIsLocal())
                    {
                        hasOwnership = true;
                        forPlayer.OrbitCamera.SetFollowTransform(spawnedCharacter.CameraFollowPoint);
                        forPlayer.OrbitCamera.IgnoredColliders = spawnedCharacter.GetComponentsInChildren <Collider>();
                    }
                }

                KinematicCharacterSubsystem.RegisterCharacterAtId(spawnedCharacter, msg.CharacterId, hasOwnership);
                spawnedCharacter.Motor.SetPositionAndRotation(msg.SpawnPosition, msg.SpawnRotation, true);
            }
        }
示例#2
0
        public void NetworkSpawnCharacter(MyCharacterController spawnedCharacter, int spawnedCharacterId, int forPlayerId)
        {
            // Character spawn msg
            SpawnCharacterMsg scm = new SpawnCharacterMsg();

            scm.CharacterId   = spawnedCharacterId;
            scm.ForPlayerId   = forPlayerId;
            scm.SpawnPosition = spawnedCharacter.transform.position;
            scm.SpawnRotation = spawnedCharacter.transform.rotation;
            scm.Serialize(GameStatics.OnlineSession.NetBuffer);
            GameStatics.OnlineSession.SendBufferToAllClients(OnlineSession.ReliableSequencedChannelId);
        }
示例#3
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;
            }
        }