local PageModule = {} local EffectType = { ["LeftTop"] = "LeftTop", ["LeftBottom"] = "LeftBottom", ["RightTop"] = "RightTop", ["RightBottom"] = "RightBottom", } local currentEffectType local funPlayPageModuleEffect local function StopAllCoroutine() if funPlayPageModuleEffect then require("Base/CoroutineHelper.lua"):Stop(funPlayPageModuleEffect) end end local function CreateBottomImgUI() local rootPanel = PageModule.rootPanel local bottomImgObj = rootPanel.transform:Find("Img_Bottom") if bottomImgObj then return end bottomImgObj = CS.UnityEngine.GameObject("Img_Bottom") bottomImgObj:AddComponent(typeof(CS.UnityEngine.UI.Image)) bottomImgObj.transform:SetParent(rootPanel.transform) local rootPanelRectCom = rootPanel:GetComponent("RectTransform") local bottomImgObjRectCom = bottomImgObj:GetComponent("RectTransform") bottomImgObjRectCom.anchoredPosition = CS.UnityEngine.Vector2.zero bottomImgObjRectCom.sizeDelta = CS.UnityEngine.Vector2(rootPanelRectCom.sizeDelta.x, rootPanelRectCom.sizeDelta.y) end local function CreateMaskShowImgUI() local rootPanel = PageModule.rootPanel local maskObj = rootPanel.transform:Find("Mask").gameObject local maskShowImgObj = rootPanel.transform:Find("Mask/Img_MaskShow") if maskShowImgObj then return end maskShowImgObj = CS.UnityEngine.GameObject("Img_MaskShow") maskShowImgObj:AddComponent(typeof(CS.UnityEngine.UI.Image)) maskShowImgObj.transform:SetParent(maskObj.transform) local rootPanelRectCom = rootPanel:GetComponent("RectTransform") local maskObjRectCom = maskShowImgObj:GetComponent("RectTransform") maskObjRectCom.anchoredPosition = CS.UnityEngine.Vector2.zero maskObjRectCom.sizeDelta = CS.UnityEngine.Vector2(rootPanelRectCom.sizeDelta.x, rootPanelRectCom.sizeDelta.y) end local function CreateMaskUI() local rootPanel = PageModule.rootPanel local maskObj = rootPanel.transform:Find("Mask") if maskObj then return end maskObj = CS.UnityEngine.GameObject("Mask") maskObj:AddComponent(typeof(CS.UnityEngine.UI.Image)) maskObj:AddComponent(typeof(CS.UnityEngine.UI.Mask)) maskObj.transform:SetParent(rootPanel.transform) maskObj.transform:GetComponent("Mask").showMaskGraphic = false local rootPanelRectCom = rootPanel:GetComponent("RectTransform") local maskObjRectCom = maskObj:GetComponent("RectTransform") maskObjRectCom.anchoredPosition = CS.UnityEngine.Vector2.zero maskObjRectCom.sizeDelta = CS.UnityEngine.Vector2(rootPanelRectCom.sizeDelta.x * 2, rootPanelRectCom.sizeDelta.y) end local function CreateNextImgUI() local rootPanel = PageModule.rootPanel local nextObj = rootPanel.transform:Find("Next").gameObject local nextImgObj = nextObj.transform:Find("Img_Next") if nextImgObj then return end nextImgObj = CS.UnityEngine.GameObject("Img_Next") nextImgObj.transform:SetParent(nextObj.transform) nextImgObj:AddComponent(typeof(CS.UnityEngine.UI.Image)) nextImgObj:AddComponent(typeof(CS.UnityEngine.UI.Mask)) local rootPanelRectCom = rootPanel:GetComponent("RectTransform") local nextImgObjRectCom = nextImgObj:GetComponent("RectTransform") nextImgObjRectCom.anchoredPosition = CS.UnityEngine.Vector2.zero nextImgObjRectCom.sizeDelta = CS.UnityEngine.Vector2(rootPanelRectCom.sizeDelta.x, rootPanelRectCom.sizeDelta.y) end local function CreateShadowImgUI(szShadowImgPath, nShadowWidth) if not szShadowImgPath then return end local rootPanel = PageModule.rootPanel local nextImgObj = rootPanel.transform:Find("Next/Img_Next").gameObject local shadowImgObj = rootPanel.transform:Find("Next/Img_Next/Img_Shadow") if not shadowImgObj then shadowImgObj = CS.UnityEngine.GameObject("Img_Shadow") shadowImgObj:AddComponent(typeof(CS.UnityEngine.UI.Image)) shadowImgObj.transform:SetParent(nextImgObj.transform) end local rootPanelRectCom = rootPanel:GetComponent("RectTransform") local shadowImgObjRectCom = shadowImgObj:GetComponent("RectTransform") if not nShadowWidth then nShadowWidth = 0 end shadowImgObjRectCom.anchoredPosition = CS.UnityEngine.Vector2.zero shadowImgObjRectCom.sizeDelta = CS.UnityEngine.Vector2(nShadowWidth, rootPanelRectCom.sizeDelta.y * 2) local uiHelper = require('Base/UIHelper.lua') uiHelper:LoadSprite(shadowImgObj, szShadowImgPath, szShadowImgPath) end local function CreateNextUI() local rootPanel = PageModule.rootPanel local nextObj = rootPanel.transform:Find("Next") if nextObj then return end nextObj = CS.UnityEngine.GameObject("Next") nextObj:AddComponent(typeof(CS.UnityEngine.UI.Image)) nextObj:AddComponent(typeof(CS.UnityEngine.UI.Mask)) nextObj.transform:SetParent(rootPanel.transform) nextObj.transform:GetComponent("Mask").showMaskGraphic = false local rootPanelRectCom = rootPanel:GetComponent("RectTransform") local nextObjCom = nextObj:GetComponent("RectTransform") nextObjCom.anchoredPosition = CS.UnityEngine.Vector2.zero nextObjCom.sizeDelta = CS.UnityEngine.Vector2(rootPanelRectCom.sizeDelta.x, rootPanelRectCom.sizeDelta.y * 2) end local function RefreshBottomImgUI(szBottomImgPath) if not szBottomImgPath then return end local rootPanel = PageModule.rootPanel local bottomImgObj = rootPanel.transform:Find("Img_Bottom").gameObject local uiHelper = require('Base/UIHelper.lua') uiHelper:LoadSprite(bottomImgObj, szBottomImgPath, szBottomImgPath) end local function RefreshMaskShowImgUI(szMaskImgPath) if not szMaskImgPath then return end local rootPanel = PageModule.rootPanel local showImgObj = rootPanel.transform:Find("Mask/Img_MaskShow") local uiHelper = require('Base/UIHelper.lua') uiHelper:LoadSprite(showImgObj, szMaskImgPath, szMaskImgPath) end local function RefreshNextShowImgUI(szNextShowImgPath) if not szNextShowImgPath then return end local rootPanel = PageModule.rootPanel local nextImgObj = rootPanel.transform:Find("Next/Img_Next") local uiHelper = require('Base/UIHelper.lua') uiHelper:LoadSprite(nextImgObj, szNextShowImgPath, szNextShowImgPath) end local function GetMaskAndNextNormalizeInfo(effectType) local tMaskInfo = { ["pivot"] = nil, ["maskPosNormalize"] = nil, ["maskImgPosNormalize"] = nil, } local tNextInfo = { ["pivot"] = nil, ["nextPosNormalize"] = nil, ["nextImgPosNormalize"] = nil, ["nextShadowImgPosNormalize"] = nil, ["nextEulerAngles"] = nil, ["nextShadowEulerAngles"] = nil } if effectType == EffectType.LeftTop then tMaskInfo.pivot = CS.UnityEngine.Vector2(0, 1) tMaskInfo.maskPosNormalize = CS.UnityEngine.Vector3(-1, 1, 0) tMaskInfo.maskImgPosNormalize = CS.UnityEngine.Vector3(-1, 1, 0) tNextInfo.pivot = CS.UnityEngine.Vector2(1, 1) tNextInfo.nextPosNormalize = CS.UnityEngine.Vector3(-1, 1, 0) tNextInfo.nextImgPosNormalize = CS.UnityEngine.Vector3(1, 1, 0) tNextInfo.nextShadowImgPosNormalize = CS.UnityEngine.Vector3(1, 1, 0) tNextInfo.nextEulerAngles = CS.UnityEngine.Vector3(0, 0, 1) tNextInfo.nextShadowEulerAngles = CS.UnityEngine.Vector3(0, 0, -1) end if effectType == EffectType.LeftBottom then tMaskInfo.pivot = CS.UnityEngine.Vector2(0, 0) tMaskInfo.maskPosNormalize = CS.UnityEngine.Vector3(-1, -1, 0) tMaskInfo.maskImgPosNormalize = CS.UnityEngine.Vector3(-1, -1, 0) tNextInfo.pivot = CS.UnityEngine.Vector2(1, 0) tNextInfo.nextPosNormalize = CS.UnityEngine.Vector3(-1, -1, 0) tNextInfo.nextImgPosNormalize = CS.UnityEngine.Vector3(1, -1, 0) tNextInfo.nextShadowImgPosNormalize = CS.UnityEngine.Vector3(1, -1, 0) tNextInfo.nextEulerAngles = CS.UnityEngine.Vector3(0, 0, -1) tNextInfo.nextShadowEulerAngles = CS.UnityEngine.Vector3(0, 0, 1) end if effectType == EffectType.RightTop then tMaskInfo.pivot = CS.UnityEngine.Vector2(1, 1) tMaskInfo.maskPosNormalize = CS.UnityEngine.Vector3(1, 1, 0) tMaskInfo.maskImgPosNormalize = CS.UnityEngine.Vector3(1, 1, 0) tNextInfo.pivot = CS.UnityEngine.Vector2(0, 1) tNextInfo.nextPosNormalize = CS.UnityEngine.Vector3(1, 1, 0) tNextInfo.nextImgPosNormalize = CS.UnityEngine.Vector3(-1, 1, 0) tNextInfo.nextShadowImgPosNormalize = CS.UnityEngine.Vector3(-1, 1, 0) tNextInfo.nextEulerAngles = CS.UnityEngine.Vector3(0, 0, -1) tNextInfo.nextShadowEulerAngles = CS.UnityEngine.Vector3(0, 0, 1) end if effectType == EffectType.RightBottom then tMaskInfo.pivot = CS.UnityEngine.Vector2(1, 0) tMaskInfo.maskPosNormalize = CS.UnityEngine.Vector3(1, -1, 0) tMaskInfo.maskImgPosNormalize = CS.UnityEngine.Vector3(1, -1, 0) tNextInfo.pivot = CS.UnityEngine.Vector2(0, 0) tNextInfo.nextPosNormalize = CS.UnityEngine.Vector3(1, -1, 0) tNextInfo.nextImgPosNormalize = CS.UnityEngine.Vector3(-1, -1, 0) tNextInfo.nextShadowImgPosNormalize = CS.UnityEngine.Vector3(-1, -1, 0) tNextInfo.nextEulerAngles = CS.UnityEngine.Vector3(0, 0, 1) tNextInfo.nextShadowEulerAngles = CS.UnityEngine.Vector3(0, 0, -1) end return tMaskInfo, tNextInfo end local function SetMaskRectInfo(tMaskInfo) local rootPanel = PageModule.rootPanel local maskObj = rootPanel.transform:Find("Mask").gameObject local maskImgObj = maskObj.transform:Find("Img_MaskShow").gameObject local maskObjCom = maskObj.transform:GetComponent("RectTransform") local maskImgObjCom = maskImgObj.transform:GetComponent("RectTransform") local nMaskObjPosX = maskObjCom.sizeDelta.x * 0.5 - maskImgObjCom.sizeDelta.x * 0.5 local nMaskObjPosY = maskObjCom.sizeDelta.y * 0.5 local nMaskImgObjPosX = maskImgObjCom.sizeDelta.x local nMaskImgObjPosY = maskImgObjCom.sizeDelta.y * 0.5 local maskPosNormalize = tMaskInfo.maskPosNormalize local maskImgPosNormalize = tMaskInfo.maskImgPosNormalize maskObjCom.pivot = tMaskInfo.pivot maskImgObjCom.pivot = tMaskInfo.pivot maskObjCom.anchoredPosition3D = CS.UnityEngine.Vector3(maskPosNormalize.x * nMaskObjPosX, maskPosNormalize.y * nMaskObjPosY, maskPosNormalize.z) maskImgObjCom.anchoredPosition3D = CS.UnityEngine.Vector3(maskImgPosNormalize.x * nMaskImgObjPosX, maskImgPosNormalize.y * nMaskImgObjPosY, maskImgPosNormalize.z) maskObjCom.localEulerAngles = CS.UnityEngine.Vector3(0, 0, 0) maskImgObjCom.localEulerAngles = CS.UnityEngine.Vector3(0, 0, 0) end local function SetNextRectInfo(tNextInfo) local rootPanel = PageModule.rootPanel local nextObj = rootPanel.transform:Find("Next").gameObject local nextImgObj = nextObj.transform:Find("Img_Next").gameObject local nextShadowImgObj = nextImgObj.transform:Find("Img_Shadow") local nextObjCom = nextObj.transform:GetComponent("RectTransform") local nextImgObjCom = nextImgObj.transform:GetComponent("RectTransform") local nNextObjPosX = nextObjCom.sizeDelta.x * 0.5 local nNextObjPosY = nextObjCom.sizeDelta.y * 0.5 - nextImgObjCom.sizeDelta.y * 0.5 local nNextImgObjPosX = nextImgObjCom.sizeDelta.x * 0.5 local nNextImgObjPosY = nextImgObjCom.sizeDelta.y local nextPosNormalize = tNextInfo.nextPosNormalize local nextImgPosNormalize = tNextInfo.nextImgPosNormalize local nextEulerAngles = tNextInfo.nextEulerAngles local nextShadowEulerAngles = tNextInfo.nextShadowEulerAngles nextObjCom.pivot = tNextInfo.pivot nextImgObjCom.pivot = tNextInfo.pivot nextObjCom.anchoredPosition3D = CS.UnityEngine.Vector3(nextPosNormalize.x * nNextObjPosX, nextPosNormalize.y * nNextObjPosY, nextPosNormalize.z) nextImgObjCom.anchoredPosition3D = CS.UnityEngine.Vector3(nextImgPosNormalize.x * nNextImgObjPosX, nextImgPosNormalize.y * nNextImgObjPosY, nextImgPosNormalize.z) nextObjCom.localEulerAngles = CS.UnityEngine.Vector3(0, 0, 90 * nextEulerAngles.z) nextImgObjCom.localEulerAngles = CS.UnityEngine.Vector3(0, 0, 90 * nextEulerAngles.z) if not nextShadowImgObj then return end local nextShadowImgObjCom = nextShadowImgObj.transform:GetComponent("RectTransform") local nextShadowImgPosNormalize = tNextInfo.nextShadowImgPosNormalize local nNextShadowImgObjPosX = nextImgObjCom.sizeDelta.x * 0.5 local nNextShadowImgObjPosY = nextImgObjCom.sizeDelta.y * 0.5 nextShadowImgObjCom.pivot = tNextInfo.pivot nextShadowImgObjCom.localEulerAngles = CS.UnityEngine.Vector3(0, 0, 90 * nextShadowEulerAngles.z) nextShadowImgObjCom.anchoredPosition3D = CS.UnityEngine.Vector3(nextShadowImgPosNormalize.x * nNextShadowImgObjPosX, nextShadowImgPosNormalize.y * nNextShadowImgObjPosY, nextShadowImgPosNormalize.z) end local function PlayEffect(nEffectTime) if not nEffectTime or 0 == nEffectTime then return end if funPlayPageModuleEffect then require("Base/CoroutineHelper.lua"):Stop(funPlayPageModuleEffect) end local rootPanel = PageModule.rootPanel local maskObj = rootPanel.transform:Find("Mask").gameObject local maskImgObj = maskObj.transform:Find("Img_MaskShow").gameObject local nextObj = rootPanel.transform:Find("Next").gameObject local nextImgObj = nextObj.transform:Find("Img_Next").gameObject local shadowImgObj = nextImgObj.transform:Find("Img_Shadow") local maskObjCom = maskObj.transform:GetComponent("RectTransform") local maskImgObjCom = maskImgObj.transform:GetComponent("RectTransform") local nextObjCom = nextObj.transform:GetComponent("RectTransform") local nextImgObjCom = nextImgObj.transform:GetComponent("RectTransform") local shadowImgObjCom if shadowImgObj then shadowImgObjCom = shadowImgObj.transform:GetComponent("RectTransform") end funPlayPageModuleEffect = require("Base/CoroutineHelper.lua"):Start(function () local nOffectAngle = CS.UnityEngine.Vector3(0, 0, -90 / (nEffectTime * 1000)) local nCurrentTime = 0 while nCurrentTime <= nEffectTime do local rotateDirection if currentEffectType == EffectType.LeftBottom or currentEffectType == EffectType.RightTop then rotateDirection = 1 end if currentEffectType == EffectType.LeftTop or currentEffectType == EffectType.RightBottom then rotateDirection = -1 end maskObjCom.localEulerAngles = maskObjCom.localEulerAngles - nOffectAngle * rotateDirection maskImgObjCom.localEulerAngles = maskImgObjCom.localEulerAngles + nOffectAngle * rotateDirection nextObjCom.localEulerAngles = nextObjCom.localEulerAngles - nOffectAngle * rotateDirection nextImgObjCom.localEulerAngles = nextImgObjCom.localEulerAngles - nOffectAngle * rotateDirection if shadowImgObjCom then shadowImgObjCom.localEulerAngles = shadowImgObjCom.localEulerAngles + nOffectAngle * rotateDirection end nCurrentTime = nCurrentTime + 0.001 require("Base/CoroutineHelper.lua"):Wait(0.001) end end) end local function CreateUIItem() CreateBottomImgUI() CreateMaskUI() CreateMaskShowImgUI() CreateNextUI() CreateNextImgUI() end local function RefreshPageModuleUI(szShowImgPath, szBottomImgPath, szNextShowImgPath) RefreshMaskShowImgUI(szShowImgPath) RefreshBottomImgUI(szBottomImgPath) RefreshNextShowImgUI(szNextShowImgPath) end local function ChangeShadowImg(szShadowImgPath, nShadowWidth) local rootPanel = PageModule.rootPanel local shadowImgObj = rootPanel.transform:Find("Next/Img_Next/Img_Shadow") if not shadowImgObj then CreateShadowImgUI(szShadowImgPath, nShadowWidth) return end if nShadowWidth then local shadowImgObjRectCom = shadowImgObj:GetComponent("RectTransform") shadowImgObjRectCom.sizeDelta = CS.UnityEngine.Vector2(nShadowWidth, shadowImgObjRectCom.sizeDelta.y * 2) end local uiHelper = require('Base/UIHelper.lua') uiHelper:LoadSprite(shadowImgObj.gameObject, szShadowImgPath, szShadowImgPath) end local function RefreshMaskAndNextUI(effectType) local tMaskInfo, tNextInfo = GetMaskAndNextNormalizeInfo(effectType) SetMaskRectInfo(tMaskInfo) SetNextRectInfo(tNextInfo) end local function ChangeEffectType(effectType) currentEffectType = effectType RefreshMaskAndNextUI(effectType) end local function RefreshUI() CreateUIItem() RefreshMaskAndNextUI("LeftBottom") end local function RegisterEvent() local eventManager = require('Base/ZEventDispatchCenter.lua') eventManager:RegisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_EFFECT, PlayEffect) eventManager:RegisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_CHANGE_SHADOW_IMG, ChangeShadowImg) eventManager:RegisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_CHANGE_EFFENT_TYPE, ChangeEffectType) eventManager:RegisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_REFRESH_UI, RefreshPageModuleUI) end local function UnregisterEvent() local eventManager = require('Base/ZEventDispatchCenter.lua') eventManager:UnregisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_REFRESH_UI, RefreshPageModuleUI) eventManager:UnregisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_CHANGE_EFFENT_TYPE, ChangeEffectType) eventManager:UnregisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_CHANGE_SHADOW_IMG, ChangeShadowImg) eventManager:UnregisterEvent(eventManager.EventType.COMMON_UI_PAGE_MODULE_EFFECT, PlayEffect) end function PageModule.Awake(luaRoot) PageModule.luaRoot = luaRoot local canvas = CS.UnityEngine.GameObject.Find('Canvas') PageModule._rootCanvas = canvas PageModule.rootPanel = luaRoot end function PageModule.Init() RefreshUI() RegisterEvent() end function PageModule.UnInit() StopAllCoroutine() UnregisterEvent() end return PageModule