Skip to content

Commit 4fa67c7

Browse files
authored
chore: remove authority & netvar perms from NetworkTransform (Unity-Technologies#1059)
* feat: networktransform pos/rot/sca thresholds on state sync * minor typo fix * add a few comments * disable some networktransform tests until post-perms changes * chore: remove authority & netvar perms from NetworkTransform
1 parent b33302c commit 4fa67c7

File tree

1 file changed

+1
-65
lines changed

1 file changed

+1
-65
lines changed

Prototyping/NetworkTransform.cs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ namespace Unity.Netcode.Prototyping
99
[AddComponentMenu("Netcode/" + nameof(NetworkTransform))]
1010
public class NetworkTransform : NetworkBehaviour
1111
{
12-
/// <summary>
13-
/// Server authority allows only the server to update this transform
14-
/// Client authority allows only the owner client to update this transform
15-
/// Shared authority allows everyone to update this transform
16-
/// </summary>
17-
public enum NetworkAuthority
18-
{
19-
Server = 0,
20-
Client,
21-
Shared
22-
}
23-
2412
internal class NetworkState : INetworkSerializable
2513
{
2614
internal const int InLocalSpaceBit = 0;
@@ -140,13 +128,6 @@ public void NetworkSerialize(NetworkSerializer serializer)
140128
}
141129
}
142130

143-
/// <summary>
144-
/// TODO this will need refactoring
145-
/// Specifies who can update this transform
146-
/// </summary>
147-
[Tooltip("Defines who can update this transform")]
148-
public NetworkAuthority Authority = NetworkAuthority.Server;
149-
150131
/// <summary>
151132
/// The network channel to use send updates
152133
/// </summary>
@@ -178,14 +159,6 @@ public void NetworkSerialize(NetworkSerializer serializer)
178159
internal readonly NetworkVariable<NetworkState> ReplNetworkState = new NetworkVariable<NetworkState>(new NetworkState());
179160
internal NetworkState PrevNetworkState;
180161

181-
/// <summary>
182-
/// Does this instance (client or server) has authority to update transform?
183-
/// </summary>
184-
public bool CanUpdateTransform =>
185-
Authority == NetworkAuthority.Client && IsClient && IsOwner ||
186-
Authority == NetworkAuthority.Server && IsServer ||
187-
Authority == NetworkAuthority.Shared;
188-
189162
// updates `NetworkState` properties if they need to and returns a `bool` indicating whether or not there was any changes made
190163
// returned boolean would be useful to change encapsulating `NetworkVariable<NetworkState>`'s dirty state, e.g. ReplNetworkState.SetDirty(isDirty);
191164
internal bool UpdateNetworkState(NetworkState networkState)
@@ -390,39 +363,13 @@ private void OnNetworkStateChanged(NetworkState oldState, NetworkState newState)
390363
return;
391364
}
392365

393-
if (Authority == NetworkAuthority.Client && IsClient && IsOwner)
394-
{
395-
// todo MTT-768 this shouldn't happen anymore with new tick system (tick written will be higher than tick read, so netvar wouldn't change in that case)
396-
return;
397-
}
398-
399366
ApplyNetworkState(newState);
400367
}
401368

402-
private void UpdateNetVarPerms()
403-
{
404-
switch (Authority)
405-
{
406-
default:
407-
throw new NotImplementedException($"Authority: {Authority} is not handled");
408-
case NetworkAuthority.Server:
409-
ReplNetworkState.Settings.WritePermission = NetworkVariablePermission.ServerOnly;
410-
break;
411-
case NetworkAuthority.Client:
412-
ReplNetworkState.Settings.WritePermission = NetworkVariablePermission.OwnerOnly;
413-
break;
414-
case NetworkAuthority.Shared:
415-
ReplNetworkState.Settings.WritePermission = NetworkVariablePermission.Everyone;
416-
break;
417-
}
418-
}
419-
420369
private void Awake()
421370
{
422371
m_Transform = transform;
423372

424-
UpdateNetVarPerms();
425-
426373
ReplNetworkState.Settings.SendNetworkChannel = Channel;
427374
ReplNetworkState.Settings.SendTickrate = FixedSendsPerSecond;
428375

@@ -446,7 +393,7 @@ private void FixedUpdate()
446393
return;
447394
}
448395

449-
if (CanUpdateTransform)
396+
if (IsServer)
450397
{
451398
ReplNetworkState.SetDirty(UpdateNetworkState(ReplNetworkState.Value));
452399
}
@@ -459,17 +406,6 @@ private void FixedUpdate()
459406
}
460407
}
461408

462-
/// <summary>
463-
/// Updates the NetworkTransform's authority model at runtime
464-
/// </summary>
465-
internal void SetAuthority(NetworkAuthority authority)
466-
{
467-
Authority = authority;
468-
UpdateNetVarPerms();
469-
// todo this should be synced with the other side.
470-
// let's wait for a more final solution before adding more code here
471-
}
472-
473409
/// <summary>
474410
/// Teleports the transform to the given values without interpolating
475411
/// </summary>

0 commit comments

Comments
 (0)