Skip to content

Usage with Unity

Rikimaru edited this page Aug 9, 2019 · 4 revisions

To use Ceras in Unity you should always use the source code version. The easiest and most comfortable way to get the code is by using Git (also makes updating very easy)

1. Clone Ceras repo from GitHub

Use GitHub Desktop or a similar tool to clone Ceras.

2. Switch to 'master'

In your git-tool of choice, make sure you're on the 'master' branch in git and not 'v5'!

3. Copy folders

Navigate to Ceras/src/ and copy the following folders:

  • Ceras
  • Ceras.AotGenerator (only needed when using IL2CPP / AoT)
  • Ceras.UnityAddon
  • Leave the other two (AotGeneratorApp and ImmutableCollections).

Copy those folders into a Plugins folder in your Unity Project. You can also put them into a subfolder (so 'Plugins/CerasSerializer/' for example) if you want to to keep things more clean (which is what I do). The complete path to one file (lets just take the Ceras.csproj file as an example) will look like this: 'Assets/Plugins/CerasSerializer/Ceras/Ceras.csproj'

4. Delete previous compilations

If you ran any of the Ceras projects from within VisualStudio in the past, then your project folders (Ceras, Ceras.AotGenerator, ...) will contain /bin/ and /obj/ folders, which you should delete!

5. Use Unity Formatters

In order to use formatters for unity (from the UnityAddon) for types like Vector3 and so on, just add the following in your code:

  var config = new SerializerConfig();
  CerasUnityFormatters.ApplyToConfig(config); // Formatters from the UnityExtension for Vector3 etc...
  var ceras = new CerasSerializer(config);

6. Find 'EditorExtension.cs'.

  • If you don't use IL2CPP: delete the EditorExtension.cs file.
  • If you use IL2CPP the default path where the AotGenerator will save its source-code is Assets/Scripts/CerasAotFormattersGenerated.cs, but most people prefer to change this location.

IL2CPP

// Also add this line when creating your SerializerConfig if you use IL2CPP
GeneratedFormatters.UseFormatters(config);

In AoT scenarios (Unity IL2CPP for example) Ceras can not generate any dynamic code. But there's special support for this with a guide on it here: