WuhuIslandTesting/Library/PackageCache/com.unity.addressables@1.21.12/Editor/GUI/AssetLabelReferenceDrawer.cs

36 lines
1.3 KiB
C#
Raw Normal View History

2025-01-07 02:06:59 +01:00
using System;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace UnityEditor.AddressableAssets.GUI
{
[CustomPropertyDrawer(typeof(AssetLabelReference), true)]
class AssetLabelReferenceDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var currentLabel = property.FindPropertyRelative("m_LabelString");
var smallPos = EditorGUI.PrefixLabel(position, label);
if (AddressableAssetSettingsDefaultObject.Settings == null)
{
using (new EditorGUI.DisabledScope(true))
EditorGUI.LabelField(smallPos, new GUIContent(currentLabel.stringValue));
}
else
{
var labelList = AddressableAssetSettingsDefaultObject.Settings.labelTable.labelNames.ToArray();
var currIndex = Array.IndexOf(labelList, currentLabel.stringValue);
var newIndex = EditorGUI.Popup(smallPos, currIndex, labelList);
if (newIndex != currIndex)
{
currentLabel.stringValue = labelList[newIndex];
}
}
EditorGUI.EndProperty();
}
}
}