mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
111 lines
6.6 KiB
Plaintext
111 lines
6.6 KiB
Plaintext
using UnityEngine;
|
|
using Mirror;
|
|
using System.Collections.Generic;
|
|
|
|
/*
|
|
Documentation: https://mirror-networking.com/docs/Guides/NetworkBehaviour.html
|
|
API Reference: https://mirror-networking.com/docs/api/Mirror.NetworkBehaviour.html
|
|
*/
|
|
|
|
public class #SCRIPTNAME# : NetworkBehaviour
|
|
{
|
|
#region Start & Stop Callbacks
|
|
|
|
/// <summary>
|
|
/// This is invoked for NetworkBehaviour objects when they become active on the server.
|
|
/// <para>This could be triggered by NetworkServer.Listen() for objects in the scene, or by NetworkServer.Spawn() for objects that are dynamically created.</para>
|
|
/// <para>This will be called for objects on a "host" as well as for object on a dedicated server.</para>
|
|
/// </summary>
|
|
public override void OnStartServer() { }
|
|
|
|
/// <summary>
|
|
/// Called on every NetworkBehaviour when it is activated on a client.
|
|
/// <para>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.</para>
|
|
/// </summary>
|
|
public override void OnStartClient() { }
|
|
|
|
/// <summary>
|
|
/// Called when the local player object has been set up.
|
|
/// <para>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.</para>
|
|
/// </summary>
|
|
public override void OnStartLocalPlayer() { }
|
|
|
|
/// <summary>
|
|
/// This is invoked on behaviours that have authority, based on context and <see cref="NetworkIdentity.hasAuthority">NetworkIdentity.hasAuthority</see>.
|
|
/// <para>This is called after <see cref="OnStartServer">OnStartServer</see> and before <see cref="OnStartClient">OnStartClient.</see></para>
|
|
/// <para>When <see cref="NetworkIdentity.AssignClientAuthority"/> is called on the server, this will be called on the client that owns the object. When an object is spawned with <see cref="NetworkServer.Spawn">NetworkServer.Spawn</see> with a NetworkConnection parameter included, this will be called on the client that owns the object.</para>
|
|
/// </summary>
|
|
public override void OnStartAuthority() { }
|
|
|
|
/// <summary>
|
|
/// This is invoked on behaviours when authority is removed.
|
|
/// <para>When NetworkIdentity.RemoveClientAuthority is called on the server, this will be called on the client that owns the object.</para>
|
|
/// </summary>
|
|
public override void OnStopAuthority() { }
|
|
|
|
#endregion
|
|
|
|
#region Observers
|
|
|
|
/// <summary>
|
|
/// Callback used by the visibility system to (re)construct the set of observers that can see this object.
|
|
/// <para>Implementations of this callback should add network connections of players that can see this object to the observers set.</para>
|
|
/// </summary>
|
|
/// <param name="observers">The new set of observers for this object.</param>
|
|
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
|
|
/// <returns>true when overwriting so that Mirror knows that we wanted to rebuild observers ourselves. otherwise it uses built in rebuild.</returns>
|
|
public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initialize)
|
|
{
|
|
return base.OnRebuildObservers(observers, initialize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Callback used by the visibility system for objects on a host.
|
|
/// <para>Objects on a host (with a local client) cannot be disabled or destroyed when they are not visibile to the local client. So this function is called to allow custom code to hide these objects. A typical implementation will disable renderer components on the object. This is only called on local clients on a host.</para>
|
|
/// </summary>
|
|
/// <param name="visible">New visibility state.</param>
|
|
public override void OnSetHostVisibility(bool visible) { }
|
|
|
|
/// <summary>
|
|
/// Callback used by the visibility system to determine if an observer (player) can see this object.
|
|
/// <para>If this function returns true, the network connection will be added as an observer.</para>
|
|
/// </summary>
|
|
/// <param name="conn">Network connection of a player.</param>
|
|
/// <returns>True if the player can see this object.</returns>
|
|
public override bool OnCheckObserver(NetworkConnection conn)
|
|
{
|
|
return base.OnCheckObserver(conn);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Serialization
|
|
|
|
/*
|
|
CAUTION: Overriding OnSerialize / OnDeserialize applies to all properties, including SyncVars!
|
|
You will have to manually code for everything in this class that needs to be serialized!
|
|
*/
|
|
|
|
/// <summary>
|
|
/// Virtual function to override to send custom serialization data. The corresponding function to send serialization data is OnDeserialize().
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>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.</para>
|
|
/// <para>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.</para>
|
|
/// <para>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.</para>
|
|
/// </remarks>
|
|
/// <param name="writer">Writer to use to write to the stream.</param>
|
|
/// <param name="initialState">If this is being called to send initial state.</param>
|
|
/// <returns>True if data was written.</returns>
|
|
/// public override bool OnSerialize(NetworkWriter writer, bool initialState) { }
|
|
|
|
/// <summary>
|
|
/// Virtual function to override to receive custom serialization data. The corresponding function to send serialization data is OnSerialize().
|
|
/// </summary>
|
|
/// <param name="reader">Reader to read from the stream.</param>
|
|
/// <param name="initialState">True if being sent initial state.</param>
|
|
/// public override void OnDeserialize(NetworkReader reader, bool initialState) { }
|
|
|
|
#endregion
|
|
}
|