-
Notifications
You must be signed in to change notification settings - Fork 450
feat: owner-writable NetworkVariable<T>
#1762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d174d40
`enum NetworkVariableWritePermission`
0xFA11 d874f80
Merge branch 'develop' into feat/ownernetworkvariable
0xFA11 cf748af
`clientId` -> `targetClientId`
0xFA11 de83e62
`OwnerOnly` -> `Owner`
0xFA11 e863de6
mvp
0xFA11 a17eac1
Merge branch 'develop' into feat/ownernetworkvariable
0xFA11 d797a24
minor refactor
0xFA11 7b3590f
minor fixes
0xFA11 46eb120
Merge branch 'develop' into feat/ownernetworkvariable
0xFA11 b248189
syntax fix
0xFA11 ea4f2da
bug fix
0xFA11 9eabf22
implement `NetworkVariablePermissionTests`
0xFA11 a5542b9
Merge branch 'develop' into feat/ownernetworkvariable
0xFA11 770c176
Merge branch 'develop' into feat/ownernetworkvariable
0xFA11 9726583
delete ctor tests
0xFA11 533dd6a
update changelog
0xFA11 b1c2b64
minor changelog update
0xFA11 a4fc4bc
fix `NetworkVariableTestComponent`
0xFA11 a646f46
add PR number to the changelog entry
0xFA11 aaffe62
assert on newvalue change
0xFA11 6327e3c
Merge branch 'develop' into feat/ownernetworkvariable
0xFA11 07afa2d
implement `NetworkVariablePermissionTests.ServerCannotChangeOwnerWrit…
0xFA11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -54,8 +54,6 @@ internal void GenerateGlobalObjectIdHash() | |
/// </summary> | ||
internal NetworkManager NetworkManagerOwner; | ||
|
||
private ulong m_NetworkObjectId; | ||
|
||
/// <summary> | ||
/// Gets the unique Id of this object that is synced across the network | ||
/// </summary> | ||
|
@@ -288,7 +286,6 @@ public void NetworkHide(ulong clientId) | |
throw new VisibilityChangeException("Cannot hide an object from the server"); | ||
} | ||
|
||
|
||
Observers.Remove(clientId); | ||
|
||
if (NetworkManager.NetworkConfig.UseSnapshotSpawn) | ||
|
@@ -319,7 +316,7 @@ public static void NetworkHide(List<NetworkObject> networkObjects, ulong clientI | |
throw new ArgumentNullException("At least one " + nameof(NetworkObject) + " has to be provided"); | ||
} | ||
|
||
NetworkManager networkManager = networkObjects[0].NetworkManager; | ||
var networkManager = networkObjects[0].NetworkManager; | ||
|
||
if (!networkManager.IsServer) | ||
{ | ||
|
@@ -364,27 +361,27 @@ private void OnDestroy() | |
throw new NotServerException($"Destroy a spawned {nameof(NetworkObject)} on a non-host client is not valid. Call {nameof(Destroy)} or {nameof(Despawn)} on the server/host instead."); | ||
} | ||
|
||
if (NetworkManager != null && NetworkManager.SpawnManager != null && NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(NetworkObjectId, out var networkObject)) | ||
if (NetworkManager != null && NetworkManager.SpawnManager != null && | ||
NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(NetworkObjectId, out var networkObject)) | ||
{ | ||
NetworkManager.SpawnManager.OnDespawnObject(networkObject, false); | ||
} | ||
} | ||
|
||
private SnapshotDespawnCommand GetDespawnCommand() | ||
{ | ||
var command = new SnapshotDespawnCommand(); | ||
command.NetworkObjectId = NetworkObjectId; | ||
|
||
return command; | ||
return new SnapshotDespawnCommand { NetworkObjectId = NetworkObjectId }; | ||
} | ||
|
||
private SnapshotSpawnCommand GetSpawnCommand() | ||
{ | ||
var command = new SnapshotSpawnCommand(); | ||
command.NetworkObjectId = NetworkObjectId; | ||
command.OwnerClientId = OwnerClientId; | ||
command.IsPlayerObject = IsPlayerObject; | ||
command.IsSceneObject = (IsSceneObject == null) || IsSceneObject.Value; | ||
var command = new SnapshotSpawnCommand | ||
{ | ||
NetworkObjectId = NetworkObjectId, | ||
OwnerClientId = OwnerClientId, | ||
IsPlayerObject = IsPlayerObject, | ||
IsSceneObject = (IsSceneObject == null) || IsSceneObject.Value | ||
}; | ||
|
||
ulong? parent = NetworkManager.SpawnManager.GetSpawnParentId(this); | ||
if (parent != null) | ||
|
@@ -415,8 +412,7 @@ private void SnapshotSpawn() | |
private void SnapshotSpawn(ulong clientId) | ||
{ | ||
var command = GetSpawnCommand(); | ||
command.TargetClientIds = new List<ulong>(); | ||
command.TargetClientIds.Add(clientId); | ||
command.TargetClientIds = new List<ulong> { clientId }; | ||
NetworkManager.SnapshotSystem.Spawn(command); | ||
} | ||
|
||
|
@@ -429,8 +425,7 @@ internal void SnapshotDespawn() | |
internal void SnapshotDespawn(ulong clientId) | ||
{ | ||
var command = GetDespawnCommand(); | ||
command.TargetClientIds = new List<ulong>(); | ||
command.TargetClientIds.Add(clientId); | ||
command.TargetClientIds = new List<ulong> { clientId }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, yeah, those are great changes, but they make the PR harder to process and possibly harder to merge later. We should try to have PRs that address just one thing and side clean-up PRs are fine too :-). < /nitpick> < /jeffshouldgethiscoffee> |
||
NetworkManager.SnapshotSystem.Despawn(command); | ||
} | ||
|
||
|
@@ -821,13 +816,13 @@ internal List<NetworkBehaviour> ChildNetworkBehaviours | |
} | ||
} | ||
|
||
internal void WriteNetworkVariableData(FastBufferWriter writer, ulong clientId) | ||
internal void WriteNetworkVariableData(FastBufferWriter writer, ulong targetClientId) | ||
{ | ||
for (int i = 0; i < ChildNetworkBehaviours.Count; i++) | ||
{ | ||
var behavior = ChildNetworkBehaviours[i]; | ||
behavior.InitializeVariables(); | ||
behavior.WriteNetworkVariableData(writer, clientId); | ||
behavior.WriteNetworkVariableData(writer, targetClientId); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rationale for copying the code from
ShouldWrite
and editing it here, as opposed to improving/adjusting/modifyingShouldWrite
? Just wondering what will make the code more easily maintainable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because there is no
ShouldWrite
anymore. there areCanClientRead
andCanClientWrite
for perm checks, whether or not to write (send) is determined outside, here.