Search Unity

Question Add custom label to addressables group

Discussion in 'Localization Tools' started by Skibitsky, May 12, 2023.

  1. Skibitsky

    Skibitsky

    Joined:
    Mar 22, 2016
    Posts:
    24
    Hello,

    I'd like to add custom labels to some entries inside of localization assets/strings groups to have more control when downloading bundles from remote.

    However, all groups used by Localization package seem to be read-only. How can I add custom labels?

    upload_2023-5-12_14-26-43.png
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    You can remove the read only flag by editing the group asset. You may need to switch the inspector to debug mode to see the field.
     
  3. Skibitsky

    Skibitsky

    Joined:
    Mar 22, 2016
    Posts:
    24
    Thanks, @karl_jones!

    Unchecking the flag makes a group editable, but all entries inside of it remain read-only. I.e. can't rename or change labels.

    Restarting Unity didn't help.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Oh looks like they changed things since I last did that.
    It seems they now also have a readonly flag on each entry. You can do the same and go and remove it. Its in the field called Serialize Entries.
     
  5. Skibitsky

    Skibitsky

    Joined:
    Mar 22, 2016
    Posts:
    24
    It seems to work, thank you!

    If anyone has thousands of entries like we do, here is an Editor tool I used to remove "ReadOnly" label from all entries in a group.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.AddressableAssets.Settings;
    3. using UnityEngine;
    4.  
    5. public class ReadonlyRemover : EditorWindow
    6. {
    7.     private AddressableAssetGroup _addressableAssetGroup;
    8.  
    9.     [MenuItem("Window/Readonly Remover")]
    10.     public static void ShowWindow()
    11.     {
    12.         GetWindow<ReadonlyRemover>("Readonly Remover");
    13.     }
    14.  
    15.     private void OnGUI()
    16.     {
    17.         EditorGUILayout.LabelField("AddressableAssetGroup Readonly Remover", EditorStyles.boldLabel);
    18.  
    19.         EditorGUILayout.Space();
    20.  
    21.         _addressableAssetGroup = (AddressableAssetGroup)EditorGUILayout.ObjectField("Addressable Asset Group",
    22.             _addressableAssetGroup, typeof(AddressableAssetGroup), false);
    23.  
    24.         if (GUILayout.Button("Remove Readonly Flag"))
    25.         {
    26.             if (_addressableAssetGroup != null)
    27.             {
    28.                 RemoveReadonlyFlag();
    29.             }
    30.             else
    31.             {
    32.                 Debug.LogError("AddressableAssetGroup is null. Please assign an AddressableAssetGroup.");
    33.             }
    34.         }
    35.     }
    36.  
    37.     private void RemoveReadonlyFlag()
    38.     {
    39.         foreach (var entry in _addressableAssetGroup.entries)
    40.             entry.ReadOnly = false;
    41.  
    42.         EditorUtility.SetDirty(_addressableAssetGroup);
    43.         AssetDatabase.SaveAssets();
    44.         AssetDatabase.Refresh();
    45.         Debug.Log("Readonly flags have been removed.");
    46.     }
    47. }
     
    karl_jones likes this.