[关闭]
@leviyuan 2017-09-13T09:30:41.000000Z 字数 4221 阅读 364

SuperMobs.lua.ui

lua ui supermobs


使用FairyGUI引擎 http://www.fairygui.com/

资源配置管理

使用配置表来替代之前 init.lua 中配置

  • 优点:参数配置更加灵活
  • 缺点:修改配置表容易冲突,需要注意excel冲突的解决

ui界面配置表目录: trunk\Desginer\Plan\10数据表\UI配置.xlsx
主要含两个配置表

  • uipackage 负责包的参数
    image_1bpshdiic1dnl13qc13p21n1314u79.png-10.3kB

  • uiconfig 负责UI界面参数配置
    image_1bpshg3nc1df3fun9s1nv61iq91j.png-37.3kB
    parentwin 主要存在目的在于通用公共的弹窗动画,用自界面的方式添加到父界面上

举例
image_1bpshm5o2s532tm1ltbk8cu3037.png-7.7kB

UI脚本

界面脚本被闭包括起来,可以读取全局环境,但不可以直接修改全局环境,所有的global写操作都会卸载ui逻辑对象上

  1. -- 初始化界面
  2. function initcom()
  3. herobtn = getchild("pannel/herobtn") --mainview:GetChild("pannel"):GetChild("herobtn")
  4. herobtn.onClick:Add(function() -- 为按钮添加监听
  5. ui.open("hero", 1) -- 打开hero界面,并且传一个参数 1
  6. end)
  7. pvebtn = mainview:GetChild("pvebtn")
  8. end
  9. -- 界面显示出来时候调用,会接到透穿参数
  10. function show(p1, p2)
  11. print("open params", p1, p2)
  12. end
  13. -- 被关闭时调用,可选,mainview已经被释放
  14. function onclose()
  15. print("home ui closed")
  16. end
  17. -- 自定义方法
  18. function customfunc(...)
  19. end

UI管理接口

UI脚本的一些内置方法

UI对象的释放说明

  1. -- supermobs/ui/fairygui.lua
  2. -- [[
  3. 显式强转delegate类型时,为luafunction添加一层包装 tocfunc
  4. 界面关闭时,释放tocfunc与实际的luafunction之间的关联,将循环引用的闭环打破
  5. ]]
  6. -- ui auto release delegate
  7. local delegates = {"EventCallback1", "PlayCompleteCallback"}
  8. for _,dname in ipairs(delegates) do
  9. local raw = FairyGUI[dname]
  10. FairyGUI[dname] = function(func, obj)
  11. local env = getfenv(func)
  12. local tocfunc = func
  13. if env ~= _G and env.__releasefuncs then
  14. table.insert(env.__releasefuncs, function()
  15. func = nil
  16. obj = nil
  17. env = nil
  18. end)
  19. tocfunc = function(...) if func then func(...) end end
  20. end
  21. return obj == nil and raw(tocfunc) or raw(tocfunc, obj)
  22. end
  23. end
  24. -- [[
  25. 这里是一些直接赋值luafunctionc#的包装
  26. 原理与delegate相同
  27. ]]
  28. -- lua function to c#
  29. local setkey, getkey
  30. do
  31. local lud = {}
  32. for k,v in pairs(getmetatable(GLabel)) do
  33. if type(k) == "userdata" and type(v) == "table" then
  34. table.insert(lud, k)
  35. end
  36. end
  37. -- 内存地址值较小的是setkey,较大的是getkey
  38. if tonumber(tostring(lud[1]):sub(10)) < tonumber(tostring(lud[2]):sub(10)) then
  39. setkey, getkey = lud[1], lud[2]
  40. else
  41. setkey, getkey = lud[2], lud[1]
  42. end
  43. end
  44. local funcpropertys = {{GList, "itemRenderer"}, {GList, "itemProvider"}}
  45. for _,item in ipairs(funcpropertys) do
  46. local tab = getmetatable(item[1])[setkey]
  47. local rawfunc = tab[item[2]]
  48. tab[item[2]] = function(self, func)
  49. local env = getfenv(func)
  50. local tocfunc = func
  51. if env ~= _G and env.__releasefuncs then
  52. table.insert(env.__releasefuncs, function()
  53. func = nil
  54. env = nil
  55. end)
  56. tocfunc = function(...) if func then func(...) end end
  57. end
  58. return rawfunc(self, tocfunc)
  59. end
  60. end
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注