mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
document mirror data types (#1059)
* document mirror data types * Fix syncvar docs * Update doc/articles/Concepts/Communications/RemoteActions.md Co-Authored-By: MrGadget <chris@clevertech.net> * Update doc/articles/Concepts/Communications/NetworkMessages.md Co-Authored-By: MrGadget <chris@clevertech.net> * Update doc/articles/Classes/SyncLists.md Co-Authored-By: MrGadget <chris@clevertech.net>
This commit is contained in:
parent
c84c3892bc
commit
fc0e6f3abb
@ -2,17 +2,7 @@
|
||||
|
||||
`SyncHashSet` are sets similar to C\# [HashSet\<T\>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1) that synchronize their contents from the server to the clients.
|
||||
|
||||
A SyncHashSet can contain items of the following types:
|
||||
|
||||
- Basic type (byte, int, float, string, UInt64, etc)
|
||||
|
||||
- Built-in Unity math type (Vector3, Quaternion, etc)
|
||||
|
||||
- NetworkIdentity
|
||||
|
||||
- Game object with a NetworkIdentity component attached.
|
||||
|
||||
- Structure with any of the above
|
||||
A SyncHashSet can contain any [supported mirror type](../Concepts/DataTypes.md)
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -2,17 +2,7 @@
|
||||
|
||||
SyncLists are array based lists similar to C\# [List\<T\>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=netframework-4.7.2) that synchronize their contents from the server to the clients.
|
||||
|
||||
A SyncList can contain items of the following types:
|
||||
|
||||
- Basic type (byte, int, float, string, UInt64, etc)
|
||||
|
||||
- Built-in Unity math type (Vector3, Quaternion, etc)
|
||||
|
||||
- NetworkIdentity
|
||||
|
||||
- Game object with a NetworkIdentity component attached.
|
||||
|
||||
- Structure with any of the above
|
||||
A SyncList can contain any [supported mirror type](../Concepts/DataTypes.md).
|
||||
|
||||
## Differences with HLAPI
|
||||
|
||||
|
@ -4,17 +4,7 @@
|
||||
|
||||
Unlike SyncHashSets, all elements in a SyncSortedSet are sorted when they are inserted. Please note this has some performance implications.
|
||||
|
||||
A SyncSortedSet can contain items of the following types:
|
||||
|
||||
- Basic type (byte, int, float, string, UInt64, etc)
|
||||
|
||||
- Built-in Unity math type (Vector3, Quaternion, etc)
|
||||
|
||||
- NetworkIdentity
|
||||
|
||||
- Game object with a NetworkIdentity component attached.
|
||||
|
||||
- Structure with any of the above
|
||||
A SyncSortedSet can contain any [supported mirror type](../Concepts/DataTypes.md)
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -20,7 +20,7 @@ class Player : NetworkBehaviour
|
||||
|
||||
The state of SyncVars is applied to game objects on clients before `OnStartClient()` is called, so the state of the object is always up-to-date inside `OnStartClient()`.
|
||||
|
||||
SyncVars can be basic types such as integers, strings and floats. They can also be Unity types such as Vector3 and user-defined structs, but updates for struct SyncVars are sent as monolithic updates, not incremental changes of fields within a struct change. You can have up to 32 SyncVars on a single NetworkBehaviour script, including SyncLists (see next section, below).
|
||||
SyncVars can use any [type supported by Mirror](../Concepts/DataTypes.md). You can have up to 32 SyncVars on a single NetworkBehaviour script, including SyncLists (see next section, below).
|
||||
|
||||
The server automatically sends SyncVar updates when the value of a SyncVar changes, so you do not need to track when they change or send information about the changes yourself.
|
||||
|
||||
|
@ -17,7 +17,7 @@ public abstract class MessageBase
|
||||
}
|
||||
```
|
||||
|
||||
The auto generated Serialize/Deserialize can efficiently deal with basic types, structs, arrays and common Unity value types such as Color, Vector3, Quaternion. Make your members public. If you need class members or complex containers such as List and Dictionary, you must implement the Serialize and Deserialize methods yourself.
|
||||
The auto generated Serialize/Deserialize can efficiently deal any [supported mirror type](../DataTypes.md) . Make your members public. If you need class members or complex containers such as List and Dictionary, you must implement the Serialize and Deserialize methods yourself.
|
||||
|
||||
To send a message, use the `Send()` method on the NetworkClient, NetworkServer, and NetworkConnection classes which work the same way. It takes a message object that is derived from MessageBase. The code below demonstrates how to send and handle a message:
|
||||
|
||||
|
@ -101,18 +101,6 @@ public class Player : NetworkBehaviour
|
||||
|
||||
## Arguments to Remote Actions
|
||||
|
||||
The arguments passed to commands and ClientRpc calls are serialized and sent over the network. These arguments can be:
|
||||
The arguments passed to commands and ClientRpc calls are serialized and sent over the network. You can use any [supported mirror type](../DataTypes.md).
|
||||
|
||||
- basic types (byte, int, float, string, UInt64, etc)
|
||||
|
||||
- arrays of basic types
|
||||
|
||||
- structs containing allowable types
|
||||
|
||||
- built-in unity math types (Vector3, Quaternion, etc)
|
||||
|
||||
- NetworkIdentity
|
||||
|
||||
- game object with a NetworkIdentity component attached
|
||||
|
||||
Arguments to remote actions cannot be sub-components of game objects, such as script instances or Transforms. They cannot be other types that cannot be serialized across the network.
|
||||
Arguments to remote actions cannot be sub-components of game objects, such as script instances or Transforms.
|
||||
|
44
doc/articles/Concepts/DataTypes.md
Normal file
44
doc/articles/Concepts/DataTypes.md
Normal file
@ -0,0 +1,44 @@
|
||||
# Data types
|
||||
|
||||
The client and server can pass data to each other via [Remote methods](Communications/RemoteActions.md), [State Synchronization](StateSync.md) or via [Network Messages](Communications/NetworkMessages.md)
|
||||
|
||||
Mirror supports a number of data types you can use with these, including:
|
||||
|
||||
- Basic c# types (byte, int, char, uint, float, string, UInt64, etc)
|
||||
|
||||
- Built-in Unity math type (Vector3, Quaternion, Rect, Plane, Vector3Int, etc)
|
||||
|
||||
- NetworkIdentity
|
||||
|
||||
- Game object with a NetworkIdentity component attached.
|
||||
|
||||
- Structures with any of the above
|
||||
|
||||
- Arrays of any of the above (not supported with syncvars or synclists)
|
||||
|
||||
- ArraySegments of any of the above (not supported with syncvars or synclists)
|
||||
|
||||
# Custom Data Types
|
||||
|
||||
Sometimes you don't want mirror to generate serialization for your own types. For example, instead of serializing quest data, you may want to serialize just the quest id, and the receiver can look up the quest by id in a predefined list.
|
||||
|
||||
Sometimes you may want to serialize data which uses a different type not supported by Mirror, such as DateTime or System.Uri
|
||||
|
||||
You can add support for any type by adding extension methods to `NetworkWriter` and `NetworkReader`. For example, to add support for `DateTime`, add this somewhere in your project:
|
||||
|
||||
```cs
|
||||
public static class DateTimeReaderWriter
|
||||
{
|
||||
public static void WriteDateTime(this NetworkWriter writer, DateTime dateTime)
|
||||
{
|
||||
writer.WriteInt64(dateTime.Ticks);
|
||||
}
|
||||
|
||||
public static DateTime ReadDateTime(this NetworkReader reader)
|
||||
{
|
||||
return new DateTime(reader.ReadInt64());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then you can use `DateTime` in your `[Command]` or `SyncList`
|
@ -12,6 +12,8 @@
|
||||
href: ClockSync.md
|
||||
- name: State Syncronization
|
||||
href: StateSync.md
|
||||
- name: Data Types
|
||||
href: DataTypes.md
|
||||
- name: Visibility
|
||||
href: Visibility.md
|
||||
- name: Custom Visibility
|
||||
|
Loading…
Reference in New Issue
Block a user