Class MPApi
The primary static class that contains methods used to interface with the multiplayer mod.
Namespace: UnofficialMultiplayerAPI
Assembly: 0UnofficialMultiplayerAPI.dll
Syntax
[StaticConstructorOnStartup]
public static class MPApi
Fields
enabled
Declaration
public static readonly bool enabled
Field Value
| Type | Description |
|---|---|
| Boolean | Returns true if API is initialized. |
Properties
IsHosting
Declaration
public static bool IsHosting { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | Returns true if currently running on a host. |
IsInMultiplayer
Declaration
public static bool IsInMultiplayer { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | Returns true if currently running in a multiplayer session (both on client and host). |
PlayerName
Declaration
public static string PlayerName { get; }
Property Value
| Type | Description |
|---|---|
| String | Returns local player's name. |
Methods
FieldWatchPostfix()
Ends the current synchronization stack and executes it.
Declaration
public static void FieldWatchPostfix()
Remarks
Has to be called after invoking Watch methods.
See also Watch(Object, Object).
FieldWatchPrefix()
Starts a new synchronization stack.
Declaration
public static void FieldWatchPrefix()
Remarks
Has to be called before invoking Watch methods.
See also Watch(Object, Object).
RegisterSyncMethod(MethodInfo, SyncType[])
Registers a method for syncing and returns its ISyncMethod.
Declaration
public static ISyncMethod RegisterSyncMethod(MethodInfo method, SyncType[] argTypes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| MethodInfo | method | MethodInfo of a method to register |
| UnofficialMultiplayerAPI.SyncType[] | argTypes | Method's parameter types |
Returns
| Type | Description |
|---|---|
| ISyncMethod | A new registered ISyncMethod |
Remarks
Has to be called inside of IMultiplayerInit.Init().
It's recommended to use SyncMethodAttribute instead, unless you have to otherwise.
Examples
Register a method for syncing using reflection and set it to debug only.
RegisterSyncMethod(typeof(MyType).GetMethod(nameof(MyType.MyMethod))).SetDebugOnly();
RegisterSyncMethod(Type, String, SyncType[])
Registers a method for syncing and returns its ISyncMethod.
Declaration
public static ISyncMethod RegisterSyncMethod(Type type, string methodOrPropertyName, SyncType[] argTypes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | Type that contains the method |
| String | methodOrPropertyName | Name of the method |
| UnofficialMultiplayerAPI.SyncType[] | argTypes | Method's parameter types |
Returns
| Type | Description |
|---|---|
| ISyncMethod | A new registered ISyncMethod |
Remarks
Has to be called inside of IMultiplayerInit.Init().
It's recommended to use SyncMethodAttribute instead, unless you have to otherwise.
SyncField(Type, String)
Registers a field for syncing and returns it's ISyncField.
Declaration
public static ISyncField SyncField(Type targetType, string memberPath)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | targetType | Type of the target class that contains the specified member if null, |
| String | memberPath | Path to a member. If the member is to be indexed, it has to end with /[] eg. |
Returns
| Type | Description |
|---|---|
| ISyncField | A new registered ISyncField |
Remarks
Has to be called inside of IMultiplayerInit.Init().
Watch(ISyncField, Object, Object)
An alias for Watch(Object, Object).
Declaration
public static void Watch(ISyncField field, object target = null, object index = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ISyncField | field | ISyncField object to watch |
| Object | target | An object of type set in the ISyncField. Set to null if you're watching a static field. |
| Object | index | Index in the field path set in ISyncField |