Asset serializer implementation based on UnityEngine.JsonUtility and a set of utility methods from JsonUtilityExtensions. Can use surrogates to replace asset types with more efficient representations (RegisterSurrogate<AssetType,SurrogateType>. Additionally, any Unity-object references are serialized as null by default (NullifyUnityObjectReferences). The output can be deserialized with Newtonsoft.Json-based deserializer from Quantum.Json assembly. If this interoperability is needed, consider enabling IntegerEnquotingMinDigits to ensure that large integers are enquoted and not treated as floating points.
More...
|
virtual TextReader | CreateReader (Stream stream) |
| Creates a new instance of StreamReader with UTF8 encoding. The underlying stream is not closed. More...
|
|
virtual TextWriter | CreateWriter (Stream stream) |
| Creates a new instance of StreamWriter with UTF8 encoding. The underlying stream is not closed. More...
|
|
virtual GameObject | ResolvePrefab (AssetGuid guid) |
| Resolves the prefab associated with the provided AssetGuid by looking it up in the global DB. More...
|
|
|
int? | CompressBinaryDataOnSerializationThreshold = 1024 [get, set] |
| If set to a positive value, all uncompressed BinaryData assets with size over the value will be compressed during serialization. More...
|
|
bool | DecompressBinaryDataOnDeserialization = false [get, set] |
| If true, all BinaryData assets will be decompressed during deserialization. More...
|
|
Func< AssetGuid, GameObject > | EntityViewPrefabResolver [get, set] |
| Custom resolver for EntityView prefabs. More...
|
|
bool | EntityViewPrefabResolvingEnabled [get, set] |
| No longer used. More...
|
|
int? | IntegerEnquotingMinDigits [get, set] |
| How many digits should a number have to be enquoted. Some JSON parsers deserialize all numbers as floating points, which in case of large integers (e.g. entity ids) can lead to precision loss. If this property is set to true (default), all integers with IntegerEnquotingMinDigits or more digits are enquoted. More...
|
|
bool | NullifyUnityObjectReferences = true [get, set] |
| Should all UnityEngine.Object references be nullified in the resulting JSON? If true, all UnityEngine.Object references will be serialized as null. Otherwise, they are serialized as { "instanceId": <value> }. More...
|
|
bool | PrettyPrintEnabled [get, set] |
| No longer used. More...
|
|
Func< string, Type, Type > | TypeResolver [get, set] |
| Custom type resolver to be used during deserialization. More...
|
|
Asset serializer implementation based on UnityEngine.JsonUtility and a set of utility methods from JsonUtilityExtensions. Can use surrogates to replace asset types with more efficient representations (RegisterSurrogate<AssetType,SurrogateType>. Additionally, any Unity-object references are serialized as null by default (NullifyUnityObjectReferences).
The output can be deserialized with Newtonsoft.Json-based deserializer from Quantum.Json assembly. If this interoperability is needed, consider enabling IntegerEnquotingMinDigits to ensure that large integers are enquoted and not treated as floating points.
◆ QuantumUnityJsonSerializer()
Quantum.QuantumUnityJsonSerializer.QuantumUnityJsonSerializer |
( |
| ) |
|
|
inline |
◆ RegisterSurrogate< AssetType, SurrogateType >()
void Quantum.QuantumUnityJsonSerializer.RegisterSurrogate< AssetType, SurrogateType > |
( |
Func< AssetType, SurrogateType > |
factory | ) |
|
|
inline |
Registers a surrogate type for the provided asset type. Surrogates are types that are serialized and deserialized instead of the original asset type. By default, the serializer only provides surrogates for EntityView and BinaryData, for a more efficient serialization.
- Parameters
-
factory | Delegate to be used when an instance of a surrogate is needed. |
- Type Constraints
-
AssetType | : | AssetObject | |
SurrogateType | : | AssetObjectSurrogate | |
◆ ResolvePrefab()
virtual GameObject Quantum.QuantumUnityJsonSerializer.ResolvePrefab |
( |
AssetGuid |
guid | ) |
|
|
inlineprotectedvirtual |
Resolves the prefab associated with the provided AssetGuid by looking it up in the global DB.
- Parameters
-
guid | The AssetGuid of the prefab to be resolved. |
- Returns
- Returns the GameObject associated with the provided AssetGuid.
- Exceptions
-
InvalidOperationException | Thrown when the prefab associated with the provided AssetGuid cannot be found. |
◆ CreateReader()
virtual TextReader Quantum.QuantumUnityJsonSerializer.CreateReader |
( |
Stream |
stream | ) |
|
|
protectedvirtual |
Creates a new instance of StreamReader with UTF8 encoding. The underlying stream is not closed.
- Parameters
-
- Returns
◆ CreateWriter()
virtual TextWriter Quantum.QuantumUnityJsonSerializer.CreateWriter |
( |
Stream |
stream | ) |
|
|
protectedvirtual |
Creates a new instance of StreamWriter with UTF8 encoding. The underlying stream is not closed.
- Parameters
-
- Returns
◆ PrettyPrintEnabled
bool Quantum.QuantumUnityJsonSerializer.PrettyPrintEnabled |
|
getset |
◆ EntityViewPrefabResolvingEnabled
bool Quantum.QuantumUnityJsonSerializer.EntityViewPrefabResolvingEnabled |
|
getset |
◆ DecompressBinaryDataOnDeserialization
bool Quantum.QuantumUnityJsonSerializer.DecompressBinaryDataOnDeserialization = false |
|
getset |
If true, all BinaryData assets will be decompressed during deserialization.
◆ CompressBinaryDataOnSerializationThreshold
int? Quantum.QuantumUnityJsonSerializer.CompressBinaryDataOnSerializationThreshold = 1024 |
|
getset |
If set to a positive value, all uncompressed BinaryData assets with size over the value will be compressed during serialization.
◆ IntegerEnquotingMinDigits
int? Quantum.QuantumUnityJsonSerializer.IntegerEnquotingMinDigits |
|
getset |
How many digits should a number have to be enquoted. Some JSON parsers deserialize all numbers as floating points, which in case of large integers (e.g. entity ids) can lead to precision loss. If this property is set to true (default), all integers with IntegerEnquotingMinDigits or more digits are enquoted.
◆ NullifyUnityObjectReferences
bool Quantum.QuantumUnityJsonSerializer.NullifyUnityObjectReferences = true |
|
getset |
Should all UnityEngine.Object references be nullified in the resulting JSON? If true, all UnityEngine.Object references will be serialized as null. Otherwise, they are serialized as { "instanceId": <value> }.
True by default.
◆ EntityViewPrefabResolver
Func<AssetGuid, GameObject> Quantum.QuantumUnityJsonSerializer.EntityViewPrefabResolver |
|
getset |
Custom resolver for EntityView prefabs.
EntityViews are serialized without prefab references (as they are not JSON serializable). Resolving takes place during deserialization, by looking up the prefab in the global DB.
◆ TypeResolver
Func<string, Type, Type> Quantum.QuantumUnityJsonSerializer.TypeResolver |
|
getset |
Custom type resolver to be used during deserialization.
If not set, Type.GetType(string, bool) will be used and an exception will be thrown on missing type. If set and returns null, the type object will be skipped and returned as null.