This repository has been archived on 2025-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs
Unity Technologies 60e2dabef4 com.unity.netcode.gameobjects@1.0.0-pre.7
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.7] - 2022-04-01

### Added

- Added editor only check prior to entering into play mode if the currently open and active scene is in the build list and if not displays a dialog box asking the user if they would like to automatically add it prior to entering into play mode. (#1828)
- Added `UnityTransport` implementation and `com.unity.transport` package dependency (#1823)
- Added `NetworkVariableWritePermission` to `NetworkVariableBase` and implemented `Owner` client writable netvars. (#1762)
- `UnityTransport` settings can now be set programmatically. (#1845)
- `FastBufferWriter` and Reader IsInitialized property. (#1859)

### Changed

- Updated `UnityTransport` dependency on `com.unity.transport` to 1.0.0 (#1849)

### Removed

- Removed `SnapshotSystem` (#1852)
- Removed `com.unity.modules.animation`, `com.unity.modules.physics` and `com.unity.modules.physics2d` dependencies from the package (#1812)
- Removed `com.unity.collections` dependency from the package (#1849)

### Fixed
- Fixed in-scene placed NetworkObjects not being found/ignored after a client disconnects and then reconnects. (#1850)
- Fixed issue where `UnityTransport` send queues were not flushed when calling `DisconnectLocalClient` or `DisconnectRemoteClient`. (#1847)
- Fixed NetworkBehaviour dependency verification check for an existing NetworkObject not searching from root parent transform relative GameObject. (#1841)
- Fixed issue where entries were not being removed from the NetworkSpawnManager.OwnershipToObjectsTable. (#1838)
- Fixed ClientRpcs would always send to all connected clients by default as opposed to only sending to the NetworkObject's Observers list by default. (#1836)
- Fixed clarity for NetworkSceneManager client side notification when it receives a scene hash value that does not exist in its local hash table. (#1828)
- Fixed client throws a key not found exception when it times out using UNet or UTP. (#1821)
- Fixed network variable updates are no longer limited to 32,768 bytes when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled. The limits are now determined by what the transport can send in a message. (#1811)
- Fixed in-scene NetworkObjects get destroyed if a client fails to connect and shuts down the NetworkManager. (#1809)
- Fixed user never being notified in the editor that a NetworkBehaviour requires a NetworkObject to function properly. (#1808)
- Fixed PlayerObjects and dynamically spawned NetworkObjects not being added to the NetworkClient's OwnedObjects (#1801)
- Fixed issue where NetworkManager would continue starting even if the NetworkTransport selected failed. (#1780)
- Fixed issue when spawning new player if an already existing player exists it does not remove IsPlayer from the previous player (#1779)
- Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications (#1777)
- Fixed parenting warning printing for false positives (#1855)
2022-04-01 00:00:00 +00:00

127 lines
4.2 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;
private protected NetworkBehaviour m_NetworkBehaviour;
public void Initialize(NetworkBehaviour networkBehaviour)
{
m_NetworkBehaviour = networkBehaviour;
}
public const NetworkVariableReadPermission DefaultReadPerm = NetworkVariableReadPermission.Everyone;
public const NetworkVariableWritePermission DefaultWritePerm = NetworkVariableWritePermission.Server;
protected NetworkVariableBase(
NetworkVariableReadPermission readPerm = DefaultReadPerm,
NetworkVariableWritePermission writePerm = DefaultWritePerm)
{
ReadPerm = readPerm;
WritePerm = writePerm;
}
private protected 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;
public readonly NetworkVariableWritePermission WritePerm;
/// <summary>
/// Sets whether or not the variable needs to be delta synced
/// </summary>
public virtual void SetDirty(bool isDirty)
{
m_IsDirty = isDirty;
}
/// <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;
}
public bool CanClientRead(ulong clientId)
{
switch (ReadPerm)
{
default:
case NetworkVariableReadPermission.Everyone:
return true;
case NetworkVariableReadPermission.Owner:
return clientId == m_NetworkBehaviour.NetworkObject.OwnerClientId;
}
}
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>
/// 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);
public virtual void Dispose()
{
}
}
}