This commit is contained in:
vis2k 2021-03-07 16:41:27 +08:00
parent 3667f76703
commit f06e6f0509

View File

@ -54,10 +54,7 @@ internal static void Shutdown()
DestroyAllClientObjects(); DestroyAllClientObjects();
} }
/// <summary> // called from message handler for Owner message
/// this is called from message handler for Owner message
/// </summary>
/// <param name="identity"></param>
internal static void InternalAddPlayer(NetworkIdentity identity) internal static void InternalAddPlayer(NetworkIdentity identity)
{ {
//Debug.Log("ClientScene.InternalAddPlayer"); //Debug.Log("ClientScene.InternalAddPlayer");
@ -77,21 +74,15 @@ internal static void InternalAddPlayer(NetworkIdentity identity)
else Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer"); else Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer");
} }
/// <summary> // Sets localPlayer to null. Should be called when the local player
/// Sets localPlayer to null // object is destroyed.
/// <para>Should be called when the local player object is destroyed</para>
/// </summary>
internal static void ClearLocalPlayer() internal static void ClearLocalPlayer()
{ {
//Debug.Log("ClientScene.ClearLocalPlayer"); //Debug.Log("ClientScene.ClearLocalPlayer");
localPlayer = null; localPlayer = null;
} }
/// <summary> /// <summary>Sends AddPlayer message to the server, indicating that we want to join the world.</summary>
/// This adds a player GameObject for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer is called.
/// </summary>
/// <param name="readyConn">The connection to become ready for this client.</param>
/// <returns>True if AddPlayer message was sent</returns>
public static bool AddPlayer(NetworkConnection readyConn) public static bool AddPlayer(NetworkConnection readyConn)
{ {
// ensure valid ready connection // ensure valid ready connection
@ -118,12 +109,11 @@ public static bool AddPlayer(NetworkConnection readyConn)
return true; return true;
} }
/// <summary> /// <summary>Sends Ready message to server, indicating that we loaded the scene, ready to enter the game.</summary>
/// Signal that the client connection is ready to enter the game. // This could be for example when a client enters an ongoing game and
/// <para>This could be for example when a client enters an ongoing game and has finished loading the current scene. The server should respond to the SYSTEM_READY event with an appropriate handler which instantiates the players object for example.</para> // has finished loading the current scene. The server should respond to
/// </summary> // the SYSTEM_READY event with an appropriate handler which instantiates
/// <param name="conn">The client connection which is ready.</param> // the players object for example.
/// <returns>True if successful</returns>
public static bool Ready(NetworkConnection conn) public static bool Ready(NetworkConnection conn)
{ {
if (ready) if (ready)
@ -144,7 +134,6 @@ public static bool Ready(NetworkConnection conn)
// Tell server we're ready to have a player object spawned // Tell server we're ready to have a player object spawned
conn.Send(new ReadyMessage()); conn.Send(new ReadyMessage());
return true; return true;
} }
Debug.LogError("Ready() called with invalid connection object: conn=null"); Debug.LogError("Ready() called with invalid connection object: conn=null");
@ -160,9 +149,7 @@ internal static void HandleClientDisconnect(NetworkConnection conn)
} }
} }
/// <summary> // Checks if identity is not spawned yet, not hidden and has sceneId
/// Checks if identity is not spawned yet, not hidden and has sceneId
/// </summary>
static bool ConsiderForSpawning(NetworkIdentity identity) static bool ConsiderForSpawning(NetworkIdentity identity)
{ {
// not spawned yet, not hidden, etc.? // not spawned yet, not hidden, etc.?
@ -172,9 +159,7 @@ static bool ConsiderForSpawning(NetworkIdentity identity)
identity.sceneId != 0; identity.sceneId != 0;
} }
/// <summary> /// <summary>Call this after loading/unloading a scene in the client after connection to register the spawnable objects</summary>
/// Call this after loading/unloading a scene in the client after connection to register the spawnable objects
/// </summary>
public static void PrepareToSpawnSceneObjects() public static void PrepareToSpawnSceneObjects()
{ {
// remove existing items, they will be re-added below // remove existing items, they will be re-added below