-
-
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.
flag that can be used inside syncvar hooks to tell if it is the spawn payload or not
- Loading branch information
1 parent
315825e
commit cce01f8
Showing
3 changed files
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using Mirage.Serialization; | ||
using NUnit.Framework; | ||
|
||
namespace Mirage.Tests.Runtime | ||
{ | ||
public class SyncVarInitialStateFlagBehaviour : NetworkBehaviour | ||
{ | ||
public event Action<int> Hook; | ||
|
||
[SyncVar(hook = nameof(Hook))] | ||
public int number; | ||
} | ||
public class SyncVarInitialStateFlagTest : TestBase | ||
{ | ||
private readonly NetworkWriter ownerWriter = new NetworkWriter(1300); | ||
private readonly NetworkWriter observersWriter = new NetworkWriter(1300); | ||
private readonly NetworkReader reader = new NetworkReader(); | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
TearDownTestObjects(); | ||
|
||
ownerWriter.Reset(); | ||
observersWriter.Reset(); | ||
reader.Dispose(); | ||
} | ||
|
||
[Test] | ||
[TestCase(true)] | ||
[TestCase(false)] | ||
public void InitialStateHasCorrectValue(bool input) | ||
{ | ||
var server = CreateBehaviour<SyncVarInitialStateFlagBehaviour>(); | ||
var client = CreateBehaviour<SyncVarInitialStateFlagBehaviour>(); | ||
|
||
server.number = 10; | ||
|
||
var invoked = 0; | ||
var result = false; | ||
client.Hook += (_) => | ||
{ | ||
invoked++; | ||
result = client.Identity.InitialState; | ||
}; | ||
|
||
server.Identity.OnSerializeAll(input, ownerWriter, observersWriter); | ||
reader.Reset(observersWriter.ToArraySegment()); | ||
client.Identity.OnDeserializeAll(reader, input); | ||
|
||
Assert.That(invoked, Is.EqualTo(1)); | ||
Assert.That(result, Is.EqualTo(input)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.