mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Test fixes & ForceShown test
This commit is contained in:
parent
12ce588711
commit
477d430a3f
@ -78,7 +78,7 @@ protected void RemoveObserver(NetworkConnectionToClient connection, NetworkIdent
|
|||||||
/// For ForceShown: Makes sure all ready connections (that aren't already) are added to observers
|
/// For ForceShown: Makes sure all ready connections (that aren't already) are added to observers
|
||||||
protected void AddObserversAllReady(NetworkIdentity identity)
|
protected void AddObserversAllReady(NetworkIdentity identity)
|
||||||
{
|
{
|
||||||
foreach (NetworkConnectionToClient connection in identity.observers.Values)
|
foreach (NetworkConnectionToClient connection in NetworkServer.connections.Values)
|
||||||
{
|
{
|
||||||
if (connection.isReady && !identity.observers.ContainsKey(connection.connectionId))
|
if (connection.isReady && !identity.observers.ContainsKey(connection.connectionId))
|
||||||
{
|
{
|
||||||
|
@ -24,10 +24,14 @@ protected NetworkIdentity CreatePlayerNI(int connectionId, Action<NetworkIdentit
|
|||||||
prespawn?.Invoke(identity);
|
prespawn?.Invoke(identity);
|
||||||
NetworkConnectionToClient connection = new NetworkConnectionToClient(connectionId);
|
NetworkConnectionToClient connection = new NetworkConnectionToClient(connectionId);
|
||||||
connection.isAuthenticated = true;
|
connection.isAuthenticated = true;
|
||||||
connection.isReady = true;
|
|
||||||
connection.identity = identity;
|
connection.identity = identity;
|
||||||
NetworkServer.connections[connection.connectionId] = connection;
|
if (!NetworkServer.connections.TryAdd(connectionId, connection))
|
||||||
|
{
|
||||||
|
throw new Exception("Duplicate connection id");
|
||||||
|
}
|
||||||
|
|
||||||
NetworkServer.Spawn(gameObject, connection);
|
NetworkServer.Spawn(gameObject, connection);
|
||||||
|
NetworkServer.SetClientReady(connection); // AddPlayerForConnection also calls this!
|
||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +93,7 @@ public void ForceHidden()
|
|||||||
// A should not be seen by B because A is force hidden
|
// A should not be seen by B because A is force hidden
|
||||||
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.False);
|
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.False);
|
||||||
// B should be seen by A
|
// B should be seen by A
|
||||||
Assert.That(b.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
Assert.That(b.observers.ContainsKey(a.connectionToClient.connectionId), Is.True);
|
||||||
|
|
||||||
// If we now set a to default, and rebuild, they should both see each other!
|
// If we now set a to default, and rebuild, they should both see each other!
|
||||||
a.visibility = Visibility.Default;
|
a.visibility = Visibility.Default;
|
||||||
@ -97,7 +101,7 @@ public void ForceHidden()
|
|||||||
AssertSelfVisible(a);
|
AssertSelfVisible(a);
|
||||||
AssertSelfVisible(b);
|
AssertSelfVisible(b);
|
||||||
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
||||||
Assert.That(b.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
Assert.That(b.observers.ContainsKey(a.connectionToClient.connectionId), Is.True);
|
||||||
// If we now set both hidden, and rebuild, they both won't see each other!
|
// If we now set both hidden, and rebuild, they both won't see each other!
|
||||||
a.visibility = Visibility.ForceHidden;
|
a.visibility = Visibility.ForceHidden;
|
||||||
b.visibility = Visibility.ForceHidden;
|
b.visibility = Visibility.ForceHidden;
|
||||||
@ -111,6 +115,45 @@ public void ForceHidden()
|
|||||||
[Test]
|
[Test]
|
||||||
public void ForceShown()
|
public void ForceShown()
|
||||||
{
|
{
|
||||||
|
// A and B are at (0,0,0) so within range!
|
||||||
|
var a = CreatePlayerNI(1, ni => ni.visibility = Visibility.ForceShown);
|
||||||
|
var b = CreatePlayerNI(2);
|
||||||
|
|
||||||
|
// no rebuild required here due to initial state :)
|
||||||
|
AssertSelfVisible(a);
|
||||||
|
AssertSelfVisible(b);
|
||||||
|
// A&B should see each other
|
||||||
|
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
||||||
|
Assert.That(b.observers.ContainsKey(a.connectionToClient.connectionId), Is.True);
|
||||||
|
aoi.LateUpdate();
|
||||||
|
// rebuild doesnt change that
|
||||||
|
// no rebuild required here due to initial state :)
|
||||||
|
AssertSelfVisible(a);
|
||||||
|
AssertSelfVisible(b);
|
||||||
|
// A&B should see each other
|
||||||
|
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
||||||
|
Assert.That(b.observers.ContainsKey(a.connectionToClient.connectionId), Is.True);
|
||||||
|
|
||||||
|
// If we now move A out of range of B
|
||||||
|
a.transform.position = new Vector3(aoi.visRange * 100, 0, 0);
|
||||||
|
aoi.LateUpdate();
|
||||||
|
AssertSelfVisible(a);
|
||||||
|
AssertSelfVisible(b);
|
||||||
|
|
||||||
|
// a will be seen by B still
|
||||||
|
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
||||||
|
// But B is out of range of A
|
||||||
|
Assert.That(b.observers.ContainsKey(a.connectionToClient.connectionId), Is.False);
|
||||||
|
|
||||||
|
|
||||||
|
// B to ForceShown:
|
||||||
|
b.visibility = Visibility.ForceShown;
|
||||||
|
aoi.LateUpdate();
|
||||||
|
AssertSelfVisible(a);
|
||||||
|
AssertSelfVisible(b);
|
||||||
|
// A&B should see each other
|
||||||
|
Assert.That(a.observers.ContainsKey(b.connectionToClient.connectionId), Is.True);
|
||||||
|
Assert.That(b.observers.ContainsKey(a.connectionToClient.connectionId), Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
Loading…
Reference in New Issue
Block a user