MonHpBarAdon.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Adon.Game.BO;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class MonHpBarAdon : MonoBehaviour
  7. {
  8. public Transform target; // 3D目标
  9. public Transform ui; // 2D UI
  10. private Vector3 originOff; // 当前UI系统(0,0)点 相对于屏幕左下角(0, 0)点的偏移量
  11. public BaseMonsterAdon m_Owner;
  12. public Image m_hpBar1;
  13. public Image m_hpBar2;
  14. private void Start()
  15. {
  16. originOff = new Vector3(-Screen.width / 2, -Screen.height / 2);
  17. Reposition();
  18. }
  19. private void Update()
  20. {
  21. // 需要性能优化 仅在物体移动或相机移动后调用即可
  22. Reposition();
  23. }
  24. // 根据目标物体 重定位UI
  25. private void Reposition()
  26. {
  27. Vector3 position = Camera.main.WorldToScreenPoint(target.position) + originOff;
  28. position.z = 0;
  29. ui.localPosition = position;
  30. }
  31. //public void RefreshHpGauge()
  32. //{
  33. // float statusBase = this.m_Owner.GetStatusBase(EnumDefine.BaseStatT.HP);//获取血量
  34. // if (statusBase < 0)
  35. // statusBase = 0;
  36. // float mhp = this.m_Owner.GetStatusBase(EnumDefine.BaseStatT.MHP);//获取最大血量
  37. // float num = statusBase / mhp;//血条百分比
  38. // m_hpBar1.fillAmount = num;
  39. // m_hpBar2.fillAmount = num;
  40. //}
  41. }