-
-
Notifications
You must be signed in to change notification settings - Fork 55
Usage with Unity
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)
Use GitHub Desktop or a similar tool to clone Ceras.
In your git-tool of choice, make sure you're on the 'master' branch in git and not 'v5'!
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
andImmutableCollections
).
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'
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!
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);
- 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.
// 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: