diff --git a/doc/articles/Classes/SyncHashSet.md b/doc/articles/Classes/SyncHashSet.md index 4fbce0875..c9513fc16 100644 --- a/doc/articles/Classes/SyncHashSet.md +++ b/doc/articles/Classes/SyncHashSet.md @@ -2,17 +2,7 @@ `SyncHashSet` are sets similar to C\# [HashSet\](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 diff --git a/doc/articles/Classes/SyncLists.md b/doc/articles/Classes/SyncLists.md index 6dbc5f044..014e82bd3 100644 --- a/doc/articles/Classes/SyncLists.md +++ b/doc/articles/Classes/SyncLists.md @@ -2,17 +2,7 @@ SyncLists are array based lists similar to C\# [List\](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 diff --git a/doc/articles/Classes/SyncSortedSet.md b/doc/articles/Classes/SyncSortedSet.md index fd270a209..b9d61ad30 100644 --- a/doc/articles/Classes/SyncSortedSet.md +++ b/doc/articles/Classes/SyncSortedSet.md @@ -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 diff --git a/doc/articles/Classes/SyncVars.md b/doc/articles/Classes/SyncVars.md index ac373f256..315031699 100644 --- a/doc/articles/Classes/SyncVars.md +++ b/doc/articles/Classes/SyncVars.md @@ -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. diff --git a/doc/articles/Concepts/Communications/NetworkMessages.md b/doc/articles/Concepts/Communications/NetworkMessages.md index 6a57d1fbe..902ca584b 100644 --- a/doc/articles/Concepts/Communications/NetworkMessages.md +++ b/doc/articles/Concepts/Communications/NetworkMessages.md @@ -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: diff --git a/doc/articles/Concepts/Communications/RemoteActions.md b/doc/articles/Concepts/Communications/RemoteActions.md index 1acaa200e..647158139 100644 --- a/doc/articles/Concepts/Communications/RemoteActions.md +++ b/doc/articles/Concepts/Communications/RemoteActions.md @@ -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. diff --git a/doc/articles/Concepts/DataTypes.md b/doc/articles/Concepts/DataTypes.md new file mode 100644 index 000000000..bad4532af --- /dev/null +++ b/doc/articles/Concepts/DataTypes.md @@ -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` \ No newline at end of file diff --git a/doc/articles/Concepts/toc.yml b/doc/articles/Concepts/toc.yml index 1da5854a3..4bfcaaa22 100644 --- a/doc/articles/Concepts/toc.yml +++ b/doc/articles/Concepts/toc.yml @@ -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