Class NetworkBehaviour
The base class to override to write network code. Inherits MonoBehaviour
Inherited Members
Namespace: MLAPI
Assembly: Unity.Multiplayer.MLAPI.Runtime.dll
Syntax
public abstract class NetworkBehaviour : MonoBehaviour
Properties
CurrentTick
Stores the network tick at the NetworkBehaviourUpdate time This allows sending NetworkVariables not more often than once per network tick, regardless of the update rate
Declaration
public static ushort CurrentTick { get; }
Property Value
Type | Description |
---|---|
ushort |
HasNetworkObject
Gets whether or not this NetworkBehaviour instance has a NetworkObject owner.
Declaration
public bool HasNetworkObject { get; }
Property Value
Type | Description |
---|---|
bool |
IsClient
Gets if we are executing as client
Declaration
protected bool IsClient { get; }
Property Value
Type | Description |
---|---|
bool |
IsHost
Gets if we are executing as Host, I.E Server and Client
Declaration
protected bool IsHost { get; }
Property Value
Type | Description |
---|---|
bool |
IsLocalPlayer
Gets if the object is the the personal clients player object
Declaration
public bool IsLocalPlayer { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwnedByServer
Gets Whether or not the object has a owner
Declaration
public bool IsOwnedByServer { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwner
Gets if the object is owned by the local player or if the object is the local player object
Declaration
public bool IsOwner { get; }
Property Value
Type | Description |
---|---|
bool |
IsServer
Gets if we are executing as server
Declaration
protected static bool IsServer { get; }
Property Value
Type | Description |
---|---|
bool |
NetworkBehaviourId
Gets NetworkId for this NetworkBehaviour from the owner NetworkObject
Declaration
public ushort NetworkBehaviourId { get; }
Property Value
Type | Description |
---|---|
ushort |
NetworkManager
Gets the NetworkManager that owns this NetworkBehaviour instance
Declaration
public NetworkManager NetworkManager { get; }
Property Value
Type | Description |
---|---|
Network |
NetworkObject
Gets the NetworkObject that owns this NetworkBehaviour instance
Declaration
public NetworkObject NetworkObject { get; }
Property Value
Type | Description |
---|---|
Network |
NetworkObjectId
Gets the NetworkId of the NetworkObject that owns this NetworkBehaviour
Declaration
public ulong NetworkObjectId { get; }
Property Value
Type | Description |
---|---|
ulong |
OwnerClientId
Gets the ClientId that owns the NetworkObject
Declaration
public ulong OwnerClientId { get; }
Property Value
Type | Description |
---|---|
ulong |
Methods
GetNetworkBehaviour(ushort)
Returns a the NetworkBehaviour with a given BehaviourId for the current NetworkObject
Declaration
protected NetworkBehaviour GetNetworkBehaviour(ushort behaviourId)
Parameters
Type | Name | Description |
---|---|---|
ushort | behaviourId | The behaviourId to return |
Returns
Type | Description |
---|---|
Network |
Returns NetworkBehaviour with given behaviourId |
GetNetworkObject(ulong)
Gets the local instance of a object with a given NetworkId
Declaration
protected NetworkObject GetNetworkObject(ulong networkId)
Parameters
Type | Name | Description |
---|---|---|
ulong | networkId |
Returns
Type | Description |
---|---|
Network |
NetworkStart()
Gets called when message handlers are ready to be registered and the network is setup
Declaration
public virtual void NetworkStart()
NetworkStart(Stream)
Gets called when message handlers are ready to be registered and the network is setup. Provides a Payload if it was provided
Declaration
public virtual void NetworkStart(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream containing the spawn payload |
OnGainedOwnership()
Gets called when the local client gains ownership of this object
Declaration
public virtual void OnGainedOwnership()
OnLostOwnership()
Gets called when we loose ownership of this object
Declaration
public virtual void OnLostOwnership()