local UIFunctionNoticeMain = UIViewClass() local PATH = "Movie/%s" local FunctionDisplayType = { None = 0, Texture = 1, Movie = 2 } local Movie_Scale_Y = 1 local OFFSET_TIME = 0.3 function UIFunctionNoticeMain:OnCreated() self.controller_Movie:SetAndroidOESEnabled(true) end function UIFunctionNoticeMain:OnOpened(context) if UNITY_ANDROID then Movie_Scale_Y = 1 else Movie_Scale_Y = -1 end self:RegistSystemEvent(EventID.UI_UpdateFunctionUnlockAward, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_UpdateFunctionNoticeUnlock, self.UpdateArrowState) self.hasAddMovieCall = false local funcID = context and context[1] or math.max(MDL.FunctionNotice.GetNextFuncID(), MDL.FunctionNotice.GetCurFuncID()) self:InitInfo(funcID) end function UIFunctionNoticeMain:InitInfo(fucID) self.state_RewardTips:SetState(1) if self.isPlaying == true then self.controller_Movie:StopMovie(false) if self.ScheduleDisappear then self:StopUIAnimation(self.ScheduleDisappear) end end self.curShowID = fucID self.funcConfig = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(fucID) if self.funcConfig.FunctionDisplayType == FunctionDisplayType.Texture then self.group_Function:SetState(1) UIUtils.SetImageByAssetBundle(self.img_FunctionImage, self.funcConfig.DisplayID) elseif self.funcConfig.FunctionDisplayType == FunctionDisplayType.Movie then if self.hasAddMovieCall == false then self.controller_Movie:AddStartCallBack(function() self:OnMovieStart() end) self.controller_Movie:AddFinishCallBack(function() self:OnMovieStop() end) self.hasAddMovieCall = true end self.group_Function:SetState(0) self.videoImgState = false self.img_FunctionVideo.transform:SetLocalScale(0, Movie_Scale_Y, 1) self.isPlaying = false self.img_Schedule.fillAmount = 0 self.movieCurTime = 0 self.state_Video:SetState(2) self.state_Suspend:SetState(1) if self.ScheduleGrow == nil then self.ScheduleGrow = self:PlayUIAnimation("ScheduleGrow") else self:PlayUIAnimation(self.ScheduleGrow) end self.txt_Time.text = "00:00/00:00" local volume = CTL.Setting.GetSoundVolume() self.controller_Movie:PlayMovie(string.format(PATH, self.funcConfig.DisplayID), volume) end --美术字 if self.loc_Name.CurState == 0 then UIUtils.SetLocalizationImage(self.img_FunctionText, self.funcConfig.ArtText) self.img_FunctionText:SetNativeSize() else self.loc_Name:SetText(2,UIUtils.GetLocalizedTxt(Const_IDS[self.funcConfig.FunctionName])) end --文字描述 self.lab_FunctionInfo.text = MDL.Unlock.GetUnlockContent(self.funcConfig.FucID, self.funcConfig.FunctionDes) --箭头逻辑 self:UpdateArrowState() --箱子逻辑 self:UpdateBoxState() end function UIFunctionNoticeMain:OnUpdateFun(deltaTime, timeSinceUpdate) if self.isPlaying then self.movieCurTime = self.movieCurTime + deltaTime if self.movieCurTime < self.movieTotalTime then local lastProgress = self.img_Schedule.fillAmount local progress = self.movieCurTime / self.movieTotalTime if progress >= lastProgress then self.img_Schedule.fillAmount = progress local timeStr = UTL.Time.FormatTimeSeconds(self.movieCurTime) self.txt_Time.text = timeStr .. "/" .. self.movieTotalTimeStr end --加个延时显示视频贴图,防止闪白 if self.videoImgState == false and timeSinceUpdate >= OFFSET_TIME then self.videoImgState = true self.img_FunctionVideo.transform:SetLocalScale(1, Movie_Scale_Y, 1) end end end end --视频暂停后恢复或者开始播放都会执行 function UIFunctionNoticeMain:OnMovieStart() local movieTotalTime = self.controller_Movie:GetDurationTime() self.movieTotalTimeStr = UTL.Time.FormatTimeSeconds(movieTotalTime) self.movieTotalTime = movieTotalTime self.movieCurTime = self.controller_Movie:GetCurrentTime() self.isPlaying = true self:StartRepeatFunc(self.OnUpdateFun, 0) end --视频暂停或者播完都会执行回调 function UIFunctionNoticeMain:OnMovieStop() self.isPlaying = false self.movieCurTime = self.controller_Movie:GetCurrentTime() self.img_Schedule.fillAmount = self.movieCurTime / self.movieTotalTime local timeStr = UTL.Time.FormatTimeSeconds(self.movieCurTime) self.txt_Time.text = timeStr .. "/" .. self.movieTotalTimeStr self.state_Video:SetState(1) if self.ScheduleDisappear == nil then self.ScheduleDisappear = self:PlayUIAnimation("ScheduleDisappear") else self:PlayUIAnimation(self.ScheduleDisappear) end self:StopRepeatFunc(self.OnUpdateFun) end function UIFunctionNoticeMain:UpdateArrowState() local next = math.max(MDL.FunctionNotice.GetNextFuncID(), MDL.FunctionNotice.GetCurFuncID()) if self.curShowID < next then UIUtils.SetActive(self.btn_ArrowR, true) --箭头红点:后边有未领就显示 local isRed = MDL.FunctionNotice.GetIfUnAwardAfter(self.curShowID + 1) self.btn_ArrowR:SetRedPoint(isRed) else UIUtils.SetActive(self.btn_ArrowR, false) end if self.curShowID > MDL.FunctionNotice.GetFirstFuncID() then UIUtils.SetActive(self.btn_ArrowL, true) --箭头红点:前边有未领就显示 local isRed = MDL.FunctionNotice.GetIfUnAwardBefore(self.curShowID - 1) self.btn_ArrowL:SetRedPoint(isRed) else UIUtils.SetActive(self.btn_ArrowL, false) end end function UIFunctionNoticeMain:UpdateBoxState() if MDL.Unlock.IsUnlock(self.funcConfig.FucID) then if MDL.FunctionNotice.GetIfUnAward(self.curShowID) then self.state_box:SetState(1) self.btn_Box:SetRedPoint(true) else self.state_box:SetState(0) self.btn_Box:SetRedPoint(false) end else self.state_box:SetState(2) self.btn_Box:SetRedPoint(false) end end function UIFunctionNoticeMain:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIFunctionNoticeMain:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Box then if MDL.Unlock.IsUnlock(self.funcConfig.FucID) and MDL.FunctionNotice.GetIfUnAward(self.curShowID) then --直接领取 MDL.FunctionNotice.UnlockFunctionRewardReq(self.curShowID) else self.state_RewardTips:SetState(0) local itemData = self.funcConfig.Item_Table for i = 1, #itemData do local item = self.group_Item[i] if item then UIUtils.SetActive(item.gameObject.transform.parent, true) UTL.Item.SetItemCell(item, itemData[i].ItemID, itemData[i].ItemNum) end end for i = #itemData + 1, #self.group_Item do local item = self.group_Item[i] if item then UIUtils.SetActive(item.gameObject.transform.parent, false) end end end elseif comp == self.btn_CloseReward then self.state_RewardTips:SetState(1) elseif comp == self.btn_Suspend or comp == self.btn_Video then if self.movieTotalTime == nil then return end self.isPlaying = not self.isPlaying if self.isPlaying then self.state_Suspend:SetState(1) self.state_Video:SetState(2) if self.movieCurTime >= self.movieTotalTime then self.img_Schedule.fillAmount = 0 local timeStr = UTL.Time.FormatTimeSeconds(0) self.txt_Time.text = timeStr .. "/" .. self.movieTotalTimeStr if self.ScheduleGrow == nil then self.ScheduleGrow = self:PlayUIAnimation("ScheduleGrow") else self:PlayUIAnimation(self.ScheduleGrow) end --3更的旧包如果配置了视频类型,视频无法播放,表现上是错误的,但是不报错。这里加个保护,防止报错 self.controller_Movie:ReplayMovie() else self.controller_Movie:ResumeMovie() end else self.state_Suspend:SetState(0) self.controller_Movie:PauseMovie() self.state_Video:SetState(0) self:StopRepeatFunc(self.OnUpdateFun) end elseif comp == self.btn_ArrowR then local curShowID = MDL.FunctionNotice.GetPreviewNextID(self.curShowID) self:InitInfo(curShowID) elseif comp == self.btn_ArrowL then local curShowID = MDL.FunctionNotice.GetPreviewBeforeID(self.curShowID) self:InitInfo(curShowID) else for i = 1, #self.group_Item do local item = self.group_Item[i] if item.event_Click == comp then local itemData = self.funcConfig.Item_Table[i] UTL.ItemTips.ShowCommonTipsById(itemData.ItemID) break end end end end function UIFunctionNoticeMain:UpdateInfo() if MDL.FunctionNotice.GetIfShowEntry() then local nextId = MDL.FunctionNotice.GetShowFuncID() if nextId > self.curShowID then self:InitInfo(nextId) end self:UpdateArrowState() self:UpdateBoxState() else self:CloseView() end end return UIFunctionNoticeMain