Portal - improved comments

This commit is contained in:
MrGadget1024 2023-10-22 06:58:28 -04:00
parent 64f2f109d5
commit 2bf9bcdcdf

View File

@ -14,7 +14,7 @@ public class Portal : NetworkBehaviour
[Tooltip("Where to spawn player in Destination Scene")]
public Vector3 startPosition;
[Tooltip("Reference to child TMP label")]
[Tooltip("Reference to child TextMesh label")]
public TextMesh label; // don't depend on TMPro. 2019 errors.
[SyncVar(hook = nameof(OnLabelTextChanged))]
@ -62,15 +62,21 @@ IEnumerator SendPlayerToNewScene(GameObject player)
NetworkConnectionToClient conn = identity.connectionToClient;
if (conn == null) yield break;
// Tell client to unload previous subscene. No custom handling for this.
// Tell client to unload previous subscene with custom handling (see NetworkManager::OnClientChangeScene).
conn.Send(new SceneMessage { sceneName = gameObject.scene.path, sceneOperation = SceneOperation.UnloadAdditive, customHandling = true });
// wait for fader to complete
yield return new WaitForSeconds(AdditiveLevelsNetworkManager.singleton.fadeInOut.GetDuration());
// Remove player after fader has completed
NetworkServer.RemovePlayerForConnection(conn, false);
// reposition player on server and client
player.transform.position = startPosition;
// Rotate player to face center of scene
// Player is 2m tall with pivot at 0,1,0 so we need to look at
// 1m height to not tilt the player down to look at origin
player.transform.LookAt(Vector3.up);
// Move player to new subscene.
@ -79,9 +85,11 @@ IEnumerator SendPlayerToNewScene(GameObject player)
// Tell client to load the new subscene with custom handling (see NetworkManager::OnClientChangeScene).
conn.Send(new SceneMessage { sceneName = destinationScene, sceneOperation = SceneOperation.LoadAdditive, customHandling = true });
// Player will be spawned after destination scene is loaded
NetworkServer.AddPlayerForConnection(conn, player);
// host client would have been disabled by OnTriggerEnter above
// host client playerController would have been disabled by OnTriggerEnter above
// Remote client players are respawned with playerController already enabled
if (NetworkClient.localPlayer != null && NetworkClient.localPlayer.TryGetComponent(out PlayerController playerController))
playerController.enabled = true;
}