Skip to content

Contains serialization surrogates for Unity's structs.

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

Depra-Inc/Serialization.Unity.Surrogates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity Serialization Surrogates

Table of Contents

Introduction

Contains serialization surrogates for Unity's structs.

🦾 Features

The provided surrogates provide serialization and deserialization of the following types:

  • Color
  • Quaternion
  • Vector2
  • Vector2Int
  • Vector3
  • Vector3Int
  • Vector4

📥 Installation

Download any version from releases.

Install via git URL:

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

🔰 Usage

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);
}

🤝 Contribute

I welcome feature requests and bug reports in issues section, as well as pull requests.

🫂 Support

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!

🪪 License

This project is licensed under the Apache-2.0 license.

Copyright (c) 2023 Nikolay Melnikov g0dzZz1lla@yandex.ru