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.1] - 2022-08-23 ### Changed - Changed version to 1.0.1. (#2131) - Updated dependency on `com.unity.transport` to 1.2.0. (#2129) - When using `UnityTransport`, _reliable_ payloads are now allowed to exceed the configured 'Max Payload Size'. Unreliable payloads remain bounded by this setting. (#2081) - Preformance improvements for cases with large number of NetworkObjects, by not iterating over all unchanged NetworkObjects ### Fixed - Fixed an issue where reading/writing more than 8 bits at a time with BitReader/BitWriter would write/read from the wrong place, returning and incorrect result. (#2130) - Fixed issue with the internal `NetworkTransformState.m_Bitset` flag not getting cleared upon the next tick advancement. (#2110) - Fixed interpolation issue with `NetworkTransform.Teleport`. (#2110) - Fixed issue where the authoritative side was interpolating its transform. (#2110) - Fixed Owner-written NetworkVariable infinitely write themselves (#2109) - Fixed NetworkList issue that showed when inserting at the very end of a NetworkList (#2099) - Fixed issue where a client owner of a `NetworkVariable` with both owner read and write permissions would not update the server side when changed. (#2097) - Fixed issue when attempting to spawn a parent `GameObject`, with `NetworkObject` component attached, that has one or more child `GameObject`s, that are inactive in the hierarchy, with `NetworkBehaviour` components it will no longer attempt to spawn the associated `NetworkBehaviour`(s) or invoke ownership changed notifications but will log a warning message. (#2096) - Fixed an issue where destroying a NetworkBehaviour would not deregister it from the parent NetworkObject, leading to exceptions when the parent was later destroyed. (#2091) - Fixed issue where `NetworkObject.NetworkHide` was despawning and destroying, as opposed to only despawning, in-scene placed `NetworkObject`s. (#2086) - Fixed `NetworkAnimator` synchronizing transitions twice due to it detecting the change in animation state once a transition is started by a trigger. (#2084) - Fixed issue where `NetworkAnimator` would not synchronize a looping animation for late joining clients if it was at the very end of its loop. (#2076) - Fixed issue where `NetworkAnimator` was not removing its subscription from `OnClientConnectedCallback` when despawned during the shutdown sequence. (#2074) - Fixed IsServer and IsClient being set to false before object despawn during the shutdown sequence. (#2074) - Fixed NetworkList Value event on the server. PreviousValue is now set correctly when a new value is set through property setter. (#2067) - Fixed NetworkLists not populating on client. NetworkList now uses the most recent list as opposed to the list at the end of previous frame, when sending full updates to dynamically spawned NetworkObject. The difference in behaviour is required as scene management spawns those objects at a different time in the frame, relative to updates. (#2062)
180 lines
6.5 KiB
C#
180 lines
6.5 KiB
C#
using System;
|
|
|
|
namespace Unity.Netcode
|
|
{
|
|
/// <summary>
|
|
/// Interface for network value containers
|
|
/// </summary>
|
|
public abstract class NetworkVariableBase : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// The delivery type (QoS) to send data with
|
|
/// </summary>
|
|
internal const NetworkDelivery Delivery = NetworkDelivery.ReliableFragmentedSequenced;
|
|
|
|
/// <summary>
|
|
/// Maintains a link to the associated NetworkBehaviour
|
|
/// </summary>
|
|
private protected NetworkBehaviour m_NetworkBehaviour;
|
|
|
|
/// <summary>
|
|
/// Initializes the NetworkVariable
|
|
/// </summary>
|
|
/// <param name="networkBehaviour">The NetworkBehaviour the NetworkVariable belongs to</param>
|
|
public void Initialize(NetworkBehaviour networkBehaviour)
|
|
{
|
|
m_NetworkBehaviour = networkBehaviour;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The default read permissions
|
|
/// </summary>
|
|
public const NetworkVariableReadPermission DefaultReadPerm = NetworkVariableReadPermission.Everyone;
|
|
|
|
/// <summary>
|
|
/// The default write permissions
|
|
/// </summary>
|
|
public const NetworkVariableWritePermission DefaultWritePerm = NetworkVariableWritePermission.Server;
|
|
|
|
/// <summary>
|
|
/// The default constructor for <see cref="NetworkVariableBase"/> that can be used to create a
|
|
/// custom NetworkVariable.
|
|
/// </summary>
|
|
/// <param name="readPerm">the <see cref="NetworkVariableReadPermission"/> access settings</param>
|
|
/// <param name="writePerm">the <see cref="NetworkVariableWritePermission"/> access settings</param>
|
|
protected NetworkVariableBase(
|
|
NetworkVariableReadPermission readPerm = DefaultReadPerm,
|
|
NetworkVariableWritePermission writePerm = DefaultWritePerm)
|
|
{
|
|
ReadPerm = readPerm;
|
|
WritePerm = writePerm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The <see cref="m_IsDirty"/> property is used to determine if the
|
|
/// value of the `NetworkVariable` has changed.
|
|
/// </summary>
|
|
private bool m_IsDirty;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the name of the network variable's instance
|
|
/// (MemberInfo) where it was declared.
|
|
/// </summary>
|
|
public string Name { get; internal set; }
|
|
|
|
/// <summary>
|
|
/// The read permission for this var
|
|
/// </summary>
|
|
public readonly NetworkVariableReadPermission ReadPerm;
|
|
|
|
/// <summary>
|
|
/// The write permission for this var
|
|
/// </summary>
|
|
public readonly NetworkVariableWritePermission WritePerm;
|
|
|
|
/// <summary>
|
|
/// Sets whether or not the variable needs to be delta synced
|
|
/// </summary>
|
|
/// <param name="isDirty">Whether or not the var is dirty</param>
|
|
public virtual void SetDirty(bool isDirty)
|
|
{
|
|
m_IsDirty = isDirty;
|
|
if (m_IsDirty && m_NetworkBehaviour != null)
|
|
{
|
|
m_NetworkBehaviour.NetworkManager.MarkNetworkObjectDirty(m_NetworkBehaviour.NetworkObject);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the dirty state and marks the variable as synced / clean
|
|
/// </summary>
|
|
public virtual void ResetDirty()
|
|
{
|
|
m_IsDirty = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets Whether or not the container is dirty
|
|
/// </summary>
|
|
/// <returns>Whether or not the container is dirty</returns>
|
|
public virtual bool IsDirty()
|
|
{
|
|
return m_IsDirty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets if a specific client has permission to read the var or not
|
|
/// </summary>
|
|
/// <param name="clientId">The client id</param>
|
|
/// <returns>Whether or not the client has permission to read</returns>
|
|
public bool CanClientRead(ulong clientId)
|
|
{
|
|
switch (ReadPerm)
|
|
{
|
|
default:
|
|
case NetworkVariableReadPermission.Everyone:
|
|
return true;
|
|
case NetworkVariableReadPermission.Owner:
|
|
return clientId == m_NetworkBehaviour.NetworkObject.OwnerClientId || NetworkManager.ServerClientId == clientId;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets if a specific client has permission to write the var or not
|
|
/// </summary>
|
|
/// <param name="clientId">The client id</param>
|
|
/// <returns>Whether or not the client has permission to write</returns>
|
|
public bool CanClientWrite(ulong clientId)
|
|
{
|
|
switch (WritePerm)
|
|
{
|
|
default:
|
|
case NetworkVariableWritePermission.Server:
|
|
return clientId == NetworkManager.ServerClientId;
|
|
case NetworkVariableWritePermission.Owner:
|
|
return clientId == m_NetworkBehaviour.NetworkObject.OwnerClientId;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the ClientId of the owning client
|
|
/// </summary>
|
|
internal ulong OwnerClientId()
|
|
{
|
|
return m_NetworkBehaviour.NetworkObject.OwnerClientId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the dirty changes, that is, the changes since the variable was last dirty, to the writer
|
|
/// </summary>
|
|
/// <param name="writer">The stream to write the dirty changes to</param>
|
|
public abstract void WriteDelta(FastBufferWriter writer);
|
|
|
|
/// <summary>
|
|
/// Writes the complete state of the variable to the writer
|
|
/// </summary>
|
|
/// <param name="writer">The stream to write the state to</param>
|
|
public abstract void WriteField(FastBufferWriter writer);
|
|
|
|
/// <summary>
|
|
/// Reads the complete state from the reader and applies it
|
|
/// </summary>
|
|
/// <param name="reader">The stream to read the state from</param>
|
|
public abstract void ReadField(FastBufferReader reader);
|
|
|
|
/// <summary>
|
|
/// Reads delta from the reader and applies them to the internal value
|
|
/// </summary>
|
|
/// <param name="reader">The stream to read the delta from</param>
|
|
/// <param name="keepDirtyDelta">Whether or not the delta should be kept as dirty or consumed</param>
|
|
public abstract void ReadDelta(FastBufferReader reader, bool keepDirtyDelta);
|
|
|
|
/// <summary>
|
|
/// Virtual <see cref="IDisposable"/> implementation
|
|
/// </summary>
|
|
public virtual void Dispose()
|
|
{
|
|
}
|
|
}
|
|
}
|