Skip to content

Commit

Permalink
style: Use PascalCase for public fields
Browse files Browse the repository at this point in the history
Follow C# guidelines: public Client and Server fields
should use pascal PascalCase

BREAKING CHANGE: NetworkSceneManager.client renamed to .Client
BREAKING CHANGE: NetworkSceneManager.server renamed to .Server
  • Loading branch information
paulpach committed Feb 2, 2021
1 parent 828335f commit 5f88032
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirror/Editor/NetworkMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static GameObject CreateNetworkManager()
playerSpawner.serverObjectManager = serverObjectManager;
playerSpawner.clientObjectManager = clientObjectManager;

nsm.client = networkClient;
nsm.server = networkServer;
nsm.Client = networkClient;
nsm.Server = networkServer;
return go;
}
}
Expand Down
53 changes: 28 additions & 25 deletions Assets/Mirror/Runtime/NetworkSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.Serialization;

namespace Mirror
{
Expand All @@ -20,8 +21,10 @@ public class NetworkSceneManager : MonoBehaviour, INetworkSceneManager

[Serializable] public class ClientSceneChangeEvent : UnityEvent<string, SceneOperation> { }

public NetworkClient client;
public NetworkServer server;
[FormerlySerializedAs("client")]
public NetworkClient Client;
[FormerlySerializedAs("server")]
public NetworkServer Server;

/// <summary>
/// Event fires when the Client starts changing scene.
Expand Down Expand Up @@ -63,13 +66,13 @@ public void Start()
{
DontDestroyOnLoad(gameObject);

if (client != null)
if (Client != null)
{
client.Authenticated.AddListener(OnClientAuthenticated);
Client.Authenticated.AddListener(OnClientAuthenticated);
}
if (server != null)
if (Server != null)
{
server.Authenticated.AddListener(OnServerAuthenticated);
Server.Authenticated.AddListener(OnServerAuthenticated);
}
}

Expand All @@ -78,7 +81,7 @@ public void Start()
void RegisterClientMessages(INetworkConnection connection)
{
connection.RegisterHandler<SceneMessage>(ClientSceneMessage);
if (!client.IsLocalClient)
if (!Client.IsLocalClient)
{
connection.RegisterHandler<SceneReadyMessage>(ClientSceneReadyMessage);
connection.RegisterHandler<NotReadyMessage>(ClientNotReadyMessage);
Expand All @@ -94,13 +97,13 @@ void OnClientAuthenticated(INetworkConnection conn)

void OnDestroy()
{
if (client != null)
client.Authenticated?.RemoveListener(OnClientAuthenticated);
if (Client != null)
Client.Authenticated?.RemoveListener(OnClientAuthenticated);
}

internal void ClientSceneMessage(INetworkConnection conn, SceneMessage msg)
{
if (!client.IsConnected)
if (!Client.IsConnected)
{
throw new InvalidOperationException("ClientSceneMessage: cannot change network scene while client is disconnected");
}
Expand All @@ -115,7 +118,7 @@ internal void ClientSceneMessage(INetworkConnection conn, SceneMessage msg)
OnClientChangeScene(msg.scenePath, msg.sceneOperation);

//Additive are scenes loaded on server and this client is not a host client
if(msg.additiveScenes != null && msg.additiveScenes.Length > 0 && client && !client.IsLocalClient)
if(msg.additiveScenes != null && msg.additiveScenes.Length > 0 && Client && !Client.IsLocalClient)
{
foreach (string scene in msg.additiveScenes)
{
Expand All @@ -139,7 +142,7 @@ internal void ClientNotReadyMessage(INetworkConnection conn, NotReadyMessage msg
{
logger.Log("NetworkSceneManager.OnClientNotReadyMessageInternal");

client.Connection.IsReady = false;
Client.Connection.IsReady = false;
}

/// <summary>
Expand All @@ -163,15 +166,15 @@ internal void OnClientSceneChanged(string scenePath, SceneOperation sceneOperati
{
ClientSceneChanged?.Invoke(scenePath, sceneOperation);

if (pendingAdditiveSceneList.Count > 0 && client && !client.IsLocalClient)
if (pendingAdditiveSceneList.Count > 0 && Client && !Client.IsLocalClient)
{
StartCoroutine(ApplySceneOperation(pendingAdditiveSceneList[0], SceneOperation.LoadAdditive));
pendingAdditiveSceneList.RemoveAt(0);
return;
}

//set ready after scene change has completed
if (!client.Connection.IsReady)
if (!Client.Connection.IsReady)
SetClientReady();
}

Expand All @@ -181,17 +184,17 @@ internal void OnClientSceneChanged(string scenePath, SceneOperation sceneOperati
/// </summary>
public void SetClientReady()
{
if (!client || !client.Active)
if (!Client || !Client.Active)
throw new InvalidOperationException("Ready() called with an null or disconnected client");

if (logger.LogEnabled()) logger.Log("ClientScene.Ready() called.");

// Set these before sending the ReadyMessage, otherwise host client
// will fail in InternalAddPlayer with null readyConnection.
client.Connection.IsReady = true;
Client.Connection.IsReady = true;

// Tell server we're ready to have a player object spawned
client.Connection.Send(new ReadyMessage());
Client.Connection.Send(new ReadyMessage());
}

#endregion
Expand Down Expand Up @@ -225,11 +228,11 @@ public void ChangeServerScene(string scenePath, SceneOperation sceneOperation =
// Let server prepare for scene change
OnServerChangeScene(scenePath, sceneOperation);

if(!server.LocalClientActive)
if(!Server.LocalClientActive)
StartCoroutine(ApplySceneOperation(scenePath, sceneOperation));

// notify all clients about the new scene
server.SendToAll(new SceneMessage { scenePath = scenePath, sceneOperation = sceneOperation });
Server.SendToAll(new SceneMessage { scenePath = scenePath, sceneOperation = sceneOperation });
}

/// <summary>
Expand All @@ -252,7 +255,7 @@ internal void OnServerSceneChanged(string scenePath, SceneOperation operation)
{
logger.Log("OnServerSceneChanged");

server.SendToAll(new SceneReadyMessage());
Server.SendToAll(new SceneReadyMessage());

ServerSceneChanged?.Invoke(scenePath, operation);
}
Expand All @@ -275,7 +278,7 @@ IEnumerator ApplySceneOperation(string scenePath, SceneOperation sceneOperation
asyncOperation.completed += OnAsyncComplete;

//If non host client. Wait for server to finish scene change
if (client && client.Active && !client.IsLocalClient)
if (Client && Client.Active && !Client.IsLocalClient)
{
asyncOperation.allowSceneActivation = false;
}
Expand Down Expand Up @@ -322,28 +325,28 @@ void OnAsyncComplete(AsyncOperation asyncOperation)
internal void FinishLoadScene(string scenePath, SceneOperation sceneOperation)
{
// host mode?
if (client && client.IsLocalClient)
if (Client && Client.IsLocalClient)
{
if (logger.LogEnabled()) logger.Log("Host: " + sceneOperation.ToString() + " operation for scene: " + scenePath);

// call OnServerSceneChanged
OnServerSceneChanged(scenePath, sceneOperation);

if (client.IsConnected)
if (Client.IsConnected)
{
// let client know that we changed scene
OnClientSceneChanged(scenePath, sceneOperation);
}
}
// server-only mode?
else if (server && server.Active)
else if (Server && Server.Active)
{
if (logger.LogEnabled()) logger.Log("Server: " + sceneOperation.ToString() + " operation for scene: " + scenePath);

OnServerSceneChanged(scenePath, sceneOperation);
}
// client-only mode?
else if (client && client.Active && !client.IsLocalClient)
else if (Client && Client.Active && !Client.IsLocalClient)
{
if (logger.LogEnabled()) logger.Log("Client: " + sceneOperation.ToString() + " operation for scene: " + scenePath);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/Editor/PlayerSpawnerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void Setup()
serverObjectManager = go.AddComponent<ServerObjectManager>();
clientObjectManager = go.AddComponent<ClientObjectManager>();
spawner.sceneManager = sceneManager;
sceneManager.client = client;
sceneManager.server = server;
sceneManager.Client = client;
sceneManager.Server = server;
serverObjectManager.server = server;
clientObjectManager.client = client;
clientObjectManager.networkSceneManager = sceneManager;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/Runtime/ClientServer/ClientServerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class ClientServerSetup<T> where T : NetworkBehaviour
serverSceneManager = serverGo.GetComponent<NetworkSceneManager>();
clientSceneManager = clientGo.GetComponent<NetworkSceneManager>();
serverSceneManager.server = server;
clientSceneManager.client = client;
serverSceneManager.Server = server;
clientSceneManager.Client = client;
serverSceneManager.Start();
clientSceneManager.Start();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/Runtime/Host/HostSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class HostSetup<T> where T : NetworkBehaviour
manager.server = networkManagerGo.GetComponent<NetworkServer>();
server = manager.server;
client = manager.client;
sceneManager.client = client;
sceneManager.server = server;
sceneManager.Client = client;
sceneManager.Server = server;
serverObjectManager.server = server;
serverObjectManager.networkSceneManager = sceneManager;
clientObjectManager.client = client;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/Runtime/Host/NetworkSceneManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public void ReadyTest()
[UnityTest]
public IEnumerator ReadyExceptionTest() => UniTask.ToCoroutine(async () =>
{
sceneManager.client.Disconnect();
sceneManager.Client.Disconnect();
await AsyncUtil.WaitUntilWithTimeout(() => !sceneManager.client.Active);
await AsyncUtil.WaitUntilWithTimeout(() => !sceneManager.Client.Active);
Assert.Throws<InvalidOperationException>(() =>
{
Expand Down

0 comments on commit 5f88032

Please sign in to comment.