mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix #1475: isClient is true in OnDestroy on host/client mode again. Reverts commit d00c95bb55
(#1483)
* fix #1475: isClient is true in OnDestroy on host/client mode again. Reverts commit d00c95bb55
* add comment
* ClientScene.InternalAddPlayer doesn't need to set isClient anymore
This commit is contained in:
parent
82a4af9a62
commit
9f7c30c1ac
@ -73,6 +73,11 @@ internal static void InternalAddPlayer(NetworkIdentity identity)
|
||||
// NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated.
|
||||
// But, the player structures are not cleaned up, we'll just replace the old player
|
||||
localPlayer = identity;
|
||||
|
||||
// NOTE: we DONT need to set isClient=true here, because OnStartClient
|
||||
// is called before OnStartLocalPlayer, hence it's already set.
|
||||
// localPlayer.isClient = true;
|
||||
|
||||
if (readyConnection != null)
|
||||
{
|
||||
readyConnection.identity = identity;
|
||||
|
@ -57,7 +57,13 @@ public sealed class NetworkIdentity : MonoBehaviour
|
||||
/// <summary>
|
||||
/// Returns true if running as a client and this object was spawned by a server.
|
||||
/// </summary>
|
||||
public bool isClient => NetworkClient.active && netId != 0 && !serverOnly;
|
||||
//
|
||||
// IMPORTANT: checking NetworkClient.active means that isClient is false in OnDestroy:
|
||||
// public bool isClient => NetworkClient.active && netId != 0 && !serverOnly;
|
||||
// but we need it in OnDestroy, e.g. when saving skillbars on quit. this
|
||||
// works fine if we keep the UNET way of setting isClient manually.
|
||||
// => fixes https://github.com/vis2k/Mirror/issues/1475
|
||||
public bool isClient { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if NetworkServer.active and server is not stopped.
|
||||
@ -509,6 +515,13 @@ internal void OnStartServer()
|
||||
// because we already set m_isServer=true above)
|
||||
spawned[netId] = this;
|
||||
|
||||
// in host mode we set isClient true before calling OnStartServer,
|
||||
// otherwise isClient is false in OnStartServer.
|
||||
if (NetworkClient.active)
|
||||
{
|
||||
isClient = true;
|
||||
}
|
||||
|
||||
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||
{
|
||||
try
|
||||
@ -529,6 +542,8 @@ internal void OnStartClient()
|
||||
return;
|
||||
clientStarted = true;
|
||||
|
||||
isClient = true;
|
||||
|
||||
if (LogFilter.Debug) Debug.Log("OnStartClient " + gameObject + " netId:" + netId);
|
||||
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||
{
|
||||
@ -1135,6 +1150,7 @@ internal void Reset()
|
||||
return;
|
||||
|
||||
clientStarted = false;
|
||||
isClient = false;
|
||||
reset = false;
|
||||
|
||||
netId = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user