Custom Serializers
Custom serializers are useful where an automatic serializer may not be possible, or where you want data to be serialized in a specific manner.
When creating a custom serializer there are a few important things to remember. When you follow the proper steps your custom serializer will be found and used by Fish-Networking. Your custom serializers can also override automatic serializers, but not included ones.
Your method must be static, and within a static class.
Writing method names must begin with Write.
Reading method names must begin with Read.
The first parameter must be this Writer for writers, and this Reader for readers.
Data must be read in the same order it is written.
Although Vector2 is already supported, the example below uses a Vector2 for simplicity sake.
Custom serializers are more commonly used for conditional situations where what you write may change depending on the data values. Here is a more complex example where certain data is only written when it's needed.
Often when creating a custom serializer you want to use it across your entire project, and all assemblies. Without taking any action further your custom serializer would only be used on the assembly it is written. Presumably, that's probably not what you want.
But making a custom serializer work across all assemblies is very simple. Simply add the [UseGlobalCustomSerializer] attribute of the type your custom serializer is for, and done!
Example:
Last updated