local UIBroadcast = UIViewClass() --中部跑马灯配置 local SCROLLING_SPEED = DataSheetManager.ConstData:GetDataByID("BroadcastSpeed").IntValue local END_DELAY_TIME = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("BroadcastEndSeconds").FloatValue) local ANIMATION_END_TIME = 0.1 function UIBroadcast:OnOpened() self:RegistSystemEvent(EventID.UI_Broadcast_CutCurrentBroadcast, self.BreakCurrentBroadcast) self:RegistSystemEvent(EventID.UI_Broadcast_UpdateBroadcast, self.RecoverBroadcast) self:RegistSystemEvent(EventID.TimeLine_Update, self.OnTimeLineActive) -- 设置表情大小 UIUtils.SetEmojiTextEmojiRatio(self.scrollingText, 1) self.imgTf = self.img_Bg.transform self.bgLength = self.ScrollingBg:GetSizeDelta() local msg = MDL.Broadcast.GetBroadcastMsg() if msg then self:ShowBroadcastMsg(msg) end end function UIBroadcast:OnClosed() self:StopCurrentBroadcastMsg() end function UIBroadcast:OnTimeLineActive(value) UIUtils.SetActive(self.imgTf, value) end function UIBroadcast:BreakCurrentBroadcast() self:StopCurrentBroadcastMsg() self:StopRepeatFunc(self.RefreshBroadcast) self:ShowBroadcastMsg(MDL.Broadcast.GetBroadcastMsg()) end function UIBroadcast:RecoverBroadcast() --判断当前是否正在广播消息,如果有则直接返回 if CTL.Broadcast.GetExistedBroadcastMsg() then return end local broadcastMsg = MDL.Broadcast.GetBroadcastMsg() if broadcastMsg then self:ShowBroadcastMsg(broadcastMsg) self:PlayShowAnim() end end function UIBroadcast:RefreshBroadcast(deltaTime, timeSinceUpdate) local msg = MDL.Broadcast.GetBroadcastMsg() if msg then self:StopCurrentBroadcastMsg() self:ShowBroadcastMsg(msg) else self:StopRepeatFunc(self.RefreshBroadcast) self:PlayEndAnim() end end function UIBroadcast:ShowBroadcastMsg(broadcastMsg) self:PlayShowAnim() self:SetBroadcastMsg(broadcastMsg) MDL.Broadcast.RemoveBroadcastMsg() end function UIBroadcast:SetBroadcastMsg(textData) if textData then local objLength = self.scrollingText:PlayBroadcastMsg(textData.content, SCROLLING_SPEED, 0, self.bgLength) local deltaLength = objLength > self.bgLength and objLength or self.bgLength local deltaTime = deltaLength / SCROLLING_SPEED local requireTime = deltaTime + END_DELAY_TIME + ANIMATION_END_TIME CTL.Broadcast.SetExistedBroadcastMsg(textData) self:StartRepeatFunc(self.RefreshBroadcast, requireTime, 1) else self:RefreshBroadcast() end end function UIBroadcast:StopCurrentBroadcastMsg() if CTL.Broadcast.GetExistedBroadcastMsg() then self.scrollingText:StopBroadcastMsg() CTL.Broadcast.ClearExistedBroadcastMsg() end end function UIBroadcast:PlayShowAnim() if self.animShow then self:PlayUIAnimation(self.animShow) else self.animShow = self:PlayUIAnimation("BroadcastShow") end end function UIBroadcast:PlayEndAnim() local _, sy = self.imgTf:GetLocalScale() if sy ~= 0 then if self.animEnd then self:PlayUIAnimation(self.animEnd) else self.animEnd = self:PlayUIAnimation("BroadcastEnd", true) end end end function UIBroadcast:OnUIAnimationStoped(playingID) if playingID == self.animEnd then self:StopCurrentBroadcastMsg() end end return UIBroadcast