Class InputJSONNodeWriter
Serializes a InputJSONNode tree back to JSON text, matching the formatting Unity's own serializer produces for input action assets.
Inherited Members
Namespace: Scylla.Input
Assembly: ScyllaInput.dll
Syntax
public static class InputJSONNodeWriter
Remarks
Unity writes action assets with JsonUtility.ToJson(value, prettyPrint: true),
which produces a four-space indent, a single space after each colon, LF newlines,
inline [] for empty arrays, and no trailing newline. Reproducing that exactly
is what lets a Scylla save of an unmodified asset leave version control untouched.
Two details are easy to get wrong. The Core writer's indent can only be changed
through Scylla.Core.Util.Serialization.ScyllaJSONWriter.Configure(Scylla.Core.Util.Serialization.SerializationSettings); calling
SetPrettyPrint(bool) alone leaves the default tab. And
numbers are emitted through WriteRawValue(string) from their
stored source text, because rendering a parsed value back would turn 1.0 into
1 and would depend on the current culture.
Fields
UNITY_INDENT
The indent Unity's pretty-printed JSON uses: four spaces per nesting level. The Core writer defaults to a tab, so this must be applied explicitly.
Declaration
public const string UNITY_INDENT = " "
Field Value
| Type | Description |
|---|---|
| string |
Methods
Write(InputJSONNode)
Serializes a tree using Unity's pretty-print formatting.
Declaration
public static string Write(InputJSONNode root)
Parameters
| Type | Name | Description |
|---|---|---|
| InputJSONNode | root | The root node. |
Returns
| Type | Description |
|---|---|
| string | The JSON text, with no trailing newline. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the root is |
Write(InputJSONNode, bool, string)
Serializes a tree with explicit formatting control.
Declaration
public static string Write(InputJSONNode root, bool prettyPrint, string indent)
Parameters
| Type | Name | Description |
|---|---|---|
| InputJSONNode | root | The root node. |
| bool | prettyPrint |
|
| string | indent | The string repeated once per nesting level. Ignored when not pretty-printing. |
Returns
| Type | Description |
|---|---|
| string | The JSON text, with no trailing newline. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the root is |
WriteBytes(InputJSONNode)
Serializes a tree using Unity's formatting and returns UTF-8 bytes with no byte order mark.
Declaration
public static byte[] WriteBytes(InputJSONNode root)
Parameters
| Type | Name | Description |
|---|---|---|
| InputJSONNode | root | The root node. |
Returns
| Type | Description |
|---|---|
| byte[] | The UTF-8 encoded JSON text. |
Remarks
Prefer this over encoding the string yourself when writing to disk. Unity's action assets carry no byte order mark, and the framework's text-writing helper emits one by default, so going through bytes avoids a corrupt first line.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the root is |