浏览代码

Object pooling for HUD entries

/aisv647_visualizations
Steven Borkman 4 年前
当前提交
8df5ba77
共有 4 个文件被更改,包括 65 次插入23 次删除
  1. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
  2. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
  3. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
  4. 74
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/HUDPanel.cs

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


if (i >= objectPool.Count)
{
objectPool.Add(GameObject.Instantiate(Resources.Load<GameObject>("BoundingBoxPrefab")));
(objectPool[i].transform as RectTransform).parent = visualizationHolder.transform;
(objectPool[i].transform as RectTransform).SetParent(visualizationHolder.transform);
}
if (!objectPool[i].activeSelf) objectPool[i].SetActive(true);

6
com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs


m_ClassCountValues = new ClassCountValue[entries.Count];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
if (visualize)
if (visualize && vizEntries == null)
if (vizEntries == null) vizEntries = new List<string>();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
vizEntries = new List<string>();
}
for (var i = 0; i < entries.Count; i++)

6
com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs


m_VisiblePixelsValues = new RenderedObjectInfoValue[renderedObjectInfos.Length];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
if (visualize)
if (visualize && vizEntries == null)
if (vizEntries == null) vizEntries = new List<string>();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
vizEntries = new List<string>();
}
for (var i = 0; i < renderedObjectInfos.Length; i++)

74
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/HUDPanel.cs


namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Heads up display panel used to publish a key value pair on the screen.
/// Heads up display panel used to publish a key value pair on the screen. Items added to this need
/// to have their values updated every frame, or else, they will be determined to be stale and removed
/// from the view and re-used for a new entry.
Dictionary<string, KeyValuePanel> entries = new Dictionary<string, KeyValuePanel>();
Dictionary<string, (bool, KeyValuePanel)> entries = new Dictionary<string, (bool, KeyValuePanel)>();
Stack<KeyValuePanel> orphans = new Stack<KeyValuePanel>();
public GameObject contentPanel = null;
public ScrollRect scrollRect = null;
public Image img = null;

i.enabled = scrollRect.enabled;
}
}
// Go through everyone that has not been updated and remove them and
// if they have been updated mark them dirty for next round
var keys = new List<string>(entries.Keys);
foreach (var key in keys)
{
var entry = entries[key];
if (!entry.Item1)
{
entry.Item2.gameObject.SetActive(false);
orphans.Push(entry.Item2);
}
else
{
entry.Item1 = false;
entries[key] = entry;
}
}
// TODO object pooling
if (!entries.ContainsKey(key))
(bool, KeyValuePanel) val;
if (!entries.ContainsKey(key))
entries[key] = GameObject.Instantiate(Resources.Load<GameObject>("KeyValuePanel")).GetComponent<KeyValuePanel>();
entries[key].SetKey(key);
entries[key].transform.SetParent(contentPanel.transform, true);
if (orphans.Any())
{
val = (true, orphans.Pop());
val.Item2.gameObject.SetActive(true);
}
else
{
val = (true, GameObject.Instantiate(Resources.Load<GameObject>("KeyValuePanel")).GetComponent<KeyValuePanel>());
val.Item2.transform.SetParent(contentPanel.transform, true);
}
val.Item2.SetKey(key);
entries[key].SetValue(value);
else
{
val = entries[key];
val.Item1 = true;
}
val.Item2.SetValue(value);
entries[key] = val;
}
/// <summary>

{
if (entries.ContainsKey(key))
{
var pair = entries[key];
var entry = entries[key];
entry.Item2.gameObject.SetActive(false);
pair.transform.SetParent(null);
Destroy(pair.gameObject);
orphans.Push(entry.Item2);
/// Removes all of the list of keys from the HUD
/// Removes all of the passed in entries from the HUD
{
foreach (var k in keys) RemoveEntry(k);
}
/// <summary>
/// Removes all of the passed in entries from the HUD
/// </summary>
public void RemoveEntries(string[] keys)
{
foreach (var k in keys) RemoveEntry(k);
}
正在加载...
取消
保存