83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using UnityEngine;
|
|
|
|
public class HUDBase : MyCoroutine
|
|
{
|
|
protected RectTransform m_RectTransform, m_CanvasRect;
|
|
protected Transform m_Target;
|
|
protected Camera m_Camera;
|
|
|
|
protected float OffTime;
|
|
|
|
bool isRect = false, isCanvasRect = false, isMainCam = false, isTarget = false;
|
|
|
|
void Init()
|
|
{
|
|
if (!isRect)
|
|
{
|
|
m_RectTransform = GetComponent<RectTransform>();
|
|
isRect = m_RectTransform;
|
|
}
|
|
if (!isCanvasRect)
|
|
{
|
|
m_CanvasRect = GetComponentInParent<Canvas>().GetComponent<RectTransform>();
|
|
isCanvasRect = m_CanvasRect;
|
|
}
|
|
if (!isMainCam)
|
|
{
|
|
m_Camera = Camera.main;
|
|
isMainCam = m_Camera;
|
|
}
|
|
}
|
|
|
|
public void Set_Target(Transform _target)
|
|
{
|
|
Init();
|
|
m_Target = _target;
|
|
isTarget = m_Target;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (isTarget && isCanvasRect && isMainCam)
|
|
{
|
|
Vector2 ViewportPosition = m_Camera.WorldToViewportPoint(m_Target.position);
|
|
Vector2 WorldObject_ScreenPosition = new Vector2(
|
|
(ViewportPosition.x * m_CanvasRect.sizeDelta.x) - (m_CanvasRect.sizeDelta.x * 0.5f),
|
|
(ViewportPosition.y * m_CanvasRect.sizeDelta.y) - (m_CanvasRect.sizeDelta.y * 0.5f) - 15f);
|
|
m_RectTransform.anchoredPosition = WorldObject_ScreenPosition;
|
|
}
|
|
|
|
if (OffTime > 0f)
|
|
{
|
|
OffTime -= Time.deltaTime;
|
|
if (OffTime <= 0f)
|
|
Off(false);
|
|
}
|
|
}
|
|
|
|
public static string Get_TextColor(eAttackType _attacktype)
|
|
{
|
|
switch (_attacktype)
|
|
{
|
|
default:
|
|
case eAttackType.Physics:
|
|
return "<color=#FFFFFF>";
|
|
case eAttackType.Magic:
|
|
return "<color=#FF8B8B>";
|
|
case eAttackType.Pure:
|
|
return "<color=#F53B96>";
|
|
}
|
|
}
|
|
|
|
public void Off(bool deltarget)
|
|
{
|
|
gameObject.SetActive(false);
|
|
if (deltarget)
|
|
{
|
|
m_Target = null;
|
|
isTarget = false;
|
|
}
|
|
Init();
|
|
m_RectTransform.anchoredPosition = Vector3.one * 10000f; // 멀리 보내야 다음에 켜질 때 깜빡임 없어짐
|
|
}
|
|
} |