In AddressableAssetSettings, you have a property for the labels "labelTable". internal LabelTable labelTable { get { return m_LabelTable; } } It would be helpful if you could make this table public, so we could programatically check if labels exist. It's a one word change. Would this be possible?
I would like this feature too, because it would be useful for me to remove labels via code if they are no longer used.
I'd like to get a list of all defined labels in my editor code. So at least, alongside AddLabel and RemoveLabel, I would love to see GetLabels or similar. Here's my use case: I'd like to initialize a custom array of AssetLabelReferences with all available labels. For now, I'm using reflection to retrieve the needed info. Code (CSharp): using UnityEditor; using UnityEditor.AddressableAssets; using System.Reflection; using System.Collections.Generic; using UnityEngine; [InitializeOnLoad] public static class AssetLabelPropertyExtension { static AssetLabelPropertyExtension() { EditorApplication.contextualPropertyMenu += OnPropertyContextMenu; } /// <summary> /// Adds a context menu to arrays of AssetLabelReference types which displays /// an option to initialize the collection with all available labels. /// </summary> /// <remarks> /// This is useful in cases such as when defining a list of fallback labels to load /// or whenever users have to input a list with almost all labels. /// </remarks> private static void OnPropertyContextMenu(GenericMenu menu, SerializedProperty property) { if (IsAssetLabelReferenceArray(property)) { // The settings object may not exist yet and so no label exist either. var settings = AddressableAssetSettingsDefaultObject.Settings; if (settings != null) { var copy = property.Copy(); menu.AddItem(new GUIContent("Initialize with all labels"), false, () => { // Since Unity does not expose the list of label, use reflection to find it. var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic; var labelTable = settings.GetType().GetProperty("labelTable", bindingFlags).GetValue(settings); var labelNames = (List<string>)labelTable.GetType().GetProperty("labelNames", bindingFlags).GetValue(labelTable); // Now we can simply overwrite the array with the found labels. copy.arraySize = labelNames.Count; for (int i = 0; i < labelNames.Count; i++) { var element = copy.GetArrayElementAtIndex(i); var labelStringProp = element.FindPropertyRelative("m_LabelString"); labelStringProp.stringValue = labelNames[i]; } // Undo is available, so no need to prompt the user for this destructive operation. copy.serializedObject.ApplyModifiedProperties(); }); } } } private static bool IsAssetLabelReferenceArray(SerializedProperty property) { return property.propertyType == SerializedPropertyType.Generic && property.isArray && property.arrayElementType == "AssetLabelReference"; } }