您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

55 行
1.6 KiB

using UnityEditorInternal;
using UnityEngine;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(Labeling))]
class LabelingEditor : Editor
{
const int k_Indent = 7;
ReorderableList m_LabelsList;
public void OnEnable()
{
m_LabelsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(global::Labeling.labels)), true, false, true, true);
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
}
void OnRemove(ReorderableList list)
{
if (list.index != -1)
Labeling.labels.RemoveAt(list.index);
}
Labeling Labeling => (Labeling)target;
void OnAdd(ReorderableList list)
{
Labeling.labels.Add("");
}
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
using (var change = new EditorGUI.ChangeCheckScope())
{
var indent = k_Indent * index;
if (indent >= rect.width)
return;
var contentRect = new Rect(rect.x + indent, rect.y, rect.width - indent, rect.height);
var value = EditorGUI.TextField(contentRect, Labeling.labels[index]);
if (change.changed)
{
Labeling.labels[index] = value;
}
}
}
public override void OnInspectorGUI()
{
m_LabelsList.DoLayoutList();
}
}
}