-
-
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.
docs: improving docs on syncvar hooks
- Loading branch information
1 parent
f84c578
commit 622d5ce
Showing
7 changed files
with
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
sidebar_position: 6 | ||
sidebar_position: 7 | ||
--- | ||
# Code Generation | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
sidebar_position: 7 | ||
sidebar_position: 8 | ||
--- | ||
# Advanced Synchronization | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
sidebar_position: 5 | ||
sidebar_position: 6 | ||
--- | ||
## Serialization Flow | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"label": "Sync Objects", | ||
"position": 3 | ||
} | ||
"position": 4 | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
sidebar_position: 4 | ||
sidebar_position: 5 | ||
--- | ||
# Sync Settings | ||
|
||
|
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,57 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
# Sync Var Hooks | ||
|
||
`SyncVar` can have hooks that are invoked when the values changes. | ||
|
||
Hooks are set using the `hook` option on the `SyncVar` attribute, the hook needs to be in the same class as the `SyncVar` | ||
|
||
```cs | ||
[SyncVar(hook = nameof(HookName))] | ||
``` | ||
|
||
|
||
A hook can be a method or a event, when using an event it should use `System.Action`. | ||
|
||
The hook can have 0, 1 or 2 args. | ||
|
||
|
||
|
||
```cs | ||
void hook0() { } | ||
|
||
void hook1(int newValue) { } | ||
|
||
void hook2(int oldValue, int newValue) { } | ||
|
||
event Action event0; | ||
|
||
event Action<int> event1; | ||
|
||
event Action<int, int> event2; | ||
``` | ||
|
||
|
||
## When is hook invoked? | ||
|
||
The following is a list of rules that SyncVar hooks follows for when and where they are invoked: | ||
|
||
- Hook only invoked if value is changed | ||
|
||
- When settings SyncVar | ||
- both flags false | ||
- invokes if host (both Server AND client active) | ||
- `invokeHookOnOwner` flag true | ||
- invokes if owner | ||
- `invokeHookOnServer` flag true | ||
- invokes if server (includes host mode) | ||
- both flags true | ||
- invokes if owner OR server | ||
|
||
- `DeserializeSyncVars` is never called on host sending update to itself, but is called when owner sends update to server | ||
|
||
- hooks are invoked in `DeserializeSyncVars` if values changes | ||
- always invokes if Only client (eg not host mode) | ||
- `invokeHookOnServer` | ||
- invokes on server (eg when an change is send from owner) |
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