123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using Adon.Game.BO;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class MonHpBarAdon : MonoBehaviour
- {
- public Transform target; // 3D目标
- public Transform ui; // 2D UI
- private Vector3 originOff; // 当前UI系统(0,0)点 相对于屏幕左下角(0, 0)点的偏移量
- public BaseMonsterAdon m_Owner;
- public Image m_hpBar1;
- public Image m_hpBar2;
- private void Start()
- {
- originOff = new Vector3(-Screen.width / 2, -Screen.height / 2);
- Reposition();
- }
- private void Update()
- {
- // 需要性能优化 仅在物体移动或相机移动后调用即可
- Reposition();
- }
- // 根据目标物体 重定位UI
- private void Reposition()
- {
- Vector3 position = Camera.main.WorldToScreenPoint(target.position) + originOff;
- position.z = 0;
- ui.localPosition = position;
- }
- //public void RefreshHpGauge()
- //{
- // float statusBase = this.m_Owner.GetStatusBase(EnumDefine.BaseStatT.HP);//获取血量
- // if (statusBase < 0)
- // statusBase = 0;
- // float mhp = this.m_Owner.GetStatusBase(EnumDefine.BaseStatT.MHP);//获取最大血量
- // float num = statusBase / mhp;//血条百分比
- // m_hpBar1.fillAmount = num;
- // m_hpBar2.fillAmount = num;
- //}
- }
|