-
-
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.
feat: allowing events to be used with syncvar hook (#991)
- Loading branch information
1 parent
fc7d8e3
commit f455a2d
Showing
11 changed files
with
257 additions
and
23 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
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,42 @@ | ||
using System; | ||
using System.Collections; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools; | ||
|
||
namespace Mirage.Tests.Runtime.ClientServer | ||
{ | ||
public class BehaviourWithSyncVarEvent : NetworkBehaviour | ||
{ | ||
[SyncVar(hook = nameof(OnHealthChanged))] | ||
public int health; | ||
|
||
public event Action<int, int> OnHealthChanged; | ||
} | ||
|
||
public class SyncVarEventHook : ClientServerSetup<BehaviourWithSyncVarEvent> | ||
{ | ||
[UnityTest] | ||
public IEnumerator SyncVarHookEventIsCalled() | ||
{ | ||
const int SValue = 10; | ||
const int CValue = 2; | ||
int clientA = default; | ||
int clientB = default; | ||
int called = 0; | ||
clientComponent.health = CValue; | ||
clientComponent.OnHealthChanged += (a, b) => | ||
{ | ||
clientA = a; | ||
clientB = b; | ||
called++; | ||
}; | ||
serverComponent.health = SValue; | ||
yield return null; | ||
yield return null; | ||
|
||
Assert.That(called, Is.EqualTo(1)); | ||
Assert.That(clientA, Is.EqualTo(CValue)); | ||
Assert.That(clientB, Is.EqualTo(SValue)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Runtime/ClientServer/SyncVarEventHook.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
13 changes: 13 additions & 0 deletions
13
Assets/Tests/Weaver/SyncVarHookTests~/ErrorWhenEventArgsAreWrong.cs
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,13 @@ | ||
using Mirage; | ||
using System; | ||
|
||
namespace SyncVarHookTests.ErrorWhenEventArgsAreWrong | ||
{ | ||
class ErrorWhenEventArgsAreWrong : NetworkBehaviour | ||
{ | ||
[SyncVar(hook = nameof(OnChangeHealth))] | ||
int health; | ||
|
||
public event Action<int, float> OnChangeHealth; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Assets/Tests/Weaver/SyncVarHookTests~/ErrorWhenHookNotAction.cs
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,14 @@ | ||
using Mirage; | ||
using System; | ||
|
||
namespace SyncVarHookTests.ErrorWhenHookNotAction | ||
{ | ||
delegate void DoStuff(int a, int b); | ||
class ErrorWhenHookNotAction : NetworkBehaviour | ||
{ | ||
[SyncVar(hook = nameof(OnChangeHealth))] | ||
int health; | ||
|
||
public event DoStuff OnChangeHealth; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Assets/Tests/Weaver/SyncVarHookTests~/ErrorWhenNotGenericAction.cs
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,13 @@ | ||
using Mirage; | ||
using System; | ||
|
||
namespace SyncVarHookTests.ErrorWhenNotGenericAction | ||
{ | ||
class ErrorWhenNotGenericAction : NetworkBehaviour | ||
{ | ||
[SyncVar(hook = nameof(OnChangeHealth))] | ||
int health; | ||
|
||
public event Action OnChangeHealth; | ||
} | ||
} |
Oops, something went wrong.