Class NetworkVariableBase
Interface for network value containers
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
Syntax
public abstract class NetworkVariableBase : IDisposable
Constructors
NetworkVariableBase(NetworkVariableReadPermission, NetworkVariableWritePermission)
The default constructor for NetworkVariableBase that can be used to create a custom NetworkVariable.
Declaration
protected NetworkVariableBase(NetworkVariableReadPermission readPerm = NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission writePerm = NetworkVariableWritePermission.Server)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkVariableReadPermission | readPerm | the NetworkVariableReadPermission access settings |
| NetworkVariableWritePermission | writePerm | the NetworkVariableWritePermission access settings |
Fields
DefaultReadPerm
The default read permissions
Declaration
public const NetworkVariableReadPermission DefaultReadPerm = Everyone
Field Value
| Type | Description |
|---|---|
| NetworkVariableReadPermission |
DefaultWritePerm
The default write permissions
Declaration
public const NetworkVariableWritePermission DefaultWritePerm = Server
Field Value
| Type | Description |
|---|---|
| NetworkVariableWritePermission |
ReadPerm
The read permission for this var
Declaration
public readonly NetworkVariableReadPermission ReadPerm
Field Value
| Type | Description |
|---|---|
| NetworkVariableReadPermission |
Properties
Name
Gets or sets the name of the network variable's instance (MemberInfo) where it was declared.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
WritePerm
The write permission for this var
Declaration
public NetworkVariableWritePermission WritePerm { get; }
Property Value
| Type | Description |
|---|---|
| NetworkVariableWritePermission |
Methods
CanClientRead(ulong)
Gets if a specific client has permission to read the var or not
Declaration
public bool CanClientRead(ulong clientId)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | clientId | The client id |
Returns
| Type | Description |
|---|---|
| bool | Whether or not the client has permission to read |
CanClientWrite(ulong)
Gets if a specific client has permission to write the var or not
Declaration
public bool CanClientWrite(ulong clientId)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | clientId | The client id |
Returns
| Type | Description |
|---|---|
| bool | Whether or not the client has permission to write |
Dispose()
Virtual IDisposable implementation
Declaration
public virtual void Dispose()
ExceedsDirtinessThreshold()
Check whether or not this variable has changed significantly enough to send an update. If not, no update will be sent even if the variable is dirty, unless the time since last update exceeds the UpdateTraits' MaxSecondsBetweenUpdates.
Declaration
public virtual bool ExceedsDirtinessThreshold()
Returns
| Type | Description |
|---|---|
| bool |
GetBehaviour()
Declaration
public NetworkBehaviour GetBehaviour()
Returns
| Type | Description |
|---|---|
| NetworkBehaviour |
Initialize(NetworkBehaviour)
Initializes the NetworkVariable
Declaration
public void Initialize(NetworkBehaviour networkBehaviour)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkBehaviour | networkBehaviour | The NetworkBehaviour the NetworkVariable belongs to |
IsDirty()
Gets Whether or not the container is dirty
Declaration
public virtual bool IsDirty()
Returns
| Type | Description |
|---|---|
| bool | Whether or not the container is dirty |
MarkNetworkBehaviourDirty()
Declaration
protected void MarkNetworkBehaviourDirty()
OnInitialize()
Called on initialization
Declaration
public virtual void OnInitialize()
ReadDelta(FastBufferReader, bool)
Reads delta from the reader and applies them to the internal value
Declaration
public abstract void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
Parameters
| Type | Name | Description |
|---|---|---|
| FastBufferReader | reader | The stream to read the delta from |
| bool | keepDirtyDelta | Whether or not the delta should be kept as dirty or consumed |
ReadField(FastBufferReader)
Reads the complete state from the reader and applies it
Declaration
public abstract void ReadField(FastBufferReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| FastBufferReader | reader | The stream to read the state from |
ResetDirty()
Resets the dirty state and marks the variable as synced / clean
Declaration
public virtual void ResetDirty()
SetDirty(bool)
Sets whether or not the variable needs to be delta synced
Declaration
public virtual void SetDirty(bool isDirty)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isDirty | Whether or not the var is dirty |
SetUpdateTraits(NetworkVariableUpdateTraits)
Sets the update traits for this network variable to determine how frequently it will send updates.
Declaration
public void SetUpdateTraits(NetworkVariableUpdateTraits traits)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkVariableUpdateTraits | traits |
WriteDelta(FastBufferWriter)
Writes the dirty changes, that is, the changes since the variable was last dirty, to the writer
Declaration
public abstract void WriteDelta(FastBufferWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| FastBufferWriter | writer | The stream to write the dirty changes to |
WriteField(FastBufferWriter)
Writes the complete state of the variable to the writer
Declaration
public abstract void WriteField(FastBufferWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| FastBufferWriter | writer | The stream to write the state to |