53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
public class HUDBase : MyCoroutine
|
|
{
|
|
protected RectTransform m_RectTransform, m_CanvasRect;
|
|
protected Transform m_Target;
|
|
protected Camera m_Camera;
|
|
|
|
void Init()
|
|
{
|
|
if (m_RectTransform == null) m_RectTransform = GetComponent<RectTransform>();
|
|
if (m_CanvasRect == null) m_CanvasRect = GetComponentInParent<Canvas>().GetComponent<RectTransform>();
|
|
if (m_Camera == null) m_Camera = Camera.main;
|
|
}
|
|
|
|
public void Set_Target(Transform _target)
|
|
{
|
|
Init();
|
|
m_Target = _target;
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
if (m_Target && m_CanvasRect && m_Camera)
|
|
{
|
|
RectTransform CanvasRect = m_CanvasRect;
|
|
Vector2 ViewportPosition = m_Camera.WorldToViewportPoint(m_Target.position);
|
|
Vector2 WorldObject_ScreenPosition = new Vector2((ViewportPosition.x * CanvasRect.sizeDelta.x) - (CanvasRect.sizeDelta.x * 0.5f), (ViewportPosition.y * CanvasRect.sizeDelta.y) - (CanvasRect.sizeDelta.y * 0.5f) - 15f);
|
|
m_RectTransform.anchoredPosition = WorldObject_ScreenPosition;
|
|
}
|
|
}
|
|
|
|
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()
|
|
{
|
|
gameObject.SetActive(false);
|
|
Init();
|
|
m_RectTransform.anchoredPosition = Vector3.one * 10000f; // 멀리 보내야 다음에 켜질 때 깜빡임 없어짐
|
|
}
|
|
} |