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
///
/// 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 override void OnStartServer() { }
///
/// 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 override void OnStartClient() { }
///
/// 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 override void OnStartLocalPlayer() { }
///
/// This is invoked on behaviours that have authority, based on context and NetworkIdentity.hasAuthority.
/// This is called after OnStartServer and OnStartClient.
/// When 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 override void OnStartAuthority() { }
///
/// 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 override void OnStopAuthority() { }
#endregion
#region Observers
///
/// Callback used by the visibility system to (re)construct the set of observers that can see this object.
/// Implementations of this callback should add network connections of players that can see this object to the observers set.
///
/// The new set of observers for this object.
/// True if the set of observers is being built for the first time.
/// true when overwriting so that Mirror knows that we wanted to rebuild observers ourselves. otherwise it uses built in rebuild.
public override bool OnRebuildObservers(HashSet observers, bool initialize)
{
return base.OnRebuildObservers(observers, initialize);
}
///
/// Callback used by the visibility system for objects on a host.
/// 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.
///
/// New visibility state.
public override void OnSetHostVisibility(bool visible) { }
///
/// Callback used by the visibility system to determine if an observer (player) can see this object.
/// If this function returns true, the network connection will be added as an observer.
///
/// Network connection of a player.
/// True if the player can see this object.
public override bool OnCheckObserver(NetworkConnection conn)
{
return base.OnCheckObserver(conn);
}
#endregion
#region Serialization
///
/// 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.
///
/// Writer to use to write to the stream.
/// If this is being called to send initial state.
/// True if data was written.
public override bool OnSerialize(NetworkWriter writer, bool initialState)
{
return base.OnSerialize(writer, initialState);
}
///
/// Virtual function to override to receive custom serialization data. The corresponding function to send serialization data is OnSerialize().
///
/// Reader to read from the stream.
/// True if being sent initial state.
public override void OnDeserialize(NetworkReader reader, bool initialState)
{
base.OnDeserialize(reader, initialState);
}
#endregion
}