docs.unity3d.com

Localization 1.5.1

Search Results for

    Show / Hide Table of Contents

    Property KeyGenerator

    KeyGenerator

    The Key Generator to use when adding new entries. By default this will use DistributedUIDGenerator.

    Declaration
    public IKeyGenerator KeyGenerator { get; set; }
    Property Value
    Type Description
    IKeyGenerator
    Examples

    This example shows how the KeyGenerator could be configured to use a SequentialIDGenerator.

    using System.Linq;
    using UnityEditor;
    using UnityEditor.Localization;
    using UnityEngine.Localization.Tables;
    
    public class ChangeKeyGeneratorExample
    {
        public void ChangeKeyGenerator()
        {
            var stringTableCollection = LocalizationEditorSettings.GetStringTableCollection("My Game Text");
    
            // Determine the highest Key Id so Unity can continue generating Ids that do not conflict with existing Ids.
            long maxKeyId = 0;
            if (stringTableCollection.SharedData.Entries.Count > 0)
                maxKeyId = stringTableCollection.SharedData.Entries.Max(e => e.Id);
    
            stringTableCollection.SharedData.KeyGenerator = new SequentialIDGenerator(maxKeyId + 1);
    
            // Mark the asset dirty so that Unity saves the changes
            EditorUtility.SetDirty(stringTableCollection.SharedData);
        }
    }
    In This Article
    • KeyGenerator
    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)