GlobalFunctions.lua.txt 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. GlobalFunctions = GlobalFunctions or {}
  2. function ShowNotice(info)
  3. local uiControllerPath = "UI/Public/ZUITextNotice.lua"
  4. require("Base/UIHelper.lua"):OpenUI(uiControllerPath)
  5. require(uiControllerPath).NoticeInfo(info)
  6. end
  7. function ShowDialogOK(szParent, tips, confirmFunction)
  8. local canvas = CS.UnityEngine.GameObject.Find("Canvas")
  9. local dialogOK = canvas.transform:Find("ZUIDialogOKPanel")
  10. local uiControllerPath = "UI/Public/ZUIPanelDialogOK.lua"
  11. if dialogOK then
  12. require("Base/UIHelper.lua"):CloseUI(uiControllerPath)
  13. end
  14. require(uiControllerPath).szParent = szParent
  15. require("Base/UIHelper.lua"):OpenUI(uiControllerPath)
  16. require(uiControllerPath).SetInfo(tips, confirmFunction)
  17. end
  18. function ShowDialogConfirm(szParent, tips, confirmFunction, cancelFunction)
  19. local canvas = CS.UnityEngine.GameObject.Find("Canvas")
  20. local dialogConfirm = canvas.transform:Find("ZUIDialogConfirmPanel")
  21. local uiControllerPath = "UI/Public/ZUIPanelDialogConfirm.lua"
  22. if dialogConfirm then
  23. require("Base/UIHelper.lua"):CloseUI(uiControllerPath)
  24. end
  25. require(uiControllerPath).szParent = szParent
  26. require("Base/UIHelper.lua"):OpenUI(uiControllerPath)
  27. require(uiControllerPath).SetInfo(tips, confirmFunction, cancelFunction)
  28. end
  29. function Debug(...)
  30. CS.UnityEngine.Debug.Log(...)
  31. end
  32. function Debugf(format, ...)
  33. CS.UnityEngine.Debug.Log(string.format(format, ...))
  34. end
  35. function Warn(...)
  36. CS.UnityEngine.Debug.LogWarning(...)
  37. end
  38. function Warnf(format, ...)
  39. CS.UnityEngine.Debug.LogWarning(string.format(format, ...))
  40. end
  41. function LoadResource(resPath)
  42. --Warnf("---- ----> isEditor: %s Path: %s", tostring(CS.UnityEngine.Application.isEditor), resPath)
  43. if CS.UnityEngine.Application.isEditor == true then
  44. return CS.SFramework.SResourceManagerE.LoadResource(resPath)
  45. else
  46. return CS.SFramework.SResourceManagerR.LoadResource(resPath)
  47. end
  48. end
  49. function GetCache(key, value)
  50. local dataRelay = require("Base/DataRelay.lua")
  51. local cache = dataRelay:GetCache(dataRelay.KEY_TYPE[key], value)
  52. return cache
  53. end
  54. function SetCache(key, value)
  55. local dataRelay = require("Base/DataRelay.lua")
  56. dataRelay:SetCache(dataRelay.KEY_TYPE[key], value)
  57. end
  58. function PrintTable(tab, csp)
  59. local szTabel = require("Base/Utils.lua"):Table2String(tab, csp)
  60. print(szTabel)
  61. end
  62. local function __TRACKBACK__(szErrorMsg)
  63. local szTrackText = debug.traceback(tostring(szErrorMsg), 6);
  64. print("---------------------------------------- TRACKBACK ----------------------------------------");
  65. print(szTrackText, "LUA ERROR");
  66. print("---------------------------------------- TRACKBACK ----------------------------------------");
  67. local szExceptionText = "LUA EXCEPTION\n" .. szTrackText;
  68. --[[Error("---------------------------------------- TRACKBACK ----------------------------------------");
  69. Error(szTrackText .. " LUA ERROR");
  70. Error("---------------------------------------- TRACKBACK ----------------------------------------");
  71. Error(szExceptionText)]]
  72. CS.UnityEngine.Debug.LogWarning(szExceptionText)
  73. return false;
  74. end
  75. function SafeCall(fnFunc, ...)
  76. local tArgs = { ... };
  77. return xpcall(function() return fnFunc(table.unpack(tArgs)) end, __TRACKBACK__);
  78. end