* Moved doc files to docfx folder * load csproj * doc generation * Run docfx * Add docfx * Deploy docs to mirror-networking.com * use deploy phase * deploy whole generated site * Fixed the semantic release command * Is last \ required? * show debug log * using lftp for site deploy * Testing lftp * Show current folder * try -e command option * Show me the files * use plain ftp * use choco install instead of cinst * fix ssl certificate validation * fix username * Upload site to xmldocs folder * no need to archive docs * No need for debug output * Fix file permissions * show me .htaccess * Show me contents * Wipe out folder to fix permissions * Set file permissions * Fix file permissions * complete toc list * Migrated intro page * Remove old docs * Update link to docs * Add link to github * Only update docs for stuff in master * This is a powershell command * Update doc/articles/Concepts/Communications/RemoteActions.md * Update doc/articles/Concepts/VisibilityCustom.md * Update doc/articles/Concepts/Authority.md * Update doc/articles/Concepts/GameObjects/SpawnObjectCustom.md * Update doc/articles/Concepts/Authority.md * Update doc/articles/Classes/SyncVars.md * No need to run semver twice
1.6 KiB
SyncEvent
This is an attribute that can be put on events in NetworkBehaviour classes to allow them to be invoked on client when the event is called on the server.
SyncEvent events are called by user code on the server, and then invoked on corresponding client objects on clients connected to the server. The arguments to the Event call are serialized across the network, so that the client event is invoked with the same values as the method on the server. These events must begin with the prefix "Event".
using UnityEngine;
using Mirror;
public class DamageClass : NetworkBehaviour
{
public delegate void TakeDamageDelegate(int amount, float dir);
[SyncEvent]
public event TakeDamageDelegate EventTakeDamage;
[Command]
public void CmdDoMe(int val)
{
EventTakeDamage(val, 1.0f);
}
}
public class Other : NetworkBehaviour
{
public DamageClass damager;
int health = 100;
void Start()
{
if (NetworkClient.active)
damager.EventTakeDamage += TakeDamage;
}
public void TakeDamage(int amount, float dir)
{
health -= amount;
}
}
SyncEvents allow networked actions to be propagated to other scripts attached to the object. In the example above, the Other class registers for the TakeDamage event on the DamageClass. When the event happens on the DamageClass on the server, the TakeDamage() method will be invoked on the Other class on the client object. This allows modular network aware systems to be created, that can be extended by new scripts that respond to the events generated by them.