Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ITableFileWriter

Writes a table snapshot to a file, so a file-backed provider can ship its tables as data instead of assets.
Read time 1 minuteLast updated 10 days ago

Definition

public interface ITableFileWriter

Remarks

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.
Write a text format that the matching reader parses back.

Examples

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; }}

Methods

Method

Description

WriteWrites a table snapshot to a stream.