Exemple #1
0
 private static void OnObjectSpawn(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectSpawnMessage);
     if (!s_ObjectSpawnMessage.assetId.IsValid())
     {
         Debug.LogError($"OnObjSpawn netId: {s_ObjectSpawnMessage.NetId} has invalid asset Id. {s_ObjectSpawnMessage.assetId}");
     }
     else
     {
         if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.NetId, out var component))
         {
             ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, null);
         }
         else if (QNetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out var original))
         {
             var gameObject = Object.Instantiate(original, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Rotation);
             component = gameObject.GetComponent <QNetworkIdentity>();
             if (component == null)
             {
                 Debug.LogError($"Client object spawned for {s_ObjectSpawnMessage.assetId} does not have a NetworkIdentity");
             }
             else
             {
                 component.Reset();
                 ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, gameObject);
             }
         }
         else if (QNetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out var spawnDelegate))
         {
             var gameObject2 = spawnDelegate(s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.assetId);
             if (gameObject2 == null)
             {
                 Debug.LogWarning($"Client spawn handler for {s_ObjectSpawnMessage.assetId} returned null");
             }
             else
             {
                 component = gameObject2.GetComponent <QNetworkIdentity>();
                 if (component == null)
                 {
                     Debug.LogError($"Client object spawned for {s_ObjectSpawnMessage.assetId} does not have a network identity");
                 }
                 else
                 {
                     component.Reset();
                     component.SetDynamicAssetId(s_ObjectSpawnMessage.assetId);
                     ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, gameObject2);
                 }
             }
         }
         else
         {
             Debug.LogError($"Failed to spawn server object, did you forget to add it to the QSBNetworkManager? assetId={s_ObjectSpawnMessage.assetId} netId={s_ObjectSpawnMessage.NetId}");
         }
     }
 }
Exemple #2
0
        internal static string GetStringForAssetId(NetworkHash128 assetId)
        {
            if (QNetworkScene.GetPrefab(assetId, out var gameObject))
            {
                return(gameObject.name);
            }

            return(QNetworkScene.GetSpawnHandler(assetId, out var func)
                                ? func.GetMethodName()
                                : "unknown");
        }