docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface ITablePostprocessor

    Gets a notification when a StringTable or AssetTable completes loading.

    Namespace: UnityEngine.Localization.Settings
    Assembly: Unity.Localization.dll
    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

    Name Description
    PostprocessTable(LocalizationTable)

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

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)