docs.unity3d.com
    Show / Hide Table of Contents

    Interface ITablePostprocessor

    Gets a notification when a StringTable or AssetTable completes loading.

    Namespace: UnityEngine.Localization.Settings
    Syntax
    public interface ITablePostprocessor
    Examples

    This example demonstrates how to use the ITablePostprocessor to apply changes to a table after it has loaded but before it has been used. This can be beneficial when you wish to modify or add entries to a table, such as when supporting third-party content, for example modding.

    [Serializable]
    public class CustomTablePatcher : ITablePostprocessor
    {
    public void PostprocessTable(LocalizationTable table)
    {
        Debug.Log($"Postprocess {table}");
    
        if (table is StringTable stringTable)
        {
            // Add a new value
            stringTable.AddEntry("some new entry", "localized value");
    
            // Update an old value
            var entry = stringTable.GetEntry("some existing value");
            if (entry != null)
            {
                entry.Value = "updated localized value";
            }
        }
        else if (table is AssetTable assetTable)
        {
            // Add a new value
            var entry = assetTable.AddEntry("my texture asset", null);
            entry.SetAssetOverride(Texture2D.whiteTexture);
    
            // Override an existing value
            var overrideEntry = assetTable.GetEntry("existing entry");
            if (overrideEntry != null)
            {
                var texture = new Texture2D(10, 10);
                overrideEntry.SetAssetOverride(texture);
            }
        }
    }
    }
    public static class AssignCustomTablePatcherExample
    {
    [MenuItem("Localization Samples/Assign Custom table postprocessor")]
    public static void AssignTablePostprocessor()
    {
        // Create an instance of the table provider.
        var provider = new CustomTablePatcher();
    
        // A table postprocessor can be assigned to each database or the same can be shared between both.
        var settings = LocalizationEditorSettings.ActiveLocalizationSettings;
        settings.GetStringDatabase().TablePostprocessor = provider;
        settings.GetAssetDatabase().TablePostprocessor = provider;
    
        // Set dirty so the changes are saved.
        EditorUtility.SetDirty(settings);
    }
    }

    Methods

    PostprocessTable(LocalizationTable)

    This could be used to patch a table with updated values.

    Declaration
    void PostprocessTable(LocalizationTable table)
    Parameters
    Type Name Description
    LocalizationTable table

    The loaded StringTable or AssetTable.

    In This Article
    • Methods
      • PostprocessTable(LocalizationTable)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023