Writes a table snapshot to a file, so a file-backed provider can ship its tables as data instead of assets.
A writer turns a ResourceTableData snapshot into the bytes a matching
ITableFileReader reads back at runtime. Writing runs in the editor when player data is generated, so
no serialization code ships in a player. Pair an implementation with a FileTableProviderEditor
subclass to have Unity generate the files for a custom format.
Additional resources: FileTableProviderEditor, ITableFileReader, ResourceTableData
<para>Write a text format that the matching reader parses back.</para>
using System.IO; using System.Text; using Unity.Localization.Editor; using Unity.Localization.Providers.FileTables;
namespace Unity.Localization.Samples { public class TextTableWriter : ITableFileWriter { public static readonly TextTableWriter Instance = new();
public void Write(ResourceTableData data, Stream stream) { using var writer = new StreamWriter(stream, new UTF8Encoding(false), 1024, leaveOpen: true); writer.WriteLine($"@collection={data.CollectionName}"); writer.WriteLine($"@guid={data.CollectionGuid}"); writer.WriteLine($"@locale={data.LocaleCode}"); foreach (var entry in data.Entries) { if (entry != null && !string.IsNullOrEmpty(entry.Key)) writer.WriteLine($"{entry.Key}={entry.Value}"); } } }
// Registering the editor for the provider type is what makes Unity generate the files at build time. [AssetProviderEditor(typeof(TextResourceProvider))] public class TextResourceProviderEditor : FileTableProviderEditor { public override ITableFileWriter Writer => TextTableWriter.Instance; } }
| Method | Description |
|---|---|
| Write | Writes a table snapshot to a stream. |