C# Class Mirror.NetworkBehaviour

Inheritance: MonoBehaviour
Afficher le fichier Open project: BatteryAcid/unity-custom-gamelift-server Class Usage Examples

Protected Properties

Свойство Type Description
syncObjects List

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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

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

Method Details

ClearAllDirtyBits() public méthode

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
Résultat void

DeserializeSyncVars() protected méthode

protected DeserializeSyncVars ( Mirror.NetworkReader reader, bool initialState ) : void
reader Mirror.NetworkReader
initialState bool
Résultat void

GetSyncVarGameObject() protected méthode

protected GetSyncVarGameObject ( uint netId, GameObject &gameObjectField ) : GameObject
netId uint
gameObjectField GameObject
Résultat GameObject

GetSyncVarNetworkBehaviour() protected méthode

protected GetSyncVarNetworkBehaviour ( NetworkBehaviourSyncVar syncNetBehaviour, &behaviourField ) : T
syncNetBehaviour NetworkBehaviourSyncVar
Résultat T

GetSyncVarNetworkIdentity() protected méthode

protected GetSyncVarNetworkIdentity ( uint netId, Mirror.NetworkIdentity &identityField ) : Mirror.NetworkIdentity
netId uint
identityField Mirror.NetworkIdentity
Résultat Mirror.NetworkIdentity

InitSyncObject() protected méthode

protected InitSyncObject ( Mirror.SyncObject syncObject ) : void
syncObject Mirror.SyncObject
Résultat void

IsDirty() public méthode

public IsDirty ( ) : bool
Résultat bool

OnDeserialize() public méthode

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.
Résultat void

OnSerialize() public méthode

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.
Résultat bool

OnStartAuthority() public méthode

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
Résultat void

OnStartClient() public méthode

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
Résultat void

OnStartLocalPlayer() public méthode

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
Résultat void

OnStartServer() public méthode

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
Résultat void

OnStopAuthority() public méthode

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
Résultat void

OnStopClient() public méthode

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
Résultat void

OnStopServer() public méthode

Invoked on the server when the object is unspawned

Useful for saving object data in persistent storage

public OnStopServer ( ) : void
Résultat void

SendCommandInternal() protected méthode

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

SendRPCInternal() protected méthode

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

SendTargetRPCInternal() protected méthode

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

SerializeObjectsAll() public méthode

public SerializeObjectsAll ( NetworkWriter writer ) : bool
writer NetworkWriter
Résultat bool

SerializeObjectsDelta() public méthode

public SerializeObjectsDelta ( NetworkWriter writer ) : bool
writer NetworkWriter
Résultat bool

SerializeSyncVars() protected méthode

protected SerializeSyncVars ( NetworkWriter writer, bool initialState ) : bool
writer NetworkWriter
initialState bool
Résultat bool

SetDirtyBit() public méthode

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.
Résultat void

SetSyncVar() protected méthode

protected SetSyncVar ( value, &fieldValue, ulong dirtyBit ) : void
dirtyBit ulong
Résultat void

SetSyncVarGameObject() protected méthode

protected SetSyncVarGameObject ( GameObject newGameObject, GameObject &gameObjectField, ulong dirtyBit, uint &netIdField ) : void
newGameObject GameObject
gameObjectField GameObject
dirtyBit ulong
netIdField uint
Résultat void

SetSyncVarNetworkBehaviour() protected méthode

protected SetSyncVarNetworkBehaviour ( newBehaviour, &behaviourField, ulong dirtyBit, NetworkBehaviourSyncVar &syncField ) : void
dirtyBit ulong
syncField NetworkBehaviourSyncVar
Résultat void

SetSyncVarNetworkIdentity() protected méthode

protected SetSyncVarNetworkIdentity ( NetworkIdentity newIdentity, NetworkIdentity &identityField, ulong dirtyBit, uint &netIdField ) : void
newIdentity NetworkIdentity
identityField NetworkIdentity
dirtyBit ulong
netIdField uint
Résultat void

SyncVarEqual() protected méthode

protected SyncVarEqual ( value, &fieldValue ) : bool
Résultat bool

SyncVarGameObjectEqual() protected méthode

protected SyncVarGameObjectEqual ( GameObject newGameObject, uint netIdField ) : bool
newGameObject GameObject
netIdField uint
Résultat bool

SyncVarNetworkBehaviourEqual() protected méthode

protected SyncVarNetworkBehaviourEqual ( newBehaviour, NetworkBehaviourSyncVar syncField ) : bool
syncField NetworkBehaviourSyncVar
Résultat bool

SyncVarNetworkIdentityEqual() protected méthode

protected SyncVarNetworkIdentityEqual ( NetworkIdentity newIdentity, uint netIdField ) : bool
newIdentity NetworkIdentity
netIdField uint
Résultat bool

getSyncVarHookGuard() protected méthode

protected getSyncVarHookGuard ( ulong dirtyBit ) : bool
dirtyBit ulong
Résultat bool

setSyncVarHookGuard() protected méthode

protected setSyncVarHookGuard ( ulong dirtyBit, bool value ) : void
dirtyBit ulong
value bool
Résultat void

Property Details

syncObjects protected_oe property

objects that can synchronize themselves, such as synclists
protected List syncObjects
Résultat List