| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 | using Common.Utility.CombatEvent;using Core.Language;using Fort23.Core;using Fort23.UTool;using GameLogic.Combat.Buff;using UnityEngine;namespace Fort23.Mono{    [UIBinding(prefab = "HeroHpWidget")]    public partial class HeroHpWidget : UIComponent    {        public CombatHeroEntity combatHeroEntity;        private Transform hpTransform;        public int size = 100;        public int shieldSize = 50;        public bool isFollowTarget = true;        private BetterList<BuffWidget> buBetterList = new BetterList<BuffWidget>();        private void Init()        {        }        public override void AddEvent()        {        }        public override void DelEvent()        {        }        public override void AddButtonEvent()        {        }        public override void DormancyObj()        {            CombatEventManager.Instance.RemoveEventListener(CombatEventType.HeroHpUpdate, HeroHpUpdateEventData);            CombatEventManager.Instance.RemoveEventListener(CombatEventType.ClearHeroHp, ClearHeroHp);            CombatEventManager.Instance.RemoveEventListener(CombatEventType.HeroDie, HeroDie);            CombatEventManager.Instance.RemoveEventListener(CombatEventType.AddBuff,                AddBuff);            CombatEventManager.Instance.RemoveEventListener(CombatEventType.RemoveBuff,                RemoveBuff);            StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);            for (int i = 0; i < buBetterList.Count; i++)            {                UIManager.Instance.DormancyGComponent(buBetterList[i]);            }            buBetterList.Clear();            base.DormancyObj();        }        private async void RemoveBuff(IEventData iEventData)        {            BuffEventData buffEventData = iEventData as BuffEventData;            if (buffEventData.target == combatHeroEntity)            {                for (int i = 0; i < buBetterList.Count; i++)                {                    BuffWidget buffWidget = buBetterList[i];                    if (buffWidget.buffBasic == buffEventData.BuffBasic)                    {                        UIManager.Instance.DormancyGComponent(buffWidget);                        buBetterList.RemoveAt(i);                    }                }            }        }        private async void AddBuff(IEventData iEventData)        {            BuffEventData buffEventData = iEventData as BuffEventData;            if (buffEventData.target == combatHeroEntity && !buffEventData.isSuperimposing)            {                BuffBasic buffBasic = buffEventData.BuffBasic;                BuffWidget buffWidget = await UIManager.Instance.CreateGComponent<BuffWidget>(null, buffRoot);                buffWidget.InitBuff(buffBasic);                buBetterList.Add(buffWidget);            }        }        private void HeroHpUpdateEventData(IEventData iEventData)        {            HeroHpUpdateEventData heroHpUpdateEventData = iEventData as HeroHpUpdateEventData;            if (heroHpUpdateEventData.combatHeroEntity == combatHeroEntity)            {                UpdateHp();            }        }        private void UpdateHp()        {            float v = (combatHeroEntity.CurrCombatHeroInfo.hp.Value * 1f) /                      combatHeroEntity.MaxCombatHeroInfo.hp.Value;            v = Mathf.Clamp(v, 0, 1);            // if (v < 0.99f && !transform.gameObject.activeSelf)            // {            //     transform.gameObject.SetActive(true);            // }            hp.rectTransform.sizeDelta = new Vector2(v * size, hp.rectTransform.sizeDelta.y);            if (combatHeroEntity.MaxCombatHeroInfo.Shield.Value > 0)            {                float v2 = (combatHeroEntity.CurrCombatHeroInfo.Shield.Value * 1f) /                           combatHeroEntity.MaxCombatHeroInfo.Shield.Value;                v2 = Mathf.Clamp(v2, 0, 1);                shield.rectTransform.sizeDelta = new Vector2(v2 * shieldSize, shield.rectTransform.sizeDelta.y);            }            else            {                shield.rectTransform.sizeDelta = new Vector2(0, shield.rectTransform.sizeDelta.y);            }        }        private void ClearHeroHp(IEventData iEventData)        {            HeroHpUpdateEventData heroHpUpdateEventData = iEventData as HeroHpUpdateEventData;            if (heroHpUpdateEventData.combatHeroEntity == combatHeroEntity)            {                if (string.IsNullOrEmpty(poolObjName))                {                    return;                }                GObjectPool.Instance.Recycle(this);            }        }        private void HeroDie(IEventData iEventData)        {            HeroDieEventData heroHpUpdateEventData = iEventData as HeroDieEventData;            if (heroHpUpdateEventData.combatHeroEntity == combatHeroEntity)            {                for (int i = 0; i < buBetterList.Count; i++)                {                    UIManager.Instance.DormancyGComponent(buBetterList[i]);                }                buBetterList.Clear();                if (string.IsNullOrEmpty(poolObjName))                {                    return;                }                GObjectPool.Instance.Recycle(this);            }        }        public void Init(CombatHeroEntity combatHeroEntity)        {            this.combatHeroEntity = combatHeroEntity;            CombatEventManager.Instance.AddEventListener(CombatEventType.HeroHpUpdate, HeroHpUpdateEventData);            CombatEventManager.Instance.AddEventListener(CombatEventType.ClearHeroHp, ClearHeroHp);            CombatEventManager.Instance.AddEventListener(CombatEventType.HeroDie, HeroDie);            CombatEventManager.Instance.AddEventListener(CombatEventType.AddBuff,                AddBuff);            CombatEventManager.Instance.AddEventListener(CombatEventType.RemoveBuff,                RemoveBuff);            StaticUpdater.Instance.AddRenderUpdateCallBack(Update);            hpTransform = combatHeroEntity.combatHeroGameObject.hpTransform;            // transform.gameObject.SetActive(false);            jy.SetActive(false);            if (playerLevel != null)            {                if (combatHeroEntity.IsEnemy)                {                    playerLevel.text =                        LanguageManager.Instance.Text(combatHeroEntity.CurrCombatHeroInfo.MonsterPowerUpConfig.jingjie1)                        + LanguageManager.Instance.Text(combatHeroEntity.CurrCombatHeroInfo.MonsterPowerUpConfig                            .jingjie2)                        + LanguageManager.Instance.Text(combatHeroEntity.CurrCombatHeroInfo.MonsterPowerUpConfig                            .jingjie3);                }                else                {                    if (combatHeroEntity.CurrCombatHeroInfo.powerUpConfig.jingjieLanIDs != null)                    {                        playerLevel.text =                            LanguageManager.Instance.Text(                                combatHeroEntity.CurrCombatHeroInfo.powerUpConfig.jingjieLanIDs[0])                            + LanguageManager.Instance.Text(                                combatHeroEntity.CurrCombatHeroInfo.powerUpConfig.jingjieLanIDs[1]) +                            combatHeroEntity.CurrCombatHeroInfo.powerUpConfig.jingjie3;                    }                    else                    {                        playerLevel.text = "";                    }                }            }            if (combatHeroEntity.CurrCombatHeroInfo.Shield > 0)            {                ShieldsRoot.SetActive(true);            }            else            {                ShieldsRoot.SetActive(false);            }            UpdateHp();            Update();        }        private void Update()        {            for (int i = 0; i < buBetterList.Count; i++)            {                bool isoK = buBetterList[i].Update();                if (!isoK)                {                    UIManager.Instance.DormancyGComponent(buBetterList[i]);                    buBetterList.RemoveAt(i);                }            }            if (!isFollowTarget)            {                return;            }            Vector3 worldPos = hpTransform.position;            Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(worldPos);            Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);            transform.position = p2;        }    }}
 |