DemoPagePoster.lua.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. --[[
  2. Tips:
  3. EffectType: LeftTop/LeftBottom/RightTop/RightBottom
  4. ]]
  5. local DemoPagePoster = {}
  6. local funPagePoster
  7. local nPosterTime = 2 -- 轮播时间
  8. local function StopAllCoroutine()
  9. if funPagePoster then require("Base/CoroutineHelper.lua"):Stop(funPagePoster) end
  10. end
  11. local function RefreshUI()
  12. local tPageInfo = {
  13. ["tImgPath"] = {
  14. "CommonUtils/Textures/Page/page0.png",
  15. "CommonUtils/Textures/Page/page1.png",
  16. "CommonUtils/Textures/Page/page2.png",
  17. "CommonUtils/Textures/Page/page3.png",
  18. "CommonUtils/Textures/Page/page4.png",
  19. "CommonUtils/Textures/Page/page5.png",
  20. },
  21. ["szImgBG"] = "CommonUtils/Textures/Page/P0_Back.png",
  22. ["szShadowLeft"] = "CommonUtils/Textures/Page/shadow.png",
  23. ["szShadowRight"] = "CommonUtils/Textures/Page/shadowLTR.png",
  24. ["nShadowWidth"] = 50,
  25. ["nEffectTime"] = 0.5,
  26. ["leftEffectType"] = "LeftBottom",
  27. ["rightEffectType"] = "RightBottom"
  28. }
  29. local tPagePosterTagInfo = {
  30. ['szTarget'] = "CommonUtils/Textures/PagePoster/light.png",
  31. ['szNoramal'] = "CommonUtils/Textures/PagePoster/normal.png",
  32. }
  33. SetCache("PAGE_INFO", tPageInfo)
  34. SetCache("PAGE_POSTER_TAG_INFO", tPagePosterTagInfo)
  35. local pageObj = DemoPagePoster.rootPanel.transform:Find("Poster/Page").gameObject
  36. local tagObj = DemoPagePoster.rootPanel.transform:Find("Poster/Tag").gameObject
  37. local uiHelper = require('Base/UIHelper.lua')
  38. local szPagePath = "CommonUtils/Page/Page.lua"
  39. local szPagePosterPath = "CommonUtils/Page/PagePoster.lua"
  40. uiHelper:AddScript(pageObj, szPagePath)
  41. uiHelper:AddScript(tagObj, szPagePosterPath)
  42. require(szPagePath).Init()
  43. require(szPagePosterPath).Init()
  44. end
  45. local function UnInitPagePoster()
  46. require("CommonUtils/Page/Page.lua").UnInit()
  47. require("CommonUtils/Page/PagePoster.lua").UnInit()
  48. end
  49. local function StartPosterCoroutine()
  50. funPagePoster = require("Base/CoroutineHelper.lua"):Start(function ()
  51. while true do
  52. require("Base/CoroutineHelper.lua"):Wait(nPosterTime)
  53. local eventManager = require('Base/ZEventDispatchCenter.lua')
  54. eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_NEXT)
  55. end
  56. end)
  57. end
  58. local function CheckInput()
  59. if not CS.UnityEngine.Application.isEditor then
  60. return
  61. end
  62. local Input = CS.UnityEngine.Input
  63. local KeyCode = CS.UnityEngine.KeyCode
  64. local eventManager = require('Base/ZEventDispatchCenter.lua')
  65. if Input.GetKeyDown(KeyCode.A) then
  66. StopAllCoroutine()
  67. eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_PRE)
  68. StartPosterCoroutine()
  69. return
  70. end
  71. if Input.GetKeyDown(KeyCode.D) then
  72. StopAllCoroutine()
  73. eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_NEXT)
  74. StartPosterCoroutine()
  75. return
  76. end
  77. end
  78. local function OnClickBtnExit()
  79. require("Base/UIHelper.lua"):SwitchUI("CommonUtils/DemoLuaScripts/DemoAll.lua", "CommonUtils/DemoLuaScripts/DemoPagePoster.lua")
  80. end
  81. local function RegisterTouchEvent()
  82. local uiHelper = require("Base/UIHelper.lua")
  83. local rootPanel = DemoPagePoster.rootPanel
  84. uiHelper:AddClickEvent(rootPanel, "Btn_Exit", OnClickBtnExit)
  85. end
  86. function DemoPagePoster.Awake(luaRoot)
  87. DemoPagePoster.luaRoot = luaRoot
  88. local canvas = CS.UnityEngine.GameObject.Find('Canvas')
  89. DemoPagePoster._rootCanvas = canvas
  90. local prefabDemoPosterPage = LoadResource("CommonUtils/Prefabs/Demo/ZDemoPagePosterPanel.prefab")
  91. local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabDemoPosterPage, canvas.transform)
  92. DemoPagePoster.rootPanel = rootPanel
  93. end
  94. function DemoPagePoster.Start()
  95. RefreshUI()
  96. StartPosterCoroutine()
  97. RegisterTouchEvent()
  98. end
  99. function DemoPagePoster.Update()
  100. CheckInput()
  101. end
  102. function DemoPagePoster.OnDestroy()
  103. UnInitPagePoster()
  104. StopAllCoroutine()
  105. CS.UnityEngine.GameObject.Destroy(DemoPagePoster.rootPanel)
  106. end
  107. return DemoPagePoster