71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ZoneUI : MonoBehaviour
|
|
{
|
|
public CaptureZone zone;
|
|
public Slider progressSlider;
|
|
public Text labelText;
|
|
public Image fillImage;
|
|
public Camera targetCamera;
|
|
|
|
public Color neutralColor = Color.gray;
|
|
public Color playerColor = new Color(0.2f, 0.45f, 1f);
|
|
public Color enemyColor = new Color(1f, 0.2f, 0.15f);
|
|
public Color contestedColor = new Color(1f, 0.82f, 0.08f);
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (zone == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (progressSlider != null)
|
|
{
|
|
progressSlider.value = zone.GetProgress();
|
|
}
|
|
|
|
Color color = GetColorForZone();
|
|
if (fillImage != null)
|
|
{
|
|
fillImage.color = color;
|
|
}
|
|
|
|
if (labelText != null)
|
|
{
|
|
labelText.text = zone.zoneName + ": " + zone.GetOwner();
|
|
labelText.color = color;
|
|
}
|
|
|
|
Camera cameraToUse = targetCamera != null ? targetCamera : Camera.main;
|
|
if (cameraToUse != null)
|
|
{
|
|
transform.rotation = Quaternion.LookRotation(transform.position - cameraToUse.transform.position, Vector3.up);
|
|
}
|
|
}
|
|
|
|
private Color GetColorForZone()
|
|
{
|
|
CaptureZone.CaptureState state = zone.GetCaptureState();
|
|
if (state == CaptureZone.CaptureState.Contested ||
|
|
state == CaptureZone.CaptureState.CapturingByPlayer ||
|
|
state == CaptureZone.CaptureState.CapturingByEnemy)
|
|
{
|
|
return contestedColor;
|
|
}
|
|
|
|
if (zone.GetOwner() == CaptureZone.Owner.Player)
|
|
{
|
|
return playerColor;
|
|
}
|
|
|
|
if (zone.GetOwner() == CaptureZone.Owner.Enemy)
|
|
{
|
|
return enemyColor;
|
|
}
|
|
|
|
return neutralColor;
|
|
}
|
|
}
|