FileTableProviderEditor
The editor half of a file-backed content source, supplying the writer that generates its table files.
Read time 2 minutesLast updated 12 days ago
Definition
- Type: Class
- Namespace: Unity.Localization.Editor
- Assembly: UnityEditor
- Inherits from: AssetProviderEditor
public abstract class FileTableProviderEditor : AssetProviderEditor
Remarks
A FileTableProvider reads tables from files at runtime, and this generates those files when player data is built. Subclass it, return a writer matching the provider's reader, and register it with an AssetProviderEditorAttribute naming the provider type. Without a registered editor the provider's files are never generated and its tables do not resolve in a player.
Additional Resources: ITableFileWriter, FileTableProvider
Register a writer for a custom file format.
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; }}
Properties
Property | Description |
|---|---|
| Writer | The writer that turns a table snapshot into the provider's file format. |
Methods
Method | Description |
|---|---|
| ClearRegistrations | Drops every collection the provider records. |
| RegisterCollection | Records a collection so the provider serves its table files at runtime. |
| UnregisterCollection | Drops a collection so the provider stops serving its table files. |