浏览代码

Bounding box visualizer fix to respond to screen resize

/aisv647_visualizations
Steven Borkman 4 年前
当前提交
37a34768
共有 1 个文件被更改,包括 15 次插入4 次删除
  1. 19
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs

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


private GameObject visualizationHolder = null;
private Vector2 originalScreenSize = Vector2.zero;
/// <summary>
/// Creates a new BoundingBox2DLabeler. Be sure to assign <see cref="idLabelConfig"/> before adding to a <see cref="PerceptionCamera"/>.
/// </summary>

perceptionCamera.RenderedObjectInfosCalculated += OnRenderedObjectInfosCalculated;
visualizationEnabled = supportsVisualization;
// Record the original screen size. The screen size can change during play, and the visual bounding
// boxes need to be scaled appropriately
originalScreenSize = new Vector2(Screen.width, Screen.height);
}
/// <inheritdoc/>

{
ClearObjectPool(m_BoundingBoxValues.Length);
// The player screen can be dynamically resized during play, need to
// scale the bounding boxes appropriately from the original screen size
float screenRatioWidth = Screen.width / originalScreenSize.x;
float screenRatioHeight = Screen.height / originalScreenSize.y;
for (int i = 0; i < m_BoundingBoxValues.Length; i++)
{
var boxVal = m_BoundingBoxValues[i];

objectPool[i].GetComponentInChildren<Text>().text = label;
var rectTrans = objectPool[i].transform as RectTransform;
rectTrans.anchoredPosition = new Vector2(boxVal.x, -boxVal.y);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, boxVal.width);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, boxVal.height);
rectTrans.anchoredPosition = new Vector2(boxVal.x * screenRatioWidth, -boxVal.y * screenRatioHeight);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, boxVal.width * screenRatioWidth);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, boxVal.height * screenRatioHeight);
}
}

正在加载...
取消
保存