Table of Contents
Contains serialization surrogates for Unity's structs.
The provided surrogates provide serialization and deserialization of the following types:
- Color
- Quaternion
- Vector2
- Vector2Int
- Vector3
- Vector3Int
- Vector4
Download any version from releases.
Alternatively, you can add this package by opening the PackageManager,
going to the Add package from git URL
option, and entering:
https://github.com/Depression-aggression/Serialization.Unity.Surrogates.git
Serialization:
using (var memoryStream = new MemoryStream())
{
// Setup Unity's structs serialization surrogates.
var surrogateSelector = new SurrogateSelector();
surrogateSelector.AddAllUnitySurrogates();
var binaryFormatter = new BinaryFormatter { SurrogateSelector = surrogateSelector };
// Serialize and put to packet.
binaryFormatter.Serialize(memoryStream, data);
memoryStream.Flush();
memoryStream.Seek(0, SeekOrigin.Begin);
var bytes = memoryStream.ToArray();
}
Deserialization:
using (var memoryStream = new MemoryStream(bytes))
{
// Setup Unity's structs serialization surrogates.
var surrogateSelector = new SurrogateSelector();
surrogateSelector.AddAllUnitySurrogates();
var binaryFormatter = new BinaryFormatter { SurrogateSelector = surrogateSelector };
// Deserialize.
var data = binaryFormatter.Deserialize(memoryStream);
}
I welcome feature requests and bug reports in issues section, as well as pull requests.
I am an independent developer, and most of the development on this project is done in my spare time. If you're interested in collaboration or hiring me for a project, please check out my portfolio and reach out!
This project is licensed under the Apache-2.0 license.
Copyright (c) 2023 Nikolay Melnikov g0dzZz1lla@yandex.ru