Class NetworkManager
Provides API access to static network methods.
Inheritance
Implements
Namespace: SuperNet.Unity.Core
Assembly: cs.temp.dll.dll
Syntax
public class NetworkManager : MonoBehaviour, MonoBehaviour
Properties
DuplicateTimeout
How long in milliseconds to keep received messages for to check for duplicates.
Declaration
public static int DuplicateTimeout { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
LogEvents
Should events be logged to the debug console.
Declaration
public static bool LogEvents { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
LogExceptions
Should exceptions be logged to the debug console.
Declaration
public static bool LogExceptions { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
TTL
Maximum number of hops each message can take before it is dropped.
Declaration
public static byte TTL { get; set; }
Property Value
Type | Description |
---|---|
System.Byte |
Methods
FindComponent(NetworkIdentity)
Find a registered component if it exists.
Declaration
public static NetworkComponent FindComponent(NetworkIdentity registerID)
Parameters
Type | Name | Description |
---|---|---|
NetworkIdentity | registerID | Network ID to check for. |
Returns
Type | Description |
---|---|
NetworkComponent | Registered component or null if not found. |
GetComponents()
Return all registered components.
Declaration
public static IReadOnlyList<NetworkComponent> GetComponents()
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<NetworkComponent> | All registered components. |
GetMainThread()
Get main unity thread.
Declaration
public static Thread GetMainThread()
Returns
Type | Description |
---|---|
Thread | Main unity thread. |
GetPeers()
Return all registered peers.
Declaration
public static IReadOnlyList<Peer> GetPeers()
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<Peer> | All registered peers. |
Initialize()
Initialize network manager.
Declaration
public static void Initialize()
IsRegistered(Peer)
Check if peer is registered.
Declaration
public static bool IsRegistered(Peer peer)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if registered, false if not. |
IsRegistered(NetworkIdentity)
Check if a network ID is registered.
Declaration
public static bool IsRegistered(NetworkIdentity registerID)
Parameters
Type | Name | Description |
---|---|---|
NetworkIdentity | registerID | Network ID to check for. |
Returns
Type | Description |
---|---|
System.Boolean | True if registered, false if not. |
Receive(Peer, Reader, MessageReceived)
Receive and process a component message.
Declaration
public static void Receive(Peer peer, Reader reader, MessageReceived info)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer message was received from. |
Reader | reader | Message itself. |
MessageReceived | info | Message information. |
Register(Peer)
Register a peer to be used for sending and receiving component messages.
Declaration
public static void Register(Peer peer)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer to register. |
Register(NetworkComponent)
Register a component to be able to start sending and receiving messages.
Declaration
public static NetworkIdentity Register(NetworkComponent component)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Component to register. |
Returns
Type | Description |
---|---|
NetworkIdentity | Registered network ID. |
Register(NetworkComponent, NetworkIdentity)
Register a component to be able to start sending and receiving messages.
Declaration
public static NetworkIdentity Register(NetworkComponent component, NetworkIdentity registerID)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Component to register. |
NetworkIdentity | registerID | Network ID to assign. |
Returns
Type | Description |
---|---|
NetworkIdentity | Registered network ID. |
RollbackBegin(HostTimestamp, Peer, Boolean, Boolean)
Update the state of all components to be the same as in the past.
Declaration
public static void RollbackBegin(HostTimestamp time, Peer peer, bool persist = false, bool includeDisabled = false)
Parameters
Type | Name | Description |
---|---|---|
HostTimestamp | time | Which timestamp in the past to rollback to. |
Peer | peer | Peer that we're performing the rollback for. |
System.Boolean | persist | If true, persist this rollback across multiple frames. |
System.Boolean | includeDisabled | If true, include disabled components. |
RollbackBegin(IEnumerable<NetworkComponent>, HostTimestamp, Peer, Boolean, Boolean)
Update the state of all provided components to be the same as in the past.
Declaration
public static void RollbackBegin(IEnumerable<NetworkComponent> components, HostTimestamp time, Peer peer, bool persist = false, bool includeDisabled = false)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<NetworkComponent> | components | Components to update. |
HostTimestamp | time | Which timestamp in the past to rollback to. |
Peer | peer | Peer that we're performing the rollback for. |
System.Boolean | persist | If true, persist this rollback across multiple frames. |
System.Boolean | includeDisabled | If true, include disabled components. |
RollbackEnd()
Revert all rollbacks.
Declaration
public static void RollbackEnd()
RollbackEnd(IEnumerable<NetworkComponent>)
Revert any rollbacks.
Declaration
public static void RollbackEnd(IEnumerable<NetworkComponent> components)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<NetworkComponent> | components | Components to revert for. |
Run(Action)
Queue action to be ran on the main unity thread.
Declaration
public static 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 static void Run(Action action, float seconds)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to run. |
System.Single | seconds | Delay in seconds. |
Run(IEnumerator)
Queue a coroutine to be ran on the main unity thread.
Declaration
public static Coroutine Run(IEnumerator routine)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerator | routine | Routine to run. |
Returns
Type | Description |
---|---|
Coroutine | The created coroutine. |
RunAsync(Action)
Queue action to be ran on a separate thread.
Declaration
public static void RunAsync(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to run. |
RunAsync(Action, CancellationToken)
Queue action to be ran on a separate thread.
Declaration
public static void RunAsync(Action action, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to run. |
CancellationToken | token | Cancellation token to use. |
RunAsync(Func<Task>, CancellationToken, Int32)
Queue task to be ran on a separate thread after a delay.
Declaration
public static void RunAsync(Func<Task> action, CancellationToken token, int millisecondsDelay = 0)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | action | Task to run. |
CancellationToken | token | Cancellation token to use. |
System.Int32 | millisecondsDelay | Delay in milliseconds. |
RunAsync(Func<Task>, Int32)
Queue task to be ran on a separate thread after a delay.
Declaration
public static void RunAsync(Func<Task> action, int millisecondsDelay = 0)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | action | Task to run. |
System.Int32 | millisecondsDelay | Delay in milliseconds. |
Send(NetworkComponent, IMessage)
Send a component message to all registered peers.
Declaration
public static void Send(NetworkComponent component, IMessage message)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Registered component to send through. |
IMessage | message | Message to send. |
Send(NetworkComponent, IMessage, Predicate<Peer>)
Send a component message to all registered peers.
Declaration
public static void Send(NetworkComponent component, IMessage message, Predicate<Peer> filter)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Registered component to send through. |
IMessage | message | Message to send. |
Predicate<Peer> | filter | Predicate to filter peers. |
Send(NetworkComponent, IMessage, Peer[])
Send a component message to specific peers.
Declaration
public static void Send(NetworkComponent component, IMessage message, params Peer[] peers)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Registered component to send through. |
IMessage | message | Message to send. |
Peer[] | peers | Peers to send to. |
Send(NetworkComponent, IMessage, IEnumerable<Peer>)
Send a component message to specific peers.
Declaration
public static void Send(NetworkComponent component, IMessage message, IEnumerable<Peer> peers)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Registered component to send through. |
IMessage | message | Message to send. |
System.Collections.Generic.IEnumerable<Peer> | peers | Peers to send to. |
Unregister(Peer)
Unregister a peer to stop being used for sending component messages.
Declaration
public static void Unregister(Peer peer)
Parameters
Type | Name | Description |
---|---|---|
Peer | peer | Peer to unregister. |
Unregister(NetworkComponent)
Unregister a component and make it stop receiving messages.
Declaration
public static void Unregister(NetworkComponent component)
Parameters
Type | Name | Description |
---|---|---|
NetworkComponent | component | Component to unregister. |