Class ColorSerializer
Type serializer for UnityEngine.Color values (32-bit RGBA with float components in the
range [0, 1]). Writes and reads the four single-precision components r, g,
b, and a as a JSON object with named properties. Unknown properties
encountered during read are silently skipped.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class ColorSerializer : TypeSerializerBase<Color>, ITypeSerializer<Color>, ITypeSerializer
Remarks
The serialized JSON format is {"r": float, "g": float, "b": float, "a": float}
with each component in the [0, 1] range. If the alpha property is absent during read,
it defaults to 1 (fully opaque). The r, g, and b components
default to 0 when absent.
For byte-based color representation, see Color32Serializer.
Use the shared Instance singleton rather than creating new instances;
ColorSerializer carries no mutable state and is safe to share across threads.
Fields
Instance
Shared, reusable singleton instance of ColorSerializer.
Prefer this over allocating a new instance wherever a ColorSerializer is needed.
Declaration
public static readonly ColorSerializer Instance
Field Value
| Type | Description |
|---|---|
| ColorSerializer |
Methods
Read(IScyllaReader, ISerializationContext)
Reads a UnityEngine.Color from the reader, populating components from a JSON object's
r, g, b, and a properties.
Declaration
public override Color Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at the start of a JSON object. Never |
| ISerializationContext | context | The active serialization context. Never |
Returns
| Type | Description |
|---|---|
| Color | The deserialized UnityEngine.Color. The |
Overrides
Write(Color, IScyllaWriter, ISerializationContext)
Writes a UnityEngine.Color to the output as a JSON object containing the
r, g, b, and a float components (each in the [0, 1] range).
Declaration
public override void Write(Color value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | value | The UnityEngine.Color to serialize. |
| IScyllaWriter | writer | The writer that receives the serialized output. Never |
| ISerializationContext | context | The active serialization context. Never |