C# Класс Mirror.NetworkBehaviour

Наследование: MonoBehaviour
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
syncObjects List

Открытые методы

Метод Описание
ClearAllDirtyBits ( ) : void

This clears all the dirty bits that were set on this script by SetDirtyBits();

This is automatically invoked when an update is sent for this object, but can be called manually as well.

IsDirty ( ) : bool
OnDeserialize ( Mirror.NetworkReader reader, bool initialState ) : void

Virtual function to override to receive custom serialization data. The corresponding function to send serialization data is OnSerialize().

OnSerialize ( Mirror.NetworkWriter writer, bool initialState ) : bool

Virtual function to override to send custom serialization data. The corresponding function to send serialization data is OnDeserialize().

The initialState flag is useful to differentiate between the first time an object is serialized and when incremental updates can be sent. The first time an object is sent to a client, it must include a full state snapshot, but subsequent updates can save on bandwidth by including only incremental changes. Note that SyncVar hook functions are not called when initialState is true, only for incremental updates.

If a class has SyncVars, then an implementation of this function and OnDeserialize() are added automatically to the class. So a class that has SyncVars cannot also have custom serialization functions.

The OnSerialize function should return true to indicate that an update should be sent. If it returns true, then the dirty bits for that script are set to zero, if it returns false then the dirty bits are not changed. This allows multiple changes to a script to be accumulated over time and sent when the system is ready, instead of every frame.

OnStartAuthority ( ) : void

This is invoked on behaviours that have authority, based on context and NetworkIdentity.hasAuthority.

This is called after OnStartServer and before OnStartClient.

When AssignClientAuthority is called on the server, this will be called on the client that owns the object. When an object is spawned with NetworkServer.Spawn with a NetworkConnection parameter included, this will be called on the client that owns the object.

OnStartClient ( ) : void

Called on every NetworkBehaviour when it is activated on a client.

Objects on the host have this function called, as there is a local client on the host. The values of SyncVars on object are guaranteed to be initialized correctly with the latest state from the server when this function is called on the client.

OnStartLocalPlayer ( ) : void

Called when the local player object has been set up.

This happens after OnStartClient(), as it is triggered by an ownership message from the server. This is an appropriate place to activate components or functionality that should only be active for the local player, such as cameras and input.

OnStartServer ( ) : void

This is invoked for NetworkBehaviour objects when they become active on the server.

This could be triggered by NetworkServer.Listen() for objects in the scene, or by NetworkServer.Spawn() for objects that are dynamically created.

This will be called for objects on a "host" as well as for object on a dedicated server.

OnStopAuthority ( ) : void

This is invoked on behaviours when authority is removed.

When NetworkIdentity.RemoveClientAuthority is called on the server, this will be called on the client that owns the object.

OnStopClient ( ) : void

This is invoked on clients when the server has caused this object to be destroyed.

This can be used as a hook to invoke effects or do client specific cleanup.

OnStopServer ( ) : void

Invoked on the server when the object is unspawned

Useful for saving object data in persistent storage

SerializeObjectsAll ( NetworkWriter writer ) : bool
SerializeObjectsDelta ( NetworkWriter writer ) : bool
SetDirtyBit ( ulong dirtyBit ) : void

Used to set the behaviour as dirty, so that a network update will be sent for the object. these are masks, not bit numbers, ie. 0x004 not 2

Защищенные методы

Метод Описание
DeserializeSyncVars ( Mirror.NetworkReader reader, bool initialState ) : void
GetSyncVarGameObject ( uint netId, GameObject &gameObjectField ) : GameObject
GetSyncVarNetworkBehaviour ( NetworkBehaviourSyncVar syncNetBehaviour, &behaviourField ) : T
GetSyncVarNetworkIdentity ( uint netId, Mirror.NetworkIdentity &identityField ) : Mirror.NetworkIdentity
InitSyncObject ( Mirror.SyncObject syncObject ) : void
SendCommandInternal ( Type invokeClass, string cmdName, NetworkWriter writer, int channelId, bool ignoreAuthority = false ) : void
SendRPCInternal ( Type invokeClass, string rpcName, NetworkWriter writer, int channelId, bool excludeOwner ) : void
SendTargetRPCInternal ( NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId ) : void
SerializeSyncVars ( NetworkWriter writer, bool initialState ) : bool
SetSyncVar ( value, &fieldValue, ulong dirtyBit ) : void
SetSyncVarGameObject ( GameObject newGameObject, GameObject &gameObjectField, ulong dirtyBit, uint &netIdField ) : void
SetSyncVarNetworkBehaviour ( newBehaviour, &behaviourField, ulong dirtyBit, NetworkBehaviourSyncVar &syncField ) : void
SetSyncVarNetworkIdentity ( NetworkIdentity newIdentity, NetworkIdentity &identityField, ulong dirtyBit, uint &netIdField ) : void
SyncVarEqual ( value, &fieldValue ) : bool
SyncVarGameObjectEqual ( GameObject newGameObject, uint netIdField ) : bool
SyncVarNetworkBehaviourEqual ( newBehaviour, NetworkBehaviourSyncVar syncField ) : bool
SyncVarNetworkIdentityEqual ( NetworkIdentity newIdentity, uint netIdField ) : bool
getSyncVarHookGuard ( ulong dirtyBit ) : bool
setSyncVarHookGuard ( ulong dirtyBit, bool value ) : void

Приватные методы

Метод Описание
AnySyncObjectDirty ( ) : bool
DeSerializeObjectsAll ( Mirror.NetworkReader reader ) : void
DeSerializeObjectsDelta ( Mirror.NetworkReader reader ) : void
DirtyObjectBits ( ) : ulong
ResetSyncObjects ( ) : void

Описание методов

ClearAllDirtyBits() публичный Метод

This clears all the dirty bits that were set on this script by SetDirtyBits();

This is automatically invoked when an update is sent for this object, but can be called manually as well.

public ClearAllDirtyBits ( ) : void
Результат void

DeserializeSyncVars() защищенный Метод

protected DeserializeSyncVars ( Mirror.NetworkReader reader, bool initialState ) : void
reader Mirror.NetworkReader
initialState bool
Результат void

GetSyncVarGameObject() защищенный Метод

protected GetSyncVarGameObject ( uint netId, GameObject &gameObjectField ) : GameObject
netId uint
gameObjectField GameObject
Результат GameObject

GetSyncVarNetworkBehaviour() защищенный Метод

protected GetSyncVarNetworkBehaviour ( NetworkBehaviourSyncVar syncNetBehaviour, &behaviourField ) : T
syncNetBehaviour NetworkBehaviourSyncVar
Результат T

GetSyncVarNetworkIdentity() защищенный Метод

protected GetSyncVarNetworkIdentity ( uint netId, Mirror.NetworkIdentity &identityField ) : Mirror.NetworkIdentity
netId uint
identityField Mirror.NetworkIdentity
Результат Mirror.NetworkIdentity

InitSyncObject() защищенный Метод

protected InitSyncObject ( Mirror.SyncObject syncObject ) : void
syncObject Mirror.SyncObject
Результат void

IsDirty() публичный Метод

public IsDirty ( ) : bool
Результат bool

OnDeserialize() публичный Метод

Virtual function to override to receive custom serialization data. The corresponding function to send serialization data is OnSerialize().
public OnDeserialize ( Mirror.NetworkReader reader, bool initialState ) : void
reader Mirror.NetworkReader Reader to read from the stream.
initialState bool True if being sent initial state.
Результат void

OnSerialize() публичный Метод

Virtual function to override to send custom serialization data. The corresponding function to send serialization data is OnDeserialize().

The initialState flag is useful to differentiate between the first time an object is serialized and when incremental updates can be sent. The first time an object is sent to a client, it must include a full state snapshot, but subsequent updates can save on bandwidth by including only incremental changes. Note that SyncVar hook functions are not called when initialState is true, only for incremental updates.

If a class has SyncVars, then an implementation of this function and OnDeserialize() are added automatically to the class. So a class that has SyncVars cannot also have custom serialization functions.

The OnSerialize function should return true to indicate that an update should be sent. If it returns true, then the dirty bits for that script are set to zero, if it returns false then the dirty bits are not changed. This allows multiple changes to a script to be accumulated over time and sent when the system is ready, instead of every frame.

public OnSerialize ( Mirror.NetworkWriter writer, bool initialState ) : bool
writer Mirror.NetworkWriter Writer to use to write to the stream.
initialState bool If this is being called to send initial state.
Результат bool

OnStartAuthority() публичный Метод

This is invoked on behaviours that have authority, based on context and NetworkIdentity.hasAuthority.

This is called after OnStartServer and before OnStartClient.

When AssignClientAuthority is called on the server, this will be called on the client that owns the object. When an object is spawned with NetworkServer.Spawn with a NetworkConnection parameter included, this will be called on the client that owns the object.

public OnStartAuthority ( ) : void
Результат void

OnStartClient() публичный Метод

Called on every NetworkBehaviour when it is activated on a client.

Objects on the host have this function called, as there is a local client on the host. The values of SyncVars on object are guaranteed to be initialized correctly with the latest state from the server when this function is called on the client.

public OnStartClient ( ) : void
Результат void

OnStartLocalPlayer() публичный Метод

Called when the local player object has been set up.

This happens after OnStartClient(), as it is triggered by an ownership message from the server. This is an appropriate place to activate components or functionality that should only be active for the local player, such as cameras and input.

public OnStartLocalPlayer ( ) : void
Результат void

OnStartServer() публичный Метод

This is invoked for NetworkBehaviour objects when they become active on the server.

This could be triggered by NetworkServer.Listen() for objects in the scene, or by NetworkServer.Spawn() for objects that are dynamically created.

This will be called for objects on a "host" as well as for object on a dedicated server.

public OnStartServer ( ) : void
Результат void

OnStopAuthority() публичный Метод

This is invoked on behaviours when authority is removed.

When NetworkIdentity.RemoveClientAuthority is called on the server, this will be called on the client that owns the object.

public OnStopAuthority ( ) : void
Результат void

OnStopClient() публичный Метод

This is invoked on clients when the server has caused this object to be destroyed.

This can be used as a hook to invoke effects or do client specific cleanup.

public OnStopClient ( ) : void
Результат void

OnStopServer() публичный Метод

Invoked on the server when the object is unspawned

Useful for saving object data in persistent storage

public OnStopServer ( ) : void
Результат void

SendCommandInternal() защищенный Метод

protected SendCommandInternal ( Type invokeClass, string cmdName, NetworkWriter writer, int channelId, bool ignoreAuthority = false ) : void
invokeClass Type
cmdName string
writer NetworkWriter
channelId int
ignoreAuthority bool
Результат void

SendRPCInternal() защищенный Метод

protected SendRPCInternal ( Type invokeClass, string rpcName, NetworkWriter writer, int channelId, bool excludeOwner ) : void
invokeClass Type
rpcName string
writer NetworkWriter
channelId int
excludeOwner bool
Результат void

SendTargetRPCInternal() защищенный Метод

protected SendTargetRPCInternal ( NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId ) : void
conn NetworkConnection
invokeClass Type
rpcName string
writer NetworkWriter
channelId int
Результат void

SerializeObjectsAll() публичный Метод

public SerializeObjectsAll ( NetworkWriter writer ) : bool
writer NetworkWriter
Результат bool

SerializeObjectsDelta() публичный Метод

public SerializeObjectsDelta ( NetworkWriter writer ) : bool
writer NetworkWriter
Результат bool

SerializeSyncVars() защищенный Метод

protected SerializeSyncVars ( NetworkWriter writer, bool initialState ) : bool
writer NetworkWriter
initialState bool
Результат bool

SetDirtyBit() публичный Метод

Used to set the behaviour as dirty, so that a network update will be sent for the object. these are masks, not bit numbers, ie. 0x004 not 2
public SetDirtyBit ( ulong dirtyBit ) : void
dirtyBit ulong Bit mask to set.
Результат void

SetSyncVar() защищенный Метод

protected SetSyncVar ( value, &fieldValue, ulong dirtyBit ) : void
dirtyBit ulong
Результат void

SetSyncVarGameObject() защищенный Метод

protected SetSyncVarGameObject ( GameObject newGameObject, GameObject &gameObjectField, ulong dirtyBit, uint &netIdField ) : void
newGameObject GameObject
gameObjectField GameObject
dirtyBit ulong
netIdField uint
Результат void

SetSyncVarNetworkBehaviour() защищенный Метод

protected SetSyncVarNetworkBehaviour ( newBehaviour, &behaviourField, ulong dirtyBit, NetworkBehaviourSyncVar &syncField ) : void
dirtyBit ulong
syncField NetworkBehaviourSyncVar
Результат void

SetSyncVarNetworkIdentity() защищенный Метод

protected SetSyncVarNetworkIdentity ( NetworkIdentity newIdentity, NetworkIdentity &identityField, ulong dirtyBit, uint &netIdField ) : void
newIdentity NetworkIdentity
identityField NetworkIdentity
dirtyBit ulong
netIdField uint
Результат void

SyncVarEqual() защищенный Метод

protected SyncVarEqual ( value, &fieldValue ) : bool
Результат bool

SyncVarGameObjectEqual() защищенный Метод

protected SyncVarGameObjectEqual ( GameObject newGameObject, uint netIdField ) : bool
newGameObject GameObject
netIdField uint
Результат bool

SyncVarNetworkBehaviourEqual() защищенный Метод

protected SyncVarNetworkBehaviourEqual ( newBehaviour, NetworkBehaviourSyncVar syncField ) : bool
syncField NetworkBehaviourSyncVar
Результат bool

SyncVarNetworkIdentityEqual() защищенный Метод

protected SyncVarNetworkIdentityEqual ( NetworkIdentity newIdentity, uint netIdField ) : bool
newIdentity NetworkIdentity
netIdField uint
Результат bool

getSyncVarHookGuard() защищенный Метод

protected getSyncVarHookGuard ( ulong dirtyBit ) : bool
dirtyBit ulong
Результат bool

setSyncVarHookGuard() защищенный Метод

protected setSyncVarHookGuard ( ulong dirtyBit, bool value ) : void
dirtyBit ulong
value bool
Результат void

Описание свойств

syncObjects защищенное свойство

objects that can synchronize themselves, such as synclists
protected List syncObjects
Результат List