mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkClient.RegisterSystemHandlers: OnHostClientSpawn/OnSpawn merged to prepare for WorldState
This commit is contained in:
parent
b640523f9b
commit
7306613dcc
@ -104,7 +104,6 @@ internal static void RegisterSystemHandlers(bool hostMode)
|
||||
if (hostMode)
|
||||
{
|
||||
RegisterHandler<NetworkPongMessage>(msg => {}, false);
|
||||
RegisterHandler<SpawnMessage>(OnHostClientSpawn);
|
||||
// host mode doesn't need spawning
|
||||
RegisterHandler<ObjectSpawnStartedMessage>(msg => {});
|
||||
// host mode doesn't need spawning
|
||||
@ -115,11 +114,11 @@ internal static void RegisterSystemHandlers(bool hostMode)
|
||||
else
|
||||
{
|
||||
RegisterHandler<NetworkPongMessage>(NetworkTime.OnClientPong, false);
|
||||
RegisterHandler<SpawnMessage>(OnSpawn);
|
||||
RegisterHandler<ObjectSpawnStartedMessage>(OnObjectSpawnStarted);
|
||||
RegisterHandler<ObjectSpawnFinishedMessage>(OnObjectSpawnFinished);
|
||||
RegisterHandler<EntityStateMessage>(OnEntityStateMessage);
|
||||
}
|
||||
RegisterHandler<SpawnMessage>(OnSpawn);
|
||||
RegisterHandler<ObjectDestroyMessage>(OnObjectDestroy);
|
||||
RegisterHandler<ObjectHideMessage>(OnObjectHide);
|
||||
RegisterHandler<RpcMessage>(OnRPCMessage);
|
||||
@ -1107,24 +1106,7 @@ static void ClearNullFromSpawned()
|
||||
removeFromSpawned.Clear();
|
||||
}
|
||||
|
||||
// host mode callbacks /////////////////////////////////////////////////
|
||||
internal static void OnHostClientSpawn(SpawnMessage message)
|
||||
{
|
||||
if (NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity localObject) &&
|
||||
localObject != null)
|
||||
{
|
||||
if (message.isLocalPlayer)
|
||||
InternalAddPlayer(localObject);
|
||||
|
||||
localObject.hasAuthority = message.isOwner;
|
||||
localObject.NotifyAuthority();
|
||||
localObject.OnStartClient();
|
||||
localObject.OnSetHostVisibility(true);
|
||||
CheckForLocalPlayer(localObject);
|
||||
}
|
||||
}
|
||||
|
||||
// client-only mode callbacks //////////////////////////////////////////
|
||||
// callbacks ///////////////////////////////////////////////////////////
|
||||
static void OnEntityStateMessage(EntityStateMessage message)
|
||||
{
|
||||
// Debug.Log("NetworkClient.OnUpdateVarsMessage " + msg.netId);
|
||||
@ -1188,10 +1170,30 @@ internal static void OnObjectDestroy(ObjectDestroyMessage message)
|
||||
|
||||
internal static void OnSpawn(SpawnMessage message)
|
||||
{
|
||||
// Debug.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId:X} pos={msg.position}");
|
||||
if (FindOrSpawnObject(message, out NetworkIdentity identity))
|
||||
// host mode
|
||||
if (isHostClient)
|
||||
{
|
||||
ApplySpawnPayload(identity, message);
|
||||
if (NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity localObject) &&
|
||||
localObject != null)
|
||||
{
|
||||
if (message.isLocalPlayer)
|
||||
InternalAddPlayer(localObject);
|
||||
|
||||
localObject.hasAuthority = message.isOwner;
|
||||
localObject.NotifyAuthority();
|
||||
localObject.OnStartClient();
|
||||
localObject.OnSetHostVisibility(true);
|
||||
CheckForLocalPlayer(localObject);
|
||||
}
|
||||
}
|
||||
// client only
|
||||
else
|
||||
{
|
||||
// Debug.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId:X} pos={msg.position}");
|
||||
if (FindOrSpawnObject(message, out NetworkIdentity identity))
|
||||
{
|
||||
ApplySpawnPayload(identity, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public IEnumerator LocalPlayerIsSetToNullAfterNetworkDestroy()
|
||||
|
||||
|
||||
NetworkIdentity.spawned[msg.netId] = identity;
|
||||
NetworkClient.OnHostClientSpawn(msg);
|
||||
NetworkClient.OnSpawn(msg);
|
||||
|
||||
NetworkServer.Destroy(identity.gameObject);
|
||||
|
||||
@ -47,7 +47,7 @@ public IEnumerator LocalPlayerIsSetToNullAfterNetworkUnspawn()
|
||||
};
|
||||
|
||||
NetworkIdentity.spawned[msg.netId] = identity;
|
||||
NetworkClient.OnHostClientSpawn(msg);
|
||||
NetworkClient.OnSpawn(msg);
|
||||
|
||||
NetworkServer.UnSpawn(identity.gameObject);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user