--[[ Tips: EffectType: LeftTop/LeftBottom/RightTop/RightBottom ]] local DemoPagePoster = {} local funPagePoster local nPosterTime = 2 -- 轮播时间 local function StopAllCoroutine() if funPagePoster then require("Base/CoroutineHelper.lua"):Stop(funPagePoster) end end local function RefreshUI() local tPageInfo = { ["tImgPath"] = { "CommonUtils/Textures/Page/page0.png", "CommonUtils/Textures/Page/page1.png", "CommonUtils/Textures/Page/page2.png", "CommonUtils/Textures/Page/page3.png", "CommonUtils/Textures/Page/page4.png", "CommonUtils/Textures/Page/page5.png", }, ["szImgBG"] = "CommonUtils/Textures/Page/P0_Back.png", ["szShadowLeft"] = "CommonUtils/Textures/Page/shadow.png", ["szShadowRight"] = "CommonUtils/Textures/Page/shadowLTR.png", ["nShadowWidth"] = 50, ["nEffectTime"] = 0.5, ["leftEffectType"] = "LeftBottom", ["rightEffectType"] = "RightBottom" } local tPagePosterTagInfo = { ['szTarget'] = "CommonUtils/Textures/PagePoster/light.png", ['szNoramal'] = "CommonUtils/Textures/PagePoster/normal.png", } SetCache("PAGE_INFO", tPageInfo) SetCache("PAGE_POSTER_TAG_INFO", tPagePosterTagInfo) local pageObj = DemoPagePoster.rootPanel.transform:Find("Poster/Page").gameObject local tagObj = DemoPagePoster.rootPanel.transform:Find("Poster/Tag").gameObject local uiHelper = require('Base/UIHelper.lua') local szPagePath = "CommonUtils/Page/Page.lua" local szPagePosterPath = "CommonUtils/Page/PagePoster.lua" uiHelper:AddScript(pageObj, szPagePath) uiHelper:AddScript(tagObj, szPagePosterPath) require(szPagePath).Init() require(szPagePosterPath).Init() end local function UnInitPagePoster() require("CommonUtils/Page/Page.lua").UnInit() require("CommonUtils/Page/PagePoster.lua").UnInit() end local function StartPosterCoroutine() funPagePoster = require("Base/CoroutineHelper.lua"):Start(function () while true do require("Base/CoroutineHelper.lua"):Wait(nPosterTime) local eventManager = require('Base/ZEventDispatchCenter.lua') eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_NEXT) end end) end local function CheckInput() if not CS.UnityEngine.Application.isEditor then return end local Input = CS.UnityEngine.Input local KeyCode = CS.UnityEngine.KeyCode local eventManager = require('Base/ZEventDispatchCenter.lua') if Input.GetKeyDown(KeyCode.A) then StopAllCoroutine() eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_PRE) StartPosterCoroutine() return end if Input.GetKeyDown(KeyCode.D) then StopAllCoroutine() eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_NEXT) StartPosterCoroutine() return end end local function OnClickBtnExit() require("Base/UIHelper.lua"):SwitchUI("CommonUtils/DemoLuaScripts/DemoAll.lua", "CommonUtils/DemoLuaScripts/DemoPagePoster.lua") end local function RegisterTouchEvent() local uiHelper = require("Base/UIHelper.lua") local rootPanel = DemoPagePoster.rootPanel uiHelper:AddClickEvent(rootPanel, "Btn_Exit", OnClickBtnExit) end function DemoPagePoster.Awake(luaRoot) DemoPagePoster.luaRoot = luaRoot local canvas = CS.UnityEngine.GameObject.Find('Canvas') DemoPagePoster._rootCanvas = canvas local prefabDemoPosterPage = LoadResource("CommonUtils/Prefabs/Demo/ZDemoPagePosterPanel.prefab") local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabDemoPosterPage, canvas.transform) DemoPagePoster.rootPanel = rootPanel end function DemoPagePoster.Start() RefreshUI() StartPosterCoroutine() RegisterTouchEvent() end function DemoPagePoster.Update() CheckInput() end function DemoPagePoster.OnDestroy() UnInitPagePoster() StopAllCoroutine() CS.UnityEngine.GameObject.Destroy(DemoPagePoster.rootPanel) end return DemoPagePoster