浏览代码

Aisv760 editor bugs - fixes for 759, 760, 761 (#58)

* Multiple object editing

* Remove indents from inspector

* Fix to commit changes on a prefab labeling edit

* Responsive label editing

Fix so that add label does not lock up

* Labeling editor fixes

* Remove placeholder text

Hopefully only temporary, but it seems to be almost impossible to get placeholder text to work in current gui implementation
/main
GitHub 4 年前
当前提交
6a3e1041
共有 1 个文件被更改,包括 77 次插入10 次删除
  1. 87
      com.unity.perception/Editor/GroundTruth/LabelingEditor.cs

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


using Unity.Entities;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;

[CustomEditor(typeof(Labeling))]
[CustomEditor(typeof(Labeling)), CanEditMultipleObjects]
const int k_Indent = 7;
ReorderableList m_LabelsList;
public void OnEnable()

m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
m_LabelsList.onReorderCallbackWithDetails += OnReordered;
labeling.labels.RemoveAt(list.index);
{
var value = labeling.labels[list.index];
foreach (var t in targets)
{
((Labeling)t).labels.Remove(value);
}
}
}
Labeling labeling => (Labeling)target;

labeling.labels.Add("");
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)

var indent = k_Indent * index;
if (indent >= rect.width)
return;
var contentRect = new Rect(rect.x, rect.y, rect.width, rect.height);
var value = EditorGUI.DelayedTextField(contentRect, labeling.labels[index]);
var contentRect = new Rect(rect.x + indent, rect.y, rect.width - indent, rect.height);
var value = EditorGUI.TextField(contentRect, labeling.labels[index]);
labeling.labels[index] = value;
ReplaceLabelAll(index, value);
if (PrefabUtility.IsPartOfAnyPrefab(target))
{
EditorUtility.SetDirty(target);
}
}
}
}

正在加载...
取消
保存