-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixing syncDirection for syncObjects in host mode
- Loading branch information
1 parent
6a6e870
commit ec45074
Showing
6 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Collections; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools; | ||
|
||
namespace Mirage.Tests.Runtime.Syncing | ||
{ | ||
public class SyncDirectionObjectFromServer_Host : SyncDirectionTestBase_Host<MockPlayerWithList> | ||
{ | ||
private const int listValue = 5; | ||
|
||
[UnityTest] | ||
public IEnumerator ToOwner() | ||
{ | ||
SetDirection(SyncFrom.Server, SyncTo.Owner); | ||
|
||
hostComponent.guild = guild; | ||
hostComponent.MySyncList.Add(listValue); | ||
|
||
// wait for sync | ||
yield return null; | ||
yield return null; | ||
|
||
Assert.That(hostComponent.guild.name, Is.EqualTo(guild.name)); | ||
Assert.That(hostComponent.MySyncList.Count, Is.EqualTo(1)); | ||
Assert.That(hostComponent.MySyncList[0], Is.EqualTo(listValue)); | ||
|
||
Assert.That(ObserverComponent.guild.name, Is.Null.Or.Empty); | ||
Assert.That(ObserverComponent.MySyncList.Count, Is.Zero); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator ToObserver() | ||
{ | ||
SetDirection(SyncFrom.Server, SyncTo.ObserversOnly); | ||
|
||
hostComponent.guild = guild; | ||
hostComponent.MySyncList.Add(listValue); | ||
|
||
// wait for sync | ||
yield return null; | ||
yield return null; | ||
|
||
// host mode, so should still be set | ||
Assert.That(hostComponent.guild.name, Is.EqualTo(guild.name)); | ||
Assert.That(hostComponent.MySyncList.Count, Is.EqualTo(1)); | ||
Assert.That(hostComponent.MySyncList[0], Is.EqualTo(listValue)); | ||
|
||
Assert.That(ObserverComponent.guild.name, Is.EqualTo(guild.name)); | ||
Assert.That(ObserverComponent.MySyncList.Count, Is.EqualTo(1)); | ||
Assert.That(ObserverComponent.MySyncList[0], Is.EqualTo(listValue)); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator ToOwnerAndObserver() | ||
{ | ||
SetDirection(SyncFrom.Server, SyncTo.OwnerAndObservers); | ||
|
||
hostComponent.guild = guild; | ||
hostComponent.MySyncList.Add(listValue); | ||
|
||
// wait for sync | ||
yield return null; | ||
yield return null; | ||
|
||
Assert.That(hostComponent.guild.name, Is.EqualTo(guild.name)); | ||
Assert.That(hostComponent.MySyncList.Count, Is.EqualTo(1)); | ||
Assert.That(hostComponent.MySyncList[0], Is.EqualTo(listValue)); | ||
|
||
Assert.That(ObserverComponent.guild.name, Is.EqualTo(guild.name)); | ||
Assert.That(ObserverComponent.MySyncList.Count, Is.EqualTo(1)); | ||
Assert.That(ObserverComponent.MySyncList[0], Is.EqualTo(listValue)); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator CanAddInStartServer() | ||
{ | ||
var clone = InstantiateForTest(_characterPrefab); | ||
var component = clone.GetComponent<MockPlayerWithList>(); | ||
clone.OnStartServer.AddListener(() => | ||
{ | ||
component.MySyncList.Add(listValue); | ||
}); | ||
|
||
serverObjectManager.Spawn(clone); | ||
|
||
// wait for sync | ||
yield return null; | ||
yield return null; | ||
|
||
var clientObj = _remoteClients[0].Get(component); | ||
|
||
Assert.That(clientObj.MySyncList.Count, Is.EqualTo(1)); | ||
Assert.That(clientObj.MySyncList[0], Is.EqualTo(listValue)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Runtime/Syncing/SyncDirectionObject_Host.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters