Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

ITableFileWriter

interface in Unity.Localization.Editor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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

Public Methods

Method Description
Write Writes a table snapshot to a stream.