コード例 #1
0
        public override void OnClientConnect()         // Called on the client when connecting to a server
        {
            DebugLog.DebugWrite("OnClientConnect", MessageType.Info);
            base.OnClientConnect();

            OnClientConnected?.SafeInvoke();

            QSBMessageManager.Init();

            gameObject.AddComponent <RespawnOnDeath>();
            gameObject.AddComponent <ServerStateManager>();
            gameObject.AddComponent <ClientStateManager>();

            if (QSBSceneManager.IsInUniverse)
            {
                QSBWorldSync.BuildWorldObjects(QSBSceneManager.CurrentScene).Forget();
            }

            var specificType = QSBCore.IsHost ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect;

            QSBPatchManager.DoPatchType(specificType);
            QSBPatchManager.DoPatchType(QSBPatchTypes.OnClientConnect);

            Delay.RunWhen(() => PlayerTransformSync.LocalInstance,
                          () => new PlayerJoinMessage(PlayerName).Send());

            if (!QSBCore.IsHost)
            {
                Delay.RunWhen(() => PlayerTransformSync.LocalInstance,
                              () => new RequestStateResyncMessage().Send());
            }

            _everConnected = true;
        }