DemoToast.lua.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --[[
  2. Tips:
  3. 1. open default toast img
  4. require("CommonUtils/Toast/Toast.lua").ToastInfo()
  5. 2. open specified toast img
  6. local szPath = "CommonUtils/Textures/Toast/prompt.png"
  7. require("CommonUtils/Toast/Toast.lua").ToastInfo(szPath)
  8. ]]
  9. local DemoToast = {}
  10. local function OnClickBtnShowToast()
  11. print("----> DemoToast.OnClickBtnShowToast")
  12. local szPath = "CommonUtils/Textures/Toast/prompt.png"
  13. require("CommonUtils/Toast/Toast.lua").ToastInfo(szPath)
  14. end
  15. local function OnClickBtnExit()
  16. require("Base/UIHelper.lua"):SwitchUI("CommonUtils/DemoLuaScripts/DemoAll.lua", "CommonUtils/DemoLuaScripts/DemoToast.lua")
  17. end
  18. local function RegisterTouchEvent()
  19. local uiHelper = require("Base/UIHelper.lua")
  20. local rootPanel = DemoToast.rootPanel
  21. uiHelper:AddClickEvent(rootPanel, "Btn_ShowToast", OnClickBtnShowToast)
  22. uiHelper:AddClickEvent(rootPanel, "Btn_Exit", OnClickBtnExit)
  23. end
  24. function DemoToast.Awake(luaRoot)
  25. DemoToast.luaRoot = luaRoot
  26. local canvas = CS.UnityEngine.GameObject.Find('Canvas')
  27. DemoToast._rootCanvas = canvas
  28. local prefabTest = LoadResource('CommonUtils/Prefabs/Demo/ZDemoToastPanel.prefab')
  29. local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabTest, canvas.transform)
  30. DemoToast.rootPanel = rootPanel
  31. end
  32. function DemoToast.Start()
  33. RegisterTouchEvent()
  34. end
  35. function DemoToast.OnDestroy()
  36. CS.UnityEngine.GameObject.Destroy(DemoToast.rootPanel)
  37. end
  38. return DemoToast