Class NetworkComponent
Base class for synchronized network components.
Inheritance
Namespace: SuperNet.Unity.Core
Assembly: cs.temp.dll.dll
Syntax
public abstract class NetworkComponent : MonoBehaviour
Properties
IsRegisteredOnNetwork
True if this component is registered on the network.
Declaration
public bool IsRegisteredOnNetwork { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
NetworkID
Registered network ID or serialized ID if not registered.
Declaration
public NetworkIdentity NetworkID { get; }
Property Value
Type | Description |
---|---|
NetworkIdentity |
Methods
GetNetworkPeers()
Return all registered peers.
Declaration
public IReadOnlyList<Peer> GetNetworkPeers()
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<Peer> | All registered peers. |
OnDestroy()
Automatically unregisters the component. Do not override.
Declaration
protected virtual void OnDestroy()
OnNetworkConnect(Peer)
Called when any peer connects to the network.
Declaration
public virtual void OnNetworkConnect(Peer peer)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer that connected. |
OnNetworkDisconnect(Peer)
Called when any peer disconnects from the network.
Declaration
public virtual void OnNetworkDisconnect(Peer peer)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer that disconnected. |
OnNetworkMessage(Peer, Reader, MessageReceived)
Called when a message is received from a peer.
Declaration
public virtual void OnNetworkMessage(Peer peer, Reader reader, MessageReceived info)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer that received the message. |
Reader | reader | Message received. |
MessageReceived | info | Message information. |
OnNetworkRegister()
Called when this component is registered locally.
Declaration
public virtual void OnNetworkRegister()
OnNetworkRegister(NetworkComponent)
Called when any component is registered locally.
Declaration
public virtual void OnNetworkRegister(NetworkComponent component)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Registered component. |
OnNetworkResend(Peer, Peer, Reader, MessageReceived)
Called when a received message is about to be resent to a peer.
Declaration
public virtual bool OnNetworkResend(Peer origin, Peer peer, Reader reader, MessageReceived info)
Parameters
Type | Name | Description |
---|---|---|
Peer | origin | Original sender of the message. |
Peer | peer | Peer message is being resent to. |
Reader | reader | Message being resent. |
MessageReceived | info | Message information. |
Returns
Type | Description |
---|---|
System.Boolean | True to resend, false to block resending. |
OnNetworkUnregister()
Called when this component is unregistered locally.
Declaration
public virtual void OnNetworkUnregister()
OnNetworkUnregister(NetworkComponent)
Called when any component is unregistered locally.
Declaration
public virtual void OnNetworkUnregister(NetworkComponent component)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Unregistered component. |
ResetNetworkID()
Reset serialized network ID to default. Editor only.
Declaration
protected void ResetNetworkID()
Run(Action)
Queue action to be ran on the main unity thread.
Declaration
public void Run(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to run. |
Run(Action, Single)
Queue action to be ran on the main unity thread after a delay.
Declaration
public void Run(Action action, float seconds)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to run. |
System.Single | seconds | Delay in seconds. |
RunAsync(Action)
Queue action to be ran on a separate thread.
Declaration
public void RunAsync(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to run. |
SendNetworkMessage(IMessage)
Send a component message to all registered peers.
Declaration
public void SendNetworkMessage(IMessage message)
Parameters
Type | Name | Description |
---|---|---|
IMessage | message | Message to send. |
SendNetworkMessage(IMessage, Predicate<Peer>)
Send a component message to all registered peers.
Declaration
public void SendNetworkMessage(IMessage message, Predicate<Peer> filter)
Parameters
Type | Name | Description |
---|---|---|
IMessage | message | Message to send. |
Predicate<Peer> | filter | Predicate to filter peers. |
SendNetworkMessage(IMessage, Peer[])
Send a component message to specific peers.
Declaration
public void SendNetworkMessage(IMessage message, params Peer[] peers)
Parameters
Type | Name | Description |
---|---|---|
IMessage | message | Message to send. |
Peer[] | peers | Peers to send to. |
SendNetworkMessage(IMessage, IEnumerable<Peer>)
Send a component message to specific peers.
Declaration
public void SendNetworkMessage(IMessage message, IEnumerable<Peer> peers)
Parameters
Type | Name | Description |
---|---|---|
IMessage | message | Message to send. |
System.Collections.Generic.IEnumerable<Peer> | peers | Peers to send to. |
Start()
Automatically registers the component. Do not override.
Declaration
protected virtual void Start()