Skip to content

Commit

Permalink
style: renaming NetworkScenePath to ActiveScenePath (MirageNet#647)
Browse files Browse the repository at this point in the history
* style: renaming NetworkScenePath to ActiveScenePath

BREAKING CHANGE: Use NetworkSceneManager.ActiveScenePath instead of NetworkSceneManager.NetworkScenePath

* removing cref till docs are fixed
  • Loading branch information
James-Frowen committed Mar 5, 2021
1 parent 7ff8516 commit 7a26360
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions Assets/Mirage/Runtime/NetworkSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public class NetworkSceneManager : MonoBehaviour, INetworkSceneManager
public ClientSceneChangeEvent ServerSceneChanged => _serverSceneChanged;

/// <summary>
/// The path of the current network scene.
/// The path of the current active scene.
/// <para>If using additive scenes this will be the first scene.</para>
/// <para>Value from SceneManager.GetActiveScene() </para>
/// </summary>
/// <remarks>
/// <para>New clients that connect to a server will automatically load this scene.</para>
/// <para>This is used to make sure that all scene changes are initialized by Mirage.</para>
/// </remarks>
public string NetworkScenePath => SceneManager.GetActiveScene().path;
public string ActiveScenePath => SceneManager.GetActiveScene().path;

internal AsyncOperation asyncOperation;

Expand Down Expand Up @@ -124,7 +126,7 @@ internal void ClientSceneMessage(INetworkConnection conn, SceneMessage msg)
throw new ArgumentNullException(msg.scenePath, "ClientSceneMessage: " + msg.scenePath + " cannot be empty or null");
}

if (logger.LogEnabled()) logger.Log("ClientSceneMessage: changing scenes from: " + NetworkScenePath + " to:" + msg.scenePath);
if (logger.LogEnabled()) logger.Log("ClientSceneMessage: changing scenes from: " + ActiveScenePath + " to:" + msg.scenePath);

// Let client prepare for scene change
OnClientChangeScene(msg.scenePath, msg.sceneOperation);
Expand Down Expand Up @@ -218,12 +220,12 @@ void OnServerAuthenticated(INetworkConnection conn)
{
logger.Log("NetworkSceneManager.OnServerAuthenticated");

conn.Send(new SceneMessage { scenePath = NetworkScenePath, additiveScenes = additiveSceneList.ToArray() });
conn.Send(new SceneMessage { scenePath = ActiveScenePath, additiveScenes = additiveSceneList.ToArray() });
conn.Send(new SceneReadyMessage());
}

/// <summary>
/// This causes the server to switch scenes and sets the NetworkScenePath.
/// This causes the server to switch scenes and sets the ActiveScenePath.
/// <para>Clients that connect to this server will automatically switch to this scene. This automatically sets clients to be not-ready. The clients must call Ready() again to participate in the new scene.</para>
/// </summary>
/// <param name="scenePath"></param>
Expand Down Expand Up @@ -280,7 +282,7 @@ IEnumerator ApplySceneOperation(string scenePath, SceneOperation sceneOperation
{
case SceneOperation.Normal:
//Scene is already active.
if (NetworkScenePath.Equals(scenePath))
if (ActiveScenePath.Equals(scenePath))
{
FinishLoadScene(scenePath, sceneOperation);
}
Expand Down Expand Up @@ -331,7 +333,7 @@ IEnumerator ApplySceneOperation(string scenePath, SceneOperation sceneOperation
void OnAsyncComplete(AsyncOperation asyncOperation)
{
//This is only called in a normal scene change
FinishLoadScene(NetworkScenePath, SceneOperation.Normal);
FinishLoadScene(ActiveScenePath, SceneOperation.Normal);
}

internal void FinishLoadScene(string scenePath, SceneOperation sceneOperation)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/Runtime/ClientServer/NetworkSceneManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public void FinishLoadSceneTest()
await AsyncUtil.WaitUntilWithTimeout(() => clientSceneManager.asyncOperation.isDone);
Assert.That(clientSceneManager.NetworkScenePath, Is.EqualTo("Assets/Mirror/Tests/Runtime/testScene.unity"));
Assert.That(clientSceneManager.ActiveScenePath, Is.EqualTo("Assets/Mirror/Tests/Runtime/testScene.unity"));
func1.Received(1).Invoke(Arg.Any<string>(), Arg.Any<SceneOperation>());
});

[Test]
public void NetworkSceneNameStringValueTest()
{
Assert.That(clientSceneManager.NetworkScenePath.Equals(SceneManager.GetActiveScene().path));
Assert.That(clientSceneManager.ActiveScenePath.Equals(SceneManager.GetActiveScene().path));
}

[Test]
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 @@ -72,10 +72,10 @@ public void FinishLoadSceneHostTest()
sceneManager.ChangeServerScene("Assets/Mirror/Tests/Runtime/testScene.unity");
await AsyncUtil.WaitUntilWithTimeout(() => sceneManager.NetworkScenePath.Equals("Assets/Mirror/Tests/Runtime/testScene.unity"));
await AsyncUtil.WaitUntilWithTimeout(() => sceneManager.ActiveScenePath.Equals("Assets/Mirror/Tests/Runtime/testScene.unity"));
func1.Received(1).Invoke(Arg.Any<string>(), Arg.Any<SceneOperation>());
Assert.That(sceneManager.NetworkScenePath, Is.EqualTo("Assets/Mirror/Tests/Runtime/testScene.unity"));
Assert.That(sceneManager.ActiveScenePath, Is.EqualTo("Assets/Mirror/Tests/Runtime/testScene.unity"));
Assert.That(invokeClientSceneMessage, Is.True);
Assert.That(invokeNotReadyMessage, Is.True);
});
Expand Down

0 comments on commit 7a26360

Please sign in to comment.