Vector2 calcCanvasPosition(IHealthBarPresentation barPresentation)
{
// Converts screen point (camera coords) to canvas point.
var screenPoint = barPresentation.position();
Vector2 canvasPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(
canvasRectTransform,
screenPoint,
null,
out canvasPoint);
canvasPoint.y += hpYOffset;
return canvasPoint;
}
void LateUpdate()
{
foreach (var pair in healthBarMap)
{
var barPresentation = pair.Value.presentation;
if (Mathf.Abs(barPresentation.getCurrentHp() - barPresentation.getMaxHp()) > 0.01f && barPresentation.isVisible())
{
pair.Value.backgroundElement.anchoredPosition = calcCanvasPosition(barPresentation);
}
else
{
pair.Value.backgroundElement.anchoredPosition = new Vector2(-10000, -10000);
}
}
}