DemoPage.lua.txt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --[[
  2. Tips:
  3. EffectType: LeftTop/LeftBottom/RightTop/RightBottom
  4. ]]
  5. local DemoPage = {}
  6. local function RefreshUI()
  7. local tPageInfo = {
  8. ["tImgPath"] = {
  9. "CommonUtils/Textures/Page/page0.png",
  10. "CommonUtils/Textures/Page/page1.png",
  11. "CommonUtils/Textures/Page/page2.png",
  12. "CommonUtils/Textures/Page/page3.png",
  13. "CommonUtils/Textures/Page/page4.png",
  14. "CommonUtils/Textures/Page/page5.png",
  15. },
  16. ["szImgBG"] = "CommonUtils/Textures/Page/P0_Back.png",
  17. ["szShadowLeft"] = "CommonUtils/Textures/Page/shadow.png",
  18. ["szShadowRight"] = "CommonUtils/Textures/Page/shadowLTR.png",
  19. ["nShadowWidth"] = 50,
  20. ["nEffectTime"] = 0.5,
  21. ["leftEffectType"] = "LeftBottom",
  22. ["rightEffectType"] = "RightBottom"
  23. }
  24. SetCache("PAGE_INFO", tPageInfo)
  25. local pageObj = DemoPage.rootPanel.transform:Find("Page").gameObject
  26. local uiHelper = require('Base/UIHelper.lua')
  27. local szPagePath = "CommonUtils/Page/Page.lua"
  28. uiHelper:AddScript(pageObj, szPagePath)
  29. require(szPagePath).Init()
  30. end
  31. local function CheckInput()
  32. if not CS.UnityEngine.Application.isEditor then
  33. return
  34. end
  35. local Input = CS.UnityEngine.Input
  36. local KeyCode = CS.UnityEngine.KeyCode
  37. local eventManager = require('Base/ZEventDispatchCenter.lua')
  38. if Input.GetKeyDown(KeyCode.A) then
  39. eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_PRE)
  40. return
  41. end
  42. if Input.GetKeyDown(KeyCode.D) then
  43. eventManager:DispatchEvent(eventManager.EventType.COMMON_UI_PAGE_NEXT)
  44. return
  45. end
  46. end
  47. local function OnClickBtnExit()
  48. require("Base/UIHelper.lua"):SwitchUI("CommonUtils/DemoLuaScripts/DemoAll.lua", "CommonUtils/DemoLuaScripts/DemoPage.lua")
  49. end
  50. local function RegisterTouchEvent()
  51. local uiHelper = require("Base/UIHelper.lua")
  52. local rootPanel = DemoPage.rootPanel
  53. uiHelper:AddClickEvent(rootPanel, "Btn_Exit", OnClickBtnExit)
  54. end
  55. local function UnInitPage()
  56. require("CommonUtils/Page/Page.lua").UnInit()
  57. end
  58. function DemoPage.Awake(luaRoot)
  59. DemoPage.luaRoot = luaRoot
  60. local canvas = CS.UnityEngine.GameObject.Find('Canvas')
  61. DemoPage._rootCanvas = canvas
  62. local prefabPage = LoadResource("CommonUtils/Prefabs/Demo/ZDemoPagePanel.prefab")
  63. local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabPage, canvas.transform)
  64. DemoPage.rootPanel = rootPanel
  65. end
  66. function DemoPage.Start()
  67. RefreshUI()
  68. RegisterTouchEvent()
  69. end
  70. function DemoPage.Update()
  71. CheckInput()
  72. end
  73. function DemoPage.OnDestroy()
  74. UnInitPage()
  75. CS.UnityEngine.GameObject.Destroy(DemoPage.rootPanel)
  76. end
  77. return DemoPage