C# Class Mirror.NetworkBehaviour

Inheritance: MonoBehaviour
Mostrar archivo Open project: BatteryAcid/unity-custom-gamelift-server Class Usage Examples

Protected Properties

Property Type Description
syncObjects List

Public Methods

Method Description
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

Protected Methods

Method Description
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

Private Methods

Method Description
AnySyncObjectDirty ( ) : bool
DeSerializeObjectsAll ( Mirror.NetworkReader reader ) : void
DeSerializeObjectsDelta ( Mirror.NetworkReader reader ) : void
DirtyObjectBits ( ) : ulong
ResetSyncObjects ( ) : void

Method Details

ClearAllDirtyBits() public method

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
return void

DeserializeSyncVars() protected method

protected DeserializeSyncVars ( Mirror.NetworkReader reader, bool initialState ) : void
reader Mirror.NetworkReader
initialState bool
return void

GetSyncVarGameObject() protected method

protected GetSyncVarGameObject ( uint netId, GameObject &gameObjectField ) : GameObject
netId uint
gameObjectField GameObject
return GameObject

GetSyncVarNetworkBehaviour() protected method

protected GetSyncVarNetworkBehaviour ( NetworkBehaviourSyncVar syncNetBehaviour, &behaviourField ) : T
syncNetBehaviour NetworkBehaviourSyncVar
return T

GetSyncVarNetworkIdentity() protected method

protected GetSyncVarNetworkIdentity ( uint netId, Mirror.NetworkIdentity &identityField ) : Mirror.NetworkIdentity
netId uint
identityField Mirror.NetworkIdentity
return Mirror.NetworkIdentity

InitSyncObject() protected method

protected InitSyncObject ( Mirror.SyncObject syncObject ) : void
syncObject Mirror.SyncObject
return void

IsDirty() public method

public IsDirty ( ) : bool
return bool

OnDeserialize() public method

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.
return void

OnSerialize() public method

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.
return bool

OnStartAuthority() public method

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
return void

OnStartClient() public method

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
return void

OnStartLocalPlayer() public method

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
return void

OnStartServer() public method

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
return void

OnStopAuthority() public method

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
return void

OnStopClient() public method

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
return void

OnStopServer() public method

Invoked on the server when the object is unspawned

Useful for saving object data in persistent storage

public OnStopServer ( ) : void
return void

SendCommandInternal() protected method

protected SendCommandInternal ( Type invokeClass, string cmdName, NetworkWriter writer, int channelId, bool ignoreAuthority = false ) : void
invokeClass Type
cmdName string
writer NetworkWriter
channelId int
ignoreAuthority bool
return void

SendRPCInternal() protected method

protected SendRPCInternal ( Type invokeClass, string rpcName, NetworkWriter writer, int channelId, bool excludeOwner ) : void
invokeClass Type
rpcName string
writer NetworkWriter
channelId int
excludeOwner bool
return void

SendTargetRPCInternal() protected method

protected SendTargetRPCInternal ( NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId ) : void
conn NetworkConnection
invokeClass Type
rpcName string
writer NetworkWriter
channelId int
return void

SerializeObjectsAll() public method

public SerializeObjectsAll ( NetworkWriter writer ) : bool
writer NetworkWriter
return bool

SerializeObjectsDelta() public method

public SerializeObjectsDelta ( NetworkWriter writer ) : bool
writer NetworkWriter
return bool

SerializeSyncVars() protected method

protected SerializeSyncVars ( NetworkWriter writer, bool initialState ) : bool
writer NetworkWriter
initialState bool
return bool

SetDirtyBit() public method

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.
return void

SetSyncVar() protected method

protected SetSyncVar ( value, &fieldValue, ulong dirtyBit ) : void
dirtyBit ulong
return void

SetSyncVarGameObject() protected method

protected SetSyncVarGameObject ( GameObject newGameObject, GameObject &gameObjectField, ulong dirtyBit, uint &netIdField ) : void
newGameObject GameObject
gameObjectField GameObject
dirtyBit ulong
netIdField uint
return void

SetSyncVarNetworkBehaviour() protected method

protected SetSyncVarNetworkBehaviour ( newBehaviour, &behaviourField, ulong dirtyBit, NetworkBehaviourSyncVar &syncField ) : void
dirtyBit ulong
syncField NetworkBehaviourSyncVar
return void

SetSyncVarNetworkIdentity() protected method

protected SetSyncVarNetworkIdentity ( NetworkIdentity newIdentity, NetworkIdentity &identityField, ulong dirtyBit, uint &netIdField ) : void
newIdentity NetworkIdentity
identityField NetworkIdentity
dirtyBit ulong
netIdField uint
return void

SyncVarEqual() protected method

protected SyncVarEqual ( value, &fieldValue ) : bool
return bool

SyncVarGameObjectEqual() protected method

protected SyncVarGameObjectEqual ( GameObject newGameObject, uint netIdField ) : bool
newGameObject GameObject
netIdField uint
return bool

SyncVarNetworkBehaviourEqual() protected method

protected SyncVarNetworkBehaviourEqual ( newBehaviour, NetworkBehaviourSyncVar syncField ) : bool
syncField NetworkBehaviourSyncVar
return bool

SyncVarNetworkIdentityEqual() protected method

protected SyncVarNetworkIdentityEqual ( NetworkIdentity newIdentity, uint netIdField ) : bool
newIdentity NetworkIdentity
netIdField uint
return bool

getSyncVarHookGuard() protected method

protected getSyncVarHookGuard ( ulong dirtyBit ) : bool
dirtyBit ulong
return bool

setSyncVarHookGuard() protected method

protected setSyncVarHookGuard ( ulong dirtyBit, bool value ) : void
dirtyBit ulong
value bool
return void

Property Details

syncObjects protected_oe property

objects that can synchronize themselves, such as synclists
protected List syncObjects
return List