local UIBroadcastUp = UIViewClass() --顶部跑马灯配置 local SCROLLING_SPEED = DataSheetManager.ConstData:GetDataByID("BroadCastSpeedHigh").IntValue local START_SHOW_TIME = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("BroadcastStartSeconds").FloatValue) local END_DELAY_TIME = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("BroadcastEndSeconds").FloatValue) local ANIMATION_END_TIME = 0.1 function UIBroadcastUp:OnOpened(context) self:RegistSystemEvent(EventID.UI_Broadcast_CutCurrentBroadcastTop, self.BreakCurrentBroadcast) self:RegistSystemEvent(EventID.UI_Broadcast_UpdateBroadcastTop, self.RecoverBroadcast) self:RegistSystemEvent(EventID.UI_Broadcast_RecoverBroadcastTop, self.RecoverBroadcast) self:RegistSystemEvent(EventID.UI_Broadcast_UpdateGM, self.BreakCurrentBroadcastByGM) self:RegistSystemEvent(EventID.TimeLine_Update, self.OnTimeLineActive) -- 设置表情大小 UIUtils.SetEmojiTextEmojiRatio(self.scrollingText.gameObject:GetComponent(typeof(UnityEngine.UI.Text)), 1) self.imgTf = self.img_Bg.transform self.bgLength = self.ScrollingBg:GetSizeDelta() local msg = MDL.Broadcast.GetBroadcastMsg_Top() if msg and not CTL.Broadcast.GetExistedBroadcastGM() then self:ShowBroadcastMsg(msg) end end function UIBroadcastUp:OnClosed() self:StopCurrentBroadcastMsg() end function UIBroadcastUp:OnTimeLineActive(value) UIUtils.SetActive(self.imgTf, value) end function UIBroadcastUp:BreakCurrentBroadcast() self:StopCurrentBroadcastMsg() self:ShowBroadcastMsg(MDL.Broadcast.GetBroadcastMsg_Top()) end function UIBroadcastUp:BreakCurrentBroadcastByGM() self:StopCurrentBroadcastMsg(true) end function UIBroadcastUp:RecoverBroadcast() --判断当前是否正在广播消息,如果有则直接返回 if CTL.Broadcast.GetExistedBroadcastMsg_Top() or CTL.Broadcast.GetExistedBroadcastGM() then return end local broadcastMsg = MDL.Broadcast.GetBroadcastMsg_Top() if broadcastMsg then self:ShowBroadcastMsg(broadcastMsg) self:PlayShowAnim() end end function UIBroadcastUp:RefreshBroadcast(deltaTime, timeSinceUpdate) local msg = MDL.Broadcast.GetBroadcastMsg_Top() if msg and not CTL.Broadcast.GetExistedBroadcastGM() then self:StopCurrentBroadcastMsg() self:ShowBroadcastMsg(msg) else self:StopRepeatFunc(self.RefreshBroadcast) self:PlayEndAnim() end end function UIBroadcastUp:ShowBroadcastMsg(broadcastMsg) self:PlayShowAnim() self:SetBroadcastMsg(broadcastMsg) MDL.Broadcast.RemoveBroadcastMsg_Top() end function UIBroadcastUp:SetBroadcastMsg(textData) if textData then local objLength = self.scrollingText:PlayBroadcastMsg(textData.content, SCROLLING_SPEED, START_SHOW_TIME, self.bgLength) local deltaLength = objLength - self.bgLength < 0 and 0 or objLength - self.bgLength local deltaTime = deltaLength / SCROLLING_SPEED local requireTime = deltaTime + START_SHOW_TIME + END_DELAY_TIME + ANIMATION_END_TIME CTL.Broadcast.SetExistedBroadcastMsg_Top(textData) self:StartRepeatFunc(self.RefreshBroadcast, requireTime, 1) else self:RefreshBroadcast() end end function UIBroadcastUp:StopCurrentBroadcastMsg(isBreakByGM) if CTL.Broadcast.GetExistedBroadcastMsg_Top() then self.scrollingText:StopBroadcastMsg() CTL.Broadcast.ClearExistedBroadcastMsg_Top() if isBreakByGM then self:PlayEndAnim() end end end function UIBroadcastUp:PlayShowAnim() if self.animShow then self:PlayUIAnimation(self.animShow) else self.animShow = self:PlayUIAnimation("BroadcastShow") end end function UIBroadcastUp: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 UIBroadcastUp:OnUIAnimationStoped(playingID) if playingID == self.animEnd then self:StopCurrentBroadcastMsg() end end return UIBroadcastUp