浏览代码

Labeling editor in progress

/main
Mohsen Kamalzadeh 4 年前
当前提交
848561a4
共有 35 个文件被更改,包括 757 次插入81 次删除
  1. 276
      com.unity.perception/Editor/GroundTruth/LabelingEditor.cs
  2. 2
      com.unity.perception/Editor/GroundTruth/LabelingEditor.cs.meta
  3. 14
      com.unity.perception/Editor/Randomization/Uss/Styles.uss
  4. 3
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
  5. 4
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Materials/SegmentationMaterial.mat
  6. 5
      com.unity.perception/Runtime/GroundTruth/Labeling/IdLabelConfig.cs
  7. 7
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelConfig.cs
  8. 13
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelEntryMatchCache.cs
  9. 11
      com.unity.perception/Runtime/GroundTruth/Labeling/Labeling.cs
  10. 147
      com.unity.perception/Editor/GroundTruth/AddToConfigWindow.cs
  11. 3
      com.unity.perception/Editor/GroundTruth/AddToConfigWindow.cs.meta
  12. 127
      com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs
  13. 3
      com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs.meta
  14. 8
      com.unity.perception/Editor/GroundTruth/Uss.meta
  15. 8
      com.unity.perception/Editor/GroundTruth/Uxml.meta
  16. 93
      com.unity.perception/Editor/GroundTruth/Uss/Styles.uss
  17. 3
      com.unity.perception/Editor/GroundTruth/Uss/Styles.uss.meta
  18. 11
      com.unity.perception/Editor/GroundTruth/Uxml/AddToConfigWindow.uxml
  19. 10
      com.unity.perception/Editor/GroundTruth/Uxml/AddToConfigWindow.uxml.meta
  20. 7
      com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml
  21. 3
      com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml.meta
  22. 8
      com.unity.perception/Editor/GroundTruth/Uxml/AddedLabelElement.uxml
  23. 3
      com.unity.perception/Editor/GroundTruth/Uxml/AddedLabelElement.uxml.meta
  24. 8
      com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelNotPresent.uxml
  25. 3
      com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelNotPresent.uxml.meta
  26. 8
      com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelPresent.uxml
  27. 3
      com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelPresent.uxml.meta
  28. 27
      com.unity.perception/Editor/GroundTruth/Uxml/Labeling_Main.uxml
  29. 10
      com.unity.perception/Editor/GroundTruth/Uxml/Labeling_Main.uxml.meta
  30. 7
      com.unity.perception/Editor/GroundTruth/Uxml/SuggestedLabelElement.uxml
  31. 3
      com.unity.perception/Editor/GroundTruth/Uxml/SuggestedLabelElement.uxml.meta
  32. 0
      /com.unity.perception/Editor/Icons.meta
  33. 0
      /com.unity.perception/Editor/Icons

276
com.unity.perception/Editor/GroundTruth/LabelingEditor.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.UIElements;
using UnityEngine.PlayerLoop;
using UnityEngine.Rendering.UI;
using UnityEngine.UIElements;
[CustomEditor(typeof(Labeling)), CanEditMultipleObjects]
[CustomEditor(typeof(Labeling))]
ReorderableList m_LabelsList;
class MyBinding : IBinding
{
private LabelingEditor m_Editor;
public void OnEnable()
{
m_LabelsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(Labeling.labels)), true, false, true, true);
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
m_LabelsList.onReorderCallbackWithDetails += OnReordered;
}
public MyBinding(LabelingEditor editor)
{
m_Editor = editor;
}
void OnRemove(ReorderableList list)
{
if (list.index != -1)
public void PreUpdate()
var value = labeling.labels[list.index];
foreach (var t in targets)
{
((Labeling)t).labels.Remove(value);
}
}
Labeling labeling => (Labeling)target;
public void Update()
{
m_Editor.RefreshUi();
}
void OnAdd(ReorderableList list)
{
foreach (var t in targets)
public void Release()
var castedTarget = ((Labeling)t);
castedTarget.labels.Add("");
EditorUtility.SetDirty(castedTarget);
void OnReordered(ReorderableList list, int oldIndex, int newIndex)
private Labeling m_Labeling;
private SerializedProperty m_SerializedLabelsArray;
private VisualElement m_Root;
private BindableElement m_OuterElement;
private ListView m_CurrentLabelsListView;
private ListView m_SuggestLabelsListView_FromName;
private ListView m_SuggestLabelsListView_FromPath;
private ListView m_SuggestLabelsListView_FromDB;
private Button m_AddButton;
private string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/";
private string m_UxmlPath;
private string[] nameSeparators = {".","-", "_"};
private string[] pathSeparators = {"/"};
public List<string> suggestedLabelsBasedOnName = new List<string>();
public List<string> suggestedLabelsBasedOnPath = new List<string>();
private void OnEnable()
var label = labeling.labels[newIndex];
m_SerializedLabelsArray = serializedObject.FindProperty("labels");
m_Labeling = (Labeling) target;
m_UxmlPath = m_UxmlDir + "Labeling_Main.uxml";
m_Root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(m_UxmlPath).CloneTree();
m_OuterElement = m_Root.Q<BindableElement>("outer-container");
m_OuterElement.binding = new MyBinding(this);
m_OuterElement.bindingPath = "labels";
m_CurrentLabelsListView = m_Root.Q<ListView>("current-labels-listview");
m_SuggestLabelsListView_FromName = m_Root.Q<ListView>("suggested-labels-name-listview");
m_SuggestLabelsListView_FromPath = m_Root.Q<ListView>("suggested-labels-path-listview");
m_SuggestLabelsListView_FromDB = m_Root.Q<ListView>("suggested-labels-db-listview");
m_AddButton = m_Root.Q<Button>("add-label");
foreach (var t in targets)
m_AddButton.clicked += () =>
var l = (Labeling)t;
if (this.labeling == l) continue;
m_SerializedLabelsArray.InsertArrayElementAtIndex(m_SerializedLabelsArray.arraySize);
m_SerializedLabelsArray.GetArrayElementAtIndex(m_SerializedLabelsArray.arraySize - 1).stringValue =
"<New Label>";
serializedObject.ApplyModifiedProperties();
m_CurrentLabelsListView.Refresh();
};
SetupListViews();
UpdateSuggestedLabelLists();
}
public override VisualElement CreateInspectorGUI()
{
serializedObject.Update();
return m_Root;
}
ReorderLabels(l, label, newIndex);
}
public void RemoveAddedLabelsFromSuggestedLists()
{
suggestedLabelsBasedOnName.RemoveAll(s => m_Labeling.labels.Contains(s));
suggestedLabelsBasedOnPath.RemoveAll(s => m_Labeling.labels.Contains(s));
static void ReorderLabels(Labeling labeling, string label, int newIndex)
public void UpdateSuggestedLabelLists()
if (labeling.labels.Contains(label))
//based on name
suggestedLabelsBasedOnName.Clear();
string assetName = m_Labeling.gameObject.name;
suggestedLabelsBasedOnName.Add(assetName);
suggestedLabelsBasedOnName.AddRange(assetName.Split(nameSeparators, StringSplitOptions.RemoveEmptyEntries).ToList());
RemoveAddedLabelsFromSuggestedLists();
//based on path
suggestedLabelsBasedOnPath.Clear();
var prefabObject = PrefabUtility.GetCorrespondingObjectFromSource(m_Labeling.gameObject);
if (prefabObject)
labeling.labels.Remove(label);
if (newIndex < labeling.labels.Count)
labeling.labels.Insert(newIndex, label);
else
labeling.labels.Add(label);
string assetPath = AssetDatabase.GetAssetPath(prefabObject);
var stringList = assetPath.Split(pathSeparators, StringSplitOptions.RemoveEmptyEntries).ToList();
stringList.Reverse();
suggestedLabelsBasedOnPath.AddRange(stringList);
RemoveAddedLabelsFromSuggestedLists();
static void ReplaceLabel(Labeling labeling, string oldLabel, string newLabel)
public void RefreshUi()
var idx = labeling.labels.IndexOf(oldLabel);
if (idx == -1) return;
labeling.labels[idx] = newLabel;
m_CurrentLabelsListView.Refresh();
m_SuggestLabelsListView_FromName.Refresh();
m_SuggestLabelsListView_FromPath.Refresh();
m_SuggestLabelsListView_FromDB.Refresh();
private void ReplaceLabel(int index, string newLabel)
void SetupListViews()
labeling.labels[index] = newLabel;
//Labels that have already been added to the target Labeling component
SetupCurrentLabelsListView();
//Labels suggested by the system, which the user can add
SetupSuggestedLabelsListViews();
void ReplaceLabelAll(int index, string currentLabel)
void SetupCurrentLabelsListView()
var oldLabel = labeling.labels[index];
ReplaceLabel(index, currentLabel);
VisualElement MakeItem() =>
new AddedLabelEditor(this, m_CurrentLabelsListView, serializedObject, m_SerializedLabelsArray);
foreach (var t in targets)
void BindItem(VisualElement e, int i)
var l = (Labeling)t;
if (e is AddedLabelEditor addedLabel)
{
addedLabel.m_IndexInList = i;
addedLabel.m_LabelTextField.BindProperty(m_SerializedLabelsArray.GetArrayElementAtIndex(i));
}
}
if (this.labeling == l) continue;
const int itemHeight = 35;
m_CurrentLabelsListView.bindItem = BindItem;
m_CurrentLabelsListView.makeItem = MakeItem;
m_CurrentLabelsListView.itemHeight = itemHeight;
m_CurrentLabelsListView.itemsSource = m_Labeling.labels;
ReplaceLabel(l, oldLabel, currentLabel);
}
//m_CurrentLabelsListView.reorderable = true;
//m_CurrentLabelsListView.selectionType = SelectionType.Multiple;
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
void SetupSuggestedLabelsListViews()
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.x, rect.y, rect.width, rect.height);
SetupSuggestedLabelsBasedOnFlatList(m_SuggestLabelsListView_FromName, suggestedLabelsBasedOnName);
SetupSuggestedLabelsBasedOnFlatList(m_SuggestLabelsListView_FromPath, suggestedLabelsBasedOnPath);
//SetupSuggestedLabelsBasedOnFlatList(m_SuggestLabelsListView_FromDB, );
}
var value = EditorGUI.DelayedTextField(contentRect, labeling.labels[index]);
void SetupSuggestedLabelsBasedOnFlatList(ListView labelsListView, List<string> stringList)
{
VisualElement MakeItem() => new SuggestedLabelElement(this, labelsListView,
m_CurrentLabelsListView,
m_SerializedLabelsArray, serializedObject);
if (change.changed)
void BindItem(VisualElement e, int i)
{
if (e is SuggestedLabelElement suggestedLabel)
ReplaceLabelAll(index, value);
if (PrefabUtility.IsPartOfAnyPrefab(target))
{
EditorUtility.SetDirty(target);
}
suggestedLabel.m_Label.text = stringList[i];
const int itemHeight = 32;
labelsListView.bindItem = BindItem;
labelsListView.makeItem = MakeItem;
labelsListView.itemHeight = itemHeight;
labelsListView.itemsSource = stringList;
labelsListView.selectionType = SelectionType.None;
}
public override void OnInspectorGUI()
class AddedLabelEditor : VisualElement
{
private string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/";
private string m_UxmlPath;
private VisualElement m_Root;
private Button m_RemoveButton;
private Button m_AddToConfigButton;
public TextField m_LabelTextField;
public int m_IndexInList;
public AddedLabelEditor(LabelingEditor editor, ListView listView, SerializedObject serializedLabelingObject, SerializedProperty labelsArrayProperty)
{
m_UxmlPath = m_UxmlDir + "AddedLabelElement.uxml";
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(m_UxmlPath).CloneTree(this);
m_LabelTextField = this.Q<TextField>("label-value");
m_RemoveButton = this.Q<Button>("remove-button");
m_AddToConfigButton = this.Q<Button>("add-to-config-button");
m_AddToConfigButton.clicked += () =>
{
AddToConfigWindow.ShowWindow(m_LabelTextField.value);
};
m_RemoveButton.clicked += () =>
{
labelsArrayProperty.DeleteArrayElementAtIndex(m_IndexInList);
serializedLabelingObject.ApplyModifiedProperties();
editor.UpdateSuggestedLabelLists();
editor.RefreshUi();
listView.Refresh();
};
}
}
class SuggestedLabelElement : VisualElement
{
private string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/";
private string m_UxmlPath;
private VisualElement m_Root;
private Button m_AddButton;
public Label m_Label;
public SuggestedLabelElement(LabelingEditor editor, ListView suggestedLabelsListView, ListView currentLabelsListView, SerializedProperty serializedLabelArray, SerializedObject serializedLabelingObject)
m_LabelsList.DoLayoutList();
m_UxmlPath = m_UxmlDir + "SuggestedLabelElement.uxml";
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(m_UxmlPath).CloneTree(this);
m_Label = this.Q<Label>("label-value");
m_AddButton = this.Q<Button>("add-button");
m_AddButton.clicked += () =>
{
serializedLabelArray.InsertArrayElementAtIndex(serializedLabelArray.arraySize);
serializedLabelArray.GetArrayElementAtIndex(serializedLabelArray.arraySize-1).stringValue = m_Label.text;
serializedLabelingObject.ApplyModifiedProperties();
editor.RemoveAddedLabelsFromSuggestedLists();
editor.RefreshUi();
};
}

2
com.unity.perception/Editor/GroundTruth/LabelingEditor.cs.meta


fileFormatVersion: 2
guid: 2e725508a34c40a0938c8d891b371980
guid: 387b8732b87094321af57795df93aec4
timeCreated: 1585933334

14
com.unity.perception/Editor/Randomization/Uss/Styles.uss


.randomization__remove-item-button {
width: 12px;
height: 14px;
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/X.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/X.png");
}
.randomization__collapse-toggle {

width: 10px;
height: 10px;
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutOpen.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/FoldoutOpen.png");
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutClosed.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/FoldoutClosed.png");
}
.randomization__collapse-toggle:hover {

.randomization__chevron-left {
height: 12px;
width: 12px;
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/ChevronLeft.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/ChevronLeft.png");
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/ChevronRight.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/ChevronRight.png");
}

width: 16px;
height: 100%;
min-height: 20px;
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/DragHandle.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/DragHandle.png");
}
.randomizer__drag-handle:hover {

top: 9px;
width: 10px;
height: 10px;
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/Search.png");
background-image: resource("Packages/com.unity.perception/Editor/Icons/Search.png");
}
.randomizer__menu-search-bar .unity-base-text-field__input {

3
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs


m_AsyncAnnotations[Time.frameCount] = perceptionCamera.SensorHandle.ReportAnnotationAsync(m_BoundingBoxAnnotationDefinition);
}
private int count = 0;
void OnRenderedObjectInfosCalculated(int frameCount, NativeArray<RenderedObjectInfo> renderedObjectInfos)
{
if (!m_AsyncAnnotations.TryGetValue(frameCount, out var asyncAnnotation))

count++;
using (s_BoundingBoxCallback.Auto())
{
m_BoundingBoxValues.Clear();

4
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Materials/SegmentationMaterial.mat


m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 1
- _BackTransparency: 0
- _BackTransparency: 1
- _Blend: 2
- _BlendOp: 0
- _BumpScale: 1

- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _SegmentTransparency: 0.8
- _SegmentTransparency: 1
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0

5
com.unity.perception/Runtime/GroundTruth/Labeling/IdLabelConfig.cs


m_LabelEntryMatchCache = null;
}
public void ClearLabelEntryMatchCache()
{
m_LabelEntryMatchCache?.ClearCache();
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal struct LabelEntrySpec
{

7
com.unity.perception/Runtime/GroundTruth/Labeling/LabelConfig.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth

{
return TryGetMatchingConfigurationEntry(labeling, out labelEntry, out int _);
}
public bool DoesLabelMatchAnyEntries(string label)
{
return m_LabelEntries.Any(entry => string.Equals(entry.label, label));
}
/// <summary>
/// Initialize the list of LabelEntries on this LabelingConfiguration. Should only be called immediately after instantiation.

13
com.unity.perception/Runtime/GroundTruth/Labeling/LabelEntryMatchCache.cs


const int k_StartingObjectCount = 1 << 8;
NativeList<ushort> m_InstanceIdToLabelEntryIndexLookup;
IdLabelConfig m_IdLabelConfig;
ushort m_DefaultValue;
ushort m_DefaultValue = ushort.MaxValue;
public LabelEntryMatchCache(IdLabelConfig idLabelConfig)
{

{
if (m_IdLabelConfig.TryGetMatchingConfigurationEntry(labeling, out _, out var index))
{
m_DefaultValue = ushort.MaxValue;
Debug.Assert(index < m_DefaultValue, "Too many entries in the label config");
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
{

m_InstanceIdToLabelEntryIndexLookup[i] = m_DefaultValue;
}
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = (ushort)index;
}
else if (m_InstanceIdToLabelEntryIndexLookup.Length > (int)instanceId)
{
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = m_DefaultValue;
}
}

m_InstanceIdToLabelEntryIndexLookup.Dispose();
}
public void ClearCache()
{
m_InstanceIdToLabelEntryIndexLookup.Clear();
}
}
}

11
com.unity.perception/Runtime/GroundTruth/Labeling/Labeling.cs


using System;
using System.Collections.Generic;
using Unity.Entities;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;

if (World.DefaultGameObjectInjectionWorld != null)
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(m_Entity);
}
void Reset()
{
labels.Clear();
labels.Add(gameObject.name);
#if UNITY_EDITOR
EditorUtility.SetDirty(gameObject);
#endif
}
/// <summary>
/// Refresh ground truth generation for the labeling of the attached GameObject. This is necessary when the

147
com.unity.perception/Editor/GroundTruth/AddToConfigWindow.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Unity.Entities;
using UnityEditor.UIElements;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.PlayerLoop;
using UnityEngine.Rendering.UI;
using UnityEngine.UIElements;
using Object = System.Object;
namespace UnityEditor.Perception.GroundTruth
{
class AddToConfigWindow : EditorWindow
{
private VisualElement m_Root;
private string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/";
private string m_UxmlPath;
private static string m_LabelValue;
private static Label m_TitleLabel;
private List<string> m_ConfigsContainingLabel = new List<string>();
private List<string> m_ConfigsNotContainingLabel = new List<string>();
private ListView m_PresentConfigsListview;
private ListView m_NonPresentConfigsListview;
public static void ShowWindow(string labelValue)
{
m_LabelValue = labelValue;
var window = GetWindow<AddToConfigWindow>();
window.Init();
window.Show();
}
void Init()
{
m_ConfigsContainingLabel.Clear();
if(m_TitleLabel != null)
m_TitleLabel.text = "Add " + m_LabelValue + "to Label Configurations";
var types = FindAllRelevant();
AssetDatabase.Refresh();
List<string> labelConfigGuids = new List<string>();
foreach (var type in types)
{
labelConfigGuids.AddRange(AssetDatabase.FindAssets("t:"+type.Name));
}
CheckInclusionInConfigs(labelConfigGuids, types, m_LabelValue, this);
Func<VisualElement> makeItem = () => new Label();
Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = m_ConfigsContainingLabel[i];
m_PresentConfigsListview.itemHeight = 30;
m_PresentConfigsListview.itemsSource = m_ConfigsContainingLabel;
m_PresentConfigsListview.bindItem = bindItem;
m_PresentConfigsListview.makeItem = makeItem;
Func<VisualElement> makeItem1 = () => new Label();
Action<VisualElement, int> bindItem1 = (e, i) => (e as Label).text = m_ConfigsNotContainingLabel[i];
m_NonPresentConfigsListview.itemHeight = 30;
m_NonPresentConfigsListview.itemsSource = m_ConfigsNotContainingLabel;
m_NonPresentConfigsListview.bindItem = bindItem1;
m_NonPresentConfigsListview.makeItem = makeItem1;
}
void OnEnable()
{
m_UxmlPath = m_UxmlDir + "AddToConfigWindow.uxml";
m_Root = rootVisualElement;
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(m_UxmlPath).CloneTree(m_Root);
m_TitleLabel = m_Root.Query<Label>("title");
m_TitleLabel.text = "Add \"" + m_LabelValue + "\" to Label Configurations";
m_PresentConfigsListview = m_Root.Query<ListView>("current-configs-listview");
m_NonPresentConfigsListview = m_Root.Query<ListView>("other-configs-listview");
}
void CheckInclusionInConfigs(List<string> configGuids, List<Type> configTypes, string label, AddToConfigWindow window)
{
foreach (var configGuid in configGuids)
{
var asset = AssetDatabase.LoadAssetAtPath<ScriptableObject>(AssetDatabase.GUIDToAssetPath(configGuid));
var methodInfo = asset.GetType().GetMethod("DoesLabelMatchAnyEntries");
if (methodInfo == null)
continue;
object[] parametersArray = new object[1];
parametersArray[0] = label;
var labelExistsInConfig = (bool) methodInfo.Invoke(asset, parametersArray);
if (labelExistsInConfig)
{
m_ConfigsContainingLabel.Add(asset.name);
}
else
{
m_ConfigsNotContainingLabel.Add(asset.name);
}
}
}
public T Cast<T>(object o)
{
return (T) o;
}
List<Type> FindAllRelevant()
{
Type superType = typeof(LabelConfig<>);
Assembly assembly = Assembly.GetAssembly(superType);
Type[] types = assembly.GetTypes();
List<Type> subclasses = types.Where(t => IsSubclassOfRawGeneric(superType, t)).ToList();
return subclasses;
}
bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
while (toCheck != null && toCheck != typeof(object)) {
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur) {
return true;
}
toCheck = toCheck.BaseType;
}
return false;
}
}
}

3
com.unity.perception/Editor/GroundTruth/AddToConfigWindow.cs.meta


fileFormatVersion: 2
guid: 2485979b726fe4f3b829a3a4173a72c6
timeCreated: 1585933334

127
com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs


//#define ENABLED
#if ENABLED
using Unity.Entities;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(Labeling)), CanEditMultipleObjects]
class LabelingEditor : Editor
{
ReorderableList m_LabelsList;
public void OnEnable()
{
m_LabelsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(Labeling.labels)), true, false, true, true);
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
m_LabelsList.onReorderCallbackWithDetails += OnReordered;
}
void OnRemove(ReorderableList list)
{
if (list.index != -1)
{
var value = labeling.labels[list.index];
foreach (var t in targets)
{
((Labeling)t).labels.Remove(value);
}
}
}
Labeling labeling => (Labeling)target;
void OnAdd(ReorderableList list)
{
foreach (var t in targets)
{
var castedTarget = ((Labeling)t);
castedTarget.labels.Add("");
EditorUtility.SetDirty(castedTarget);
}
}
void OnReordered(ReorderableList list, int oldIndex, int newIndex)
{
var label = labeling.labels[newIndex];
foreach (var t in targets)
{
var l = (Labeling)t;
if (this.labeling == l) continue;
ReorderLabels(l, label, newIndex);
}
}
static void ReorderLabels(Labeling labeling, string label, int newIndex)
{
if (labeling.labels.Contains(label))
{
labeling.labels.Remove(label);
if (newIndex < labeling.labels.Count)
labeling.labels.Insert(newIndex, label);
else
labeling.labels.Add(label);
}
}
static void ReplaceLabel(Labeling labeling, string oldLabel, string newLabel)
{
var idx = labeling.labels.IndexOf(oldLabel);
if (idx == -1) return;
labeling.labels[idx] = newLabel;
}
private void ReplaceLabel(int index, string newLabel)
{
labeling.labels[index] = newLabel;
}
void ReplaceLabelAll(int index, string currentLabel)
{
var oldLabel = labeling.labels[index];
ReplaceLabel(index, currentLabel);
foreach (var t in targets)
{
var l = (Labeling)t;
if (this.labeling == l) continue;
ReplaceLabel(l, oldLabel, currentLabel);
}
}
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.x, rect.y, rect.width, rect.height);
var value = EditorGUI.DelayedTextField(contentRect, labeling.labels[index]);
if (change.changed)
{
ReplaceLabelAll(index, value);
if (PrefabUtility.IsPartOfAnyPrefab(target))
{
EditorUtility.SetDirty(target);
}
}
}
}
public override void OnInspectorGUI()
{
m_LabelsList.DoLayoutList();
}
}
}
#endif

3
com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs.meta


fileFormatVersion: 2
guid: 2e725508a34c40a0938c8d891b371980
timeCreated: 1585933334

8
com.unity.perception/Editor/GroundTruth/Uss.meta


fileFormatVersion: 2
guid: c9dfe1921f7e84112aa13f8a71d7a2f1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.perception/Editor/GroundTruth/Uxml.meta


fileFormatVersion: 2
guid: d98210a441f014a5cb3b1f68cfa69326
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

93
com.unity.perception/Editor/GroundTruth/Uss/Styles.uss


.labeling__remove-item-button {
width: 16px;
height: 16px;
background-image: resource('Packages/com.unity.perception/Editor/Icons/X.png');
align-self: center;
}
.added-label {
margin: 3px 4px 3px 4px;
flex-direction: row;
align-content: center;
}
.suggested-label {
margin: 3px 6px 3px 6px;
flex-direction: row;
align-content: center;
border-color: grey;
border-width: 1px;
padding: 2px;
padding-left: 5px;
border-radius: 4px;
}
.labeling__added-label-value {
width: auto;
flex-grow: 1;
}
.labeling__suggested-label-value {
width: auto;
flex-grow: 1;
align-self: center;
}
.labeling__label-listview {
flex-grow: 1;
min-height: 150px;
border-radius: 4px;
margin-right: 2px;
margin-top: 2px;
padding: 6px;
padding-top: 6px;
border-bottom-right-radius: 0;
border-width: 1px;
border-color: gray;
background-color: ButtonHighlight;
}
.labeling__configs-listview {
flex-grow: 1;
min-height: 150px;
background-color: rgb(32, 32, 32);
border-radius: 4px;
margin: 6px;
padding: 6px;
padding-top: 6px;
border-bottom-right-radius: 0;
}
.labeling__add-label-button {
align-self: flex-end;
border-width: 0;
border-top-right-radius: 0;
border-top-left-radius: 0;
background-color: rgb(32, 32, 32);
margin-right: 2px;
margin-top: 2px;
}
.outer-container {
padding-top: 5px;
}
.inner-container {
margin-top: 10px;
border-radius: 10px;
border-width: 1px;
border-color: gray;
padding: 10px;
}
.labeling__add-to-list-button {
align-self: flex-end;
}
.labeling__add-to-config-button {
padding: 6px;
}
.title-label {
-unity-font-style: bold;
}

3
com.unity.perception/Editor/GroundTruth/Uss/Styles.uss.meta


fileFormatVersion: 2
guid: dbe9e8ec4b8ef4ff384a22001ff72674
timeCreated: 1601665266

11
com.unity.perception/Editor/GroundTruth/Uxml/AddToConfigWindow.uxml


<UXML xmlns="UnityEngine.UIElements">
<BindableElement class="outer-container" name="outer-container">
<Style src="../Uss/Styles.uss"/>
<Label name="title" class="title-label"/>
<Label text="Currently Present In:"/>
<ListView name="current-configs-listview" class="labeling__configs-listview" style="height:150px"/>
<Label text="Other Label Configs in Project:"/>
<ListView name="other-configs-listview" class="labeling__configs-listview"/>
</BindableElement>
</UXML>

10
com.unity.perception/Editor/GroundTruth/Uxml/AddToConfigWindow.uxml.meta


fileFormatVersion: 2
guid: 8b8acfa72087c43698d342a06e2b30e6
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

7
com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="added-config">
<Style src="../Uss/Styles.uss"/>
<Label name="config-name" class="labeling__config-name"/>
<Button name="remove-from-config-button" class="labeling__config-addremove-button"/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml.meta


fileFormatVersion: 2
guid: 4883c5b4a100149dabfe7832ca5a5ca6
timeCreated: 1603311500

8
com.unity.perception/Editor/GroundTruth/Uxml/AddedLabelElement.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="added-label">
<Style src="../Uss/Styles.uss"/>
<Button name="remove-button" class="labeling__remove-item-button"/>
<TextField name="label-value" class="labeling__added-label-value"/>
<Button name="add-to-config-button" class="labeling__add-to-config-button" text="Add to Label Config..."/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/AddedLabelElement.uxml.meta


fileFormatVersion: 2
guid: ab7eae2a6fad4a95ac73aa5d46704ef6
timeCreated: 1603311500

8
com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelNotPresent.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="added-label">
<Style src="../Uss/Styles.uss"/>
<Button name="remove-button" class="labeling__remove-item-button"/>
<TextField name="label-value" class="labeling__added-label-value"/>
<Button name="add-to-config-button" class="labeling__add-to-config-button" text="Add to Label Config..."/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelNotPresent.uxml.meta


fileFormatVersion: 2
guid: 5335f0007841a4aae96d6ec9e95d1b39
timeCreated: 1603311500

8
com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelPresent.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="added-label">
<Style src="../Uss/Styles.uss"/>
<Button name="remove-button" class="labeling__remove-item-button"/>
<TextField name="label-value" class="labeling__added-label-value"/>
<Button name="add-to-config-button" class="labeling__add-to-config-button" text="Add to Label Config..."/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelPresent.uxml.meta


fileFormatVersion: 2
guid: f65364e03181f4f24acd20305f6c34bb
timeCreated: 1603311500

27
com.unity.perception/Editor/GroundTruth/Uxml/Labeling_Main.uxml


<UXML xmlns="UnityEngine.UIElements">
<BindableElement class="outer-container" name="outer-container">
<Style src="../Uss/Styles.uss"/>
<VisualElement name="added-labels" class="inner-container" style="margin-top:0px">
<Label text="Added Labels" class="title-label"/>
<ListView name="current-labels-listview" class="labeling__label-listview"/>
<Button name="add-label" text="Add New Label" class="labeling__add-label-button"/>
</VisualElement>
<VisualElement name="suggested-labels" class="inner-container">
<Label text="Suggested Labels" class="title-label"/>
<VisualElement name="suggested-labels-from-name" style="padding-top: 10px;">
<Label text="Based on asset name"/>
<ListView name="suggested-labels-name-listview" class="labeling__label-listview" style="min-height: 100px;"/>
</VisualElement><VisualElement/>
<VisualElement name="suggested-labels-from-path" style="padding-top: 10px;">
<Label text="Based on asset path"/>
<ListView name="suggested-labels-path-listview" class="labeling__label-listview" style="min-height: 97px;"/>
</VisualElement><VisualElement/>
<VisualElement name="suggested-labels-from-db">
<Label text="From Perception asset database" style="padding-top: 10px;"/>
<ListView name="suggested-labels-db-listview" class="labeling__label-listview" style="min-height: 97px;"/>
</VisualElement><VisualElement/>
</VisualElement>
</BindableElement>
</UXML>

10
com.unity.perception/Editor/GroundTruth/Uxml/Labeling_Main.uxml.meta


fileFormatVersion: 2
guid: 3cef46fa678f14155a2dfb5393f41af1
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

7
com.unity.perception/Editor/GroundTruth/Uxml/SuggestedLabelElement.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="suggested-label">
<Style src="../Uss/Styles.uss"/>
<Label name="label-value" class="labeling__suggested-label-value"/>
<Button name="add-button" class="labeling__add-to-list-button" text="Add"/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/SuggestedLabelElement.uxml.meta


fileFormatVersion: 2
guid: 194f2c0998a924e0eb89baba7fa4141a
timeCreated: 1603311500

/com.unity.perception/Editor/Randomization/Icons.meta → /com.unity.perception/Editor/Icons.meta

/com.unity.perception/Editor/Randomization/Icons → /com.unity.perception/Editor/Icons

正在加载...
取消
保存