The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.0.0-pre.5] - 2022-01-26 ### Added - Added `PreviousValue` in `NetworkListEvent`, when `Value` has changed (#1528) ### Changed - NetworkManager's GameObject is no longer allowed to be nested under one or more GameObject(s).(#1484) - NetworkManager DontDestroy property was removed and now NetworkManager always is migrated into the DontDestroyOnLoad scene. (#1484) ### Fixed - Fixed network tick value sometimes being duplicated or skipped. (#1614) - Fixed The ClientNetworkTransform sample script to allow for owner changes at runtime. (#1606)
41 lines
1.7 KiB
C#
41 lines
1.7 KiB
C#
using Unity.Netcode.Components;
|
|
using UnityEngine;
|
|
|
|
namespace Unity.Netcode.Samples
|
|
{
|
|
/// <summary>
|
|
/// Used for syncing a transform with client side changes. This includes host. Pure server as owner isn't supported by this. Please use NetworkTransform
|
|
/// for transforms that'll always be owned by the server.
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
public class ClientNetworkTransform : NetworkTransform
|
|
{
|
|
/// <summary>
|
|
/// Used to determine who can write to this transform. Owner client only.
|
|
/// Changing this value alone will not allow you to create a NetworkTransform which can be written to by clients.
|
|
/// We're using RPCs to send updated values from client to server. Netcode doesn't support client side network variable writing.
|
|
/// This imposes state to the server. This is putting trust on your clients. Make sure no security-sensitive features use this transform.
|
|
/// </summary>
|
|
// 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
|
|
|
|
public override void OnNetworkSpawn()
|
|
{
|
|
base.OnNetworkSpawn();
|
|
CanCommitToTransform = IsOwner;
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
CanCommitToTransform = IsOwner;
|
|
base.Update();
|
|
if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening))
|
|
{
|
|
if (CanCommitToTransform)
|
|
{
|
|
TryCommitTransformToServer(transform, NetworkManager.LocalTime.Time);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|