private void LateUpdate()
{
bool isTargetVisible;
Vector3 screenLocationCamera;
Vector3 screenLocationUI;
for (int i = 0; i < ActiveMarkers.Count; i++)
{
screenLocationCamera = Cam.WorldToScreenPoint(ActiveMarkers[i].Location.position);
if (isPixelating)
{
float recalcualted = 1 / Faker.instance.pixelizationCoeff;
screenLocationUI = new Vector3(screenLocationCamera.x * recalcualted, screenLocationCamera.y * recalcualted, screenLocationCamera.z);
}
else
{
screenLocationUI = screenLocationCamera;
}
isTargetVisible = screenLocationUI.z > 0 && screenLocationUI.x > OffsetX && screenLocationUI.x < MaxxPos && screenLocationUI.y > OffsetYBottom && screenLocationUI.y < MaxyPos;
if (isTargetVisible)
{
if (ActiveMarkers[i].EdgeIcon != null)
{
if (Images[i].MainImage.sprite != ActiveMarkers[i].Icon)
{
Images[i].MainImage.sprite = ActiveMarkers[i].Icon;
}
}
screenLocationUI.z = 0;
Images[i].MainTransform.position = screenLocationUI;
}
else
{
if (ActiveMarkers[i].EdgeIcon != null)
{
if (Images[i].MainImage.sprite != ActiveMarkers[i].EdgeIcon)
{
Images[i].MainImage.sprite = ActiveMarkers[i].EdgeIcon;
}
}
if (screenLocationUI.z < 0)
{
screenLocationUI *= -1;
}
screenLocationUI -= screenCentre;
float angle = Mathf.Atan2(screenLocationUI.y, screenLocationUI.x);
float slope = Mathf.Tan(angle);
if (screenLocationUI.x > 0)
{
screenLocationUI = new Vector3(screenCentre.x - OffsetX, (screenCentre.x - OffsetX) * slope, 0);
}
else
{
screenLocationUI = new Vector3(- (screenCentre.x - OffsetX), - (screenCentre.x - OffsetX) * slope, 0);
}
if (screenLocationUI.y > (screenCentre.y - OffsetYTop))
{
screenLocationUI = new Vector3((screenCentre.y - OffsetYTop) / slope, screenCentre.y - OffsetYTop, 0);
}
else if (screenLocationUI.y < -(screenCentre.y - OffsetYBottom))
{
screenLocationUI = new Vector3(-(screenCentre.y - OffsetYBottom) / slope, -(screenCentre.y - OffsetYBottom), 0);
}
screenLocationUI += screenCentre;
Images[i].MainTransform.position = screenLocationUI;
}
if (ActiveMarkers[i].isDistancable)
{
float size = ActiveMarkers[i].normalSizeDistance/Vector3.Distance(ActiveMarkers[i].Location.position, Cam.transform.position);
size = Mathf.Clamp(size, ActiveMarkers[i].minScale, ActiveMarkers[i].maxScale);
Images[i].MainTransform.localScale = new Vector3(size, size, 0);
}
if (ActiveMarkers[i].stage != -1)
{
if (ActiveMarkers[i].stage == 1)
{
Images[i].SizeTransform.localScale = Vector3.Lerp(new Vector3(AlertIconsManager.instance.spawnedAlertScale, AlertIconsManager.instance.spawnedAlertScale), Vector3.one, ActiveMarkers[i].SpentTime / AlertIconsManager.instance.timeToNormal);
ActiveMarkers[i].SpentTime += Time.deltaTime;
if (ActiveMarkers[i].SpentTime >= AlertIconsManager.instance.timeToNormal)
{
ActiveMarkers[i].SpentTime = 0;
Images[i].SizeTransform.localScale = Vector3.one;
ActiveMarkers[i].stage = -1;
}
}
if (ActiveMarkers[i].stage == 2)
{
Images[i].MainImage.color = Color.Lerp(AlertIconsManager.instance.normalColor, AlertIconsManager.instance.hiddenColor, ActiveMarkers[i].SpentTime / AlertIconsManager.instance.timeToDissapearAfterShooting);
ActiveMarkers[i].SpentTime += Time.deltaTime;
if (ActiveMarkers[i].SpentTime >= AlertIconsManager.instance.timeToDissapearAfterShooting)
{
ActiveMarkers[i].SpentTime = 0;
Images[i].MainImage.color = AlertIconsManager.instance.hiddenColor;
ActiveMarkers[i].stage = -1;
}
}
}
}
}