local UILuckyEggAnimView = require("UILuckyEgg/UILuckyEggAnimView_Generate") function UILuckyEggAnimView:OnAwake(data) self.controller = require("UILuckyEgg/UILuckyEggAnimCtr"):new() self.controller:Init(self) self.controller:SetData(data) end function UILuckyEggAnimView:AddEventListener() ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_CLOSE_COMPELETED, self, self.OnUICloseCompleted) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_PAGE_OUT_END_NTF, self, self.OnUIViewCloseAnimEnd) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_AGAIN_DATA_CHANGED, self, self.OnLuckyAnimAgainDataChanged) end function UILuckyEggAnimView:FillContent(data, uiBase) self.uiBase = uiBase local gameObject = self.uiBase:GetRoot() if gameObject ~= nil then self.gameObject = gameObject self.transform = gameObject.transform end self:InitGenerate(self.transform, data) self:Init() end function UILuckyEggAnimView:Init() self.againData = nil self.white:SetActive(false) self.guide:SetActive(false) if self.controller:HasNeedShowItem() then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggShow, nil, self.uiData.id) else ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggResult) end end function UILuckyEggAnimView:RemoveEventListener() ManagerContainer.LuaEventMgr:Unregister(self.uiData.name) end function UILuckyEggAnimView:AddUIEventListener() end function UILuckyEggAnimView:OnHide() end function UILuckyEggAnimView:OnShow(data) self.controller:SetData(data) end function UILuckyEggAnimView:OnClose() end function UILuckyEggAnimView:OnDispose() self.againData = nil if self.timer then self.timer:Stop() self.timer = nil end if self.openDelayTimer then self.openDelayTimer:Stop() self.openDelayTimer = nil end self.controller:OnDispose() end function UILuckyEggAnimView:OnUICloseCompleted(owner) end function UILuckyEggAnimView:OnUIViewCloseAnimEnd(id) if id == Enum.UIPageName.UILuckyEggResult then if self.againData then if not self.openDelayTimer then self.openDelayTimer = FrameTimer.New(slot(self.Init, self), 1) else self.openDelayTimer.count = Time.frameCount + 1 end if not self.openDelayTimer.running then self.openDelayTimer:Start() end self.againData = false end end end function UILuckyEggAnimView:OnLuckyAnimAgainDataChanged() self.againData = true end function UILuckyEggAnimView:OnBeginDragDrawRect() if self.eventDataHashCode then return end local currentEventData = self.drawRect.uIEventTriggerListener.currentEventData if not currentEventData then return end self.eventDataHashCode = currentEventData:GetHashCode() if self.timer.state == 2 then self.timer:Stop() end self.guide:SetActive(false) end function UILuckyEggAnimView:OnEndDragDrawRect() if not self.eventDataHashCode then return end local currentEventData = self.drawRect.uIEventTriggerListener.currentEventData if not currentEventData then return end if self.eventDataHashCode ~= currentEventData:GetHashCode() then return end self.eventDataHashCode = nil local deltaPos = currentEventData.position - currentEventData.pressPosition if Mathf.Approximately(deltaPos.y, 0) then if self.timer.state == 2 then self.timer.time = 5 self.timer.duration = 5 if not self.timer.running then self.timer:Start() end end return end self.white:SetActive(true) self.white.image:DOFade(1, 1) self.timer.state = 3 self.timer.time = 1 self.timer.duration = 1 if not self.timer.running then self.timer:Start() end end function UILuckyEggAnimView:LoadComplete() self.white:SetActive(true) self.white.image:DOFade(0, 1) self.timer.state = 1 self.timer.time = 1 self.timer.duration = 1 if not self.timer.running then self.timer:Start() end end function UILuckyEggAnimView:TimerEnd() if self.timer.state == 1 then self.white:SetActive(false) self.timer.state = 2 self.timer.time = 0 self.timer.duration = 5 if not self.timer.running then self.timer:Start() end elseif self.timer.state == 2 then self.guide:SetActive(true) self.timer:Stop() elseif self.timer.state == 3 then self.timer:Stop() if self.controller:HasNeedShowItem() then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggShow, nil, self.uiData.id) else ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggResult) end end end return UILuckyEggAnimView