using System.Collections.Generic; using System.IO; using System.Linq; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.Perception.GroundTruth; using UnityEngine.UIElements; using UnityEditor.UIElements; namespace UnityEditor.Perception.GroundTruth { abstract class LabelConfigEditor : Editor where T : ILabelEntry { string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/"; string m_UxmlPath; int m_AddedLabelsItemHeight = 37; int m_OtherLabelsItemHeight = 27; List m_AddedLabels = new List(); protected SerializedProperty m_SerializedLabelsArray; HashSet m_AllLabelsInProject = new HashSet(); List m_LabelsNotPresentInConfig = new List(); bool m_UiInitialized; bool m_EditorHasUi; VisualElement m_Root; Button m_SaveButton; Button m_AddNewLabelButton; Button m_RemoveAllButton; Button m_AddAllButton; Button m_ImportFromFileButton; Button m_ExportToFileButton; ListView m_NonPresentLabelsListView; protected ListView m_LabelListView; protected Button m_MoveUpButton; protected Button m_MoveDownButton; protected VisualElement m_MoveButtons; protected VisualElement m_IdSpecificUi; protected EnumField m_StartingIdEnumField; protected Toggle m_AutoIdToggle; public void OnEnable() { m_SerializedLabelsArray = serializedObject.FindProperty(IdLabelConfig.labelEntriesFieldName); m_UiInitialized = false; ChangesHappeningInForeground = true; RefreshListDataAndPresentation(); } int m_PreviousLabelsArraySize = -1; /// /// This boolean is used to signify when changes in the model are triggered directly from the inspector UI by the user. /// In these cases, the scheduled model checker does not need to update the UI again. /// public bool ChangesHappeningInForeground { get; set; } void CheckForModelChanges() { serializedObject.Update(); if (ChangesHappeningInForeground) { ChangesHappeningInForeground = false; m_PreviousLabelsArraySize = m_SerializedLabelsArray.arraySize; return; } if (m_SerializedLabelsArray.arraySize != m_PreviousLabelsArraySize) { RefreshListDataAndPresentation(); m_PreviousLabelsArraySize = m_SerializedLabelsArray.arraySize; } } protected abstract void InitUiExtended(); public abstract void PostRemoveOperations(); public override VisualElement CreateInspectorGUI() { if (!m_UiInitialized) { InitUi(); m_UiInitialized = true; } serializedObject.Update(); RefreshListDataAndPresentation(); return m_Root; } void InitUi() { m_EditorHasUi = true; m_UxmlPath = m_UxmlDir + "LabelConfig_Main.uxml"; m_Root = AssetDatabase.LoadAssetAtPath(m_UxmlPath).CloneTree(); m_LabelListView = m_Root.Q("labels-listview"); m_NonPresentLabelsListView = m_Root.Q("labels-in-project-listview"); m_SaveButton = m_Root.Q