Vector2 calcCanvasPosition IHealthBarPresentati on barPresentation Con

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}
}
}