VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
ClientNetworkTransform.cs
1 using Unity.Netcode.Components;
2 using UnityEngine;
3 
4 namespace Unity.Netcode.Samples
5 {
6  /// <summary>
7  /// Used for syncing a transform with client side changes. This includes host. Pure server as owner isn't supported by this. Please use NetworkTransform
8  /// for transforms that'll always be owned by the server.
9  /// </summary>
10  [DisallowMultipleComponent]
11  public class ClientNetworkTransform : NetworkTransform
12  {
13  /// <summary>
14  /// Used to determine who can write to this transform. Owner client only.
15  /// Changing this value alone will not allow you to create a NetworkTransform which can be written to by clients.
16  /// We're using RPCs to send updated values from client to server. Netcode doesn't support client side network variable writing.
17  /// This imposes state to the server. This is putting trust on your clients. Make sure no security-sensitive features use this transform.
18  /// </summary>
19  // This is public to make sure that users don't depend on this IsClient && IsOwner check in their code. If this logic changes in the future, we can make it invisible here
20 
21  public override void OnNetworkSpawn()
22  {
23  base.OnNetworkSpawn();
24  CanCommitToTransform = IsOwner;
25  }
26 
27  protected override void Update()
28  {
29  base.Update();
30  if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening))
31  {
32  if (CanCommitToTransform)
33  {
34  TryCommitTransformToServer(transform, NetworkManager.LocalTime.Time);
35  }
36  }
37  }
38  }
39 }
Used for syncing a transform with client side changes. This includes host. Pure server as owner isn't...
override void OnNetworkSpawn()
Used to determine who can write to this transform. Owner client only. Changing this value alone will ...