local UIBattleBossBattleInfoView = require("View/Battle/UIBattleBossBattleInfoView") local UIDemonGodBossHp = UIViewClass(UIBattleBossBattleInfoView) local ANIM_DURATION = 0.3 --不是多层血条 或者 多层血条最后一层的运动是时间 local ANIM_DURATION_QUICK = 0.1 -- 多层血条的最初血条运动时间 快速的消失 function UIDemonGodBossHp:OnOpened(context) UIUtils.SetActive(self.group_Info, false) self.hpValue1.text = "x??" self.curBossHpLayer = 10 end function UIDemonGodBossHp:OnHPChanged(hp, layerHp , entityID, delta) if entityID == self.bindingEntityID then self:DoAnimation(hp, layerHp, delta) if hp <= 0 then self:CloseView() end end end --这一段表现参考公会boss的掉血表现,实际hp无变化 function UIDemonGodBossHp:DoAnimation(hp, layerHp, delta) if not self.curHp then self.curHp = layerHp return end if delta then delta = - delta else delta = 0 end self.isDamage = delta > 0 if self.curBossHpLayer > 0 then -- 如果层数大于0 local nextLayerValue = 0 if delta - self.curHp > 0 then nextLayerValue = math.ceil( (delta - self.curHp) / layerHp) end if nextLayerValue > 0 then -- 当前伤害掉层数了 local scaleValue = (delta - self.curHp ) % layerHp / layerHp self.nextScaleValue = scaleValue --下一次动画 缩放比例 local targetDestinationPos = self.isDamage and 0 or 1 --- 因为掉层了 0.1秒把当前层缩放到0 然后在把下一层的动画开启 local playingID = self.hpAnimWithCallBack[self.curIndex] self:FinishUIAnimationByIndex(self.curIndex, false) self:FinishUIAnimationByIndex(self.curIndex, true) if playingID then self:ScaleToSize(playingID, targetDestinationPos, 1, ANIM_DURATION_QUICK) else playingID = self:ScaleToSize(self.hpGroup[self.curIndex].transform, targetDestinationPos, 1, ANIM_DURATION_QUICK, true) self.hpAnimWithCallBack[self.curIndex] = playingID end self.hpAnimWithCallBackParams[playingID] = scaleValue self.curHp = layerHp - (delta - self.curHp) else local scaleValue = (self.curHp - delta) / layerHp self.curHp = self.curHp - delta self:FinishUIAnimationByIndex(self.curIndex, true) if self.hpAnimSimple[self.curIndex] then self:ScaleToSize(self.hpAnimSimple[self.curIndex], scaleValue, 1, ANIM_DURATION) else self.hpAnimSimple[self.curIndex] = self:ScaleToSize(self.hpGroup[self.curIndex].transform, scaleValue, 1, ANIM_DURATION, false) end --将当前掉血的血条放到最上边 self.hpGroup[self.curIndex].transform:SetAsLastSibling() end end end return UIDemonGodBossHp