コード例 #1
0
 protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField)
 {
     if (!SyncVarHookGuard)
     {
         NetworkInstanceId networkInstanceId = default;
         if (newGameObject != null)
         {
             var component = newGameObject.GetComponent <QNetworkIdentity>();
             if (component != null)
             {
                 networkInstanceId = component.NetId;
                 if (networkInstanceId.IsEmpty())
                 {
                     QLog.Warning(
                         $"SetSyncVarGameObject GameObject {newGameObject} has a zero netId. Maybe it is not spawned yet?");
                 }
             }
         }
         NetworkInstanceId networkInstanceId2 = default;
         if (gameObjectField != null)
         {
             networkInstanceId2 = gameObjectField.GetComponent <QNetworkIdentity>().NetId;
         }
         if (networkInstanceId != networkInstanceId2)
         {
             QLog.Log(
                 $"SetSyncVar GameObject {GetType().Name} bit [{dirtyBit}] netfieldId:{networkInstanceId2}->{networkInstanceId}");
             SetDirtyBit(dirtyBit);
             gameObjectField = newGameObject;
             netIdField      = networkInstanceId;
         }
     }
 }
コード例 #2
0
 private void InitializeSingleton()
 {
     if (!(singleton != null) || !(singleton == this))
     {
         if (dontDestroyOnLoad)
         {
             if (singleton != null)
             {
                 QLog.Warning("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used.");
                 Destroy(gameObject);
                 return;
             }
             QLog.Log("NetworkManager created singleton (DontDestroyOnLoad)");
             singleton = this;
             if (Application.isPlaying)
             {
                 DontDestroyOnLoad(gameObject);
             }
         }
         else
         {
             QLog.Log("NetworkManager created singleton (ForScene)");
             singleton = this;
         }
         if (networkAddress != "")
         {
             s_Address = networkAddress;
         }
         else if (s_Address != "")
         {
             networkAddress = s_Address;
         }
     }
 }
コード例 #3
0
 public virtual void OnServerReady(QNetworkConnection conn)
 {
     if (conn.PlayerControllers.Count == 0)
     {
         QLog.Warning("Ready with no player object");
     }
     QNetworkServer.SetClientReady(conn);
 }
コード例 #4
0
 protected void SendTargetRPCInternal(QNetworkConnection conn, QNetworkWriter writer, int channelId, string rpcName)
 {
     if (!IsServer)
     {
         QLog.Warning("TargetRpc call on un-spawned object");
         return;
     }
     writer.FinishMessage();
     conn.SendWriter(writer, channelId);
 }
コード例 #5
0
 protected void SendRPCInternal(QNetworkWriter writer, int channelId, string rpcName)
 {
     if (!IsServer)
     {
         QLog.Warning("ClientRpc call on un-spawned object");
         return;
     }
     writer.FinishMessage();
     QNetworkServer.SendWriterToReady(gameObject, writer, channelId);
 }
コード例 #6
0
 protected void SendCommandInternal(QNetworkWriter writer, int channelId, string cmdName)
 {
     if (!IsLocalPlayer && !HasAuthority)
     {
         QLog.Warning("Trying to send command for object without authority.");
     }
     else if (QClientScene.readyConnection == null)
     {
         QLog.Error($"Send command attempted with no client running [client={ConnectionToServer}].");
     }
     else
     {
         writer.FinishMessage();
         QClientScene.readyConnection.SendWriter(writer, channelId);
     }
 }
コード例 #7
0
 private void OnServerAddPlayerInternal(QNetworkConnection conn, short playerControllerId)
 {
     if (playerPrefab == null)
     {
         QLog.FatalError("The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object.");
     }
     else if (playerPrefab.GetComponent <QNetworkIdentity>() == null)
     {
         QLog.FatalError("The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab.");
     }
     else if (playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[playerControllerId].IsValid && conn.PlayerControllers[playerControllerId].Gameobject != null)
     {
         QLog.Warning("There is already a player at that playerControllerId for this connections.");
     }
     else
     {
         var player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
         QNetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
     }
 }
コード例 #8
0
        private bool CheckChannel(int channelId)
        {
            bool result;

            if (m_Channels == null)
            {
                QLog.Warning($"Channels not initialized sending on id '{channelId}");
                result = false;
            }
            else if (channelId < 0 || channelId >= m_Channels.Length)
            {
                QLog.Error(
                    $"Invalid channel when sending buffered data, '{channelId}'. Current channel count is {m_Channels.Length}");
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
コード例 #9
0
        public static void HandleTransform(QNetworkMessage netMsg)
        {
            var networkInstanceId = netMsg.Reader.ReadNetworkId();
            var gameObject        = QNetworkServer.FindLocalObject(networkInstanceId);

            if (gameObject == null)
            {
                QLog.Warning("Received NetworkTransform data for GameObject that doesn't exist");
            }
            else
            {
                var component = gameObject.GetComponent <QNetworkTransform>();
                if (component == null)
                {
                    QLog.Warning("HandleTransform null target");
                }
                else if (!component.LocalPlayerAuthority)
                {
                    QLog.Warning("HandleTransform no localPlayerAuthority");
                }
                else if (netMsg.Connection.ClientOwnedObjects == null)
                {
                    QLog.Warning("HandleTransform object not owned by connection");
                }
                else if (netMsg.Connection.ClientOwnedObjects.Contains(networkInstanceId))
                {
                    component.UnserializeModeTransform(netMsg.Reader, false);
                    component.LastSyncTime = Time.time;
                }
                else
                {
                    QLog.Warning(
                        $"HandleTransform netId:{networkInstanceId} is not for a valid player");
                }
            }
        }