源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

106 行
3.2 KiB

  1. LuaState = LuaState or BaseClass(BaseView)
  2. function LuaState:__init()
  3. self.base_file = "luaState"
  4. self.layout_file = "luaState"
  5. self.layer_name = "Top"
  6. self.all_count = 0
  7. self.all_fps = 0
  8. self.server_list = {}
  9. self.load_callback = function ()
  10. self:LoadSuccess()
  11. self:InitEvent()
  12. end
  13. self.open_callback = function ()
  14. end
  15. self.close_callback = function ()
  16. end
  17. self.destroy_callback = function ()
  18. self:Remove()
  19. end
  20. end
  21. function LuaState:Remove()
  22. if self.update_id then
  23. GlobalEventSystem:UnBind(self.update_id)
  24. self.update_id = nil
  25. end
  26. if self.story_start_id then
  27. GlobalEventSystem:UnBind(self.story_start_id)
  28. self.story_start_id = nil
  29. end
  30. if self.story_finish_id then
  31. GlobalEventSystem:UnBind(self.story_finish_id)
  32. self.story_finish_id = nil
  33. end
  34. if self.scene_complete_id then
  35. GlobalEventSystem:UnBind(self.scene_complete_id)
  36. self.scene_complete_id = nil
  37. end
  38. end
  39. function LuaState:LoadSuccess()
  40. self.transform.localPosition = Vector3(-ScreenWidth / 2 + 500, ScreenHeight/2)
  41. self.memText = self:GetChild("memText"):GetComponent("Text")
  42. end
  43. function LuaState:Update(now_time, elapse_time)
  44. self:SetContent()
  45. end
  46. function LuaState:SetContent()
  47. self.all_count = self.all_count + 1
  48. self.all_fps = self.all_fps + LuaFPS.FPS
  49. local temp_str = string.format("mem: %.0f k\nmemlevel: %d\nfps: %d\navgfps: %.1f", collectgarbage("count"), SystemMemoryLevel.Cur, LuaFPS.FPS, self.all_fps/self.all_count)
  50. -- local role_angle = MainRole.role_from_camera_angle or 0
  51. -- local camera_angle = MainRole.camera_cur_angle or 0
  52. -- local temp_str = string.format("mem: %.0f k\nmemlevel: %d\nrole: %d\ncamera: %.1f", collectgarbage("count"), SystemMemoryLevel.Cur, role_angle, camera_angle)
  53. self.memText.text = "<color='#00ff00'>"..temp_str.."</color>"
  54. end
  55. function LuaState:InitEvent()
  56. local function onUpdate()
  57. self:SetContent()
  58. end
  59. self.update_id = GlobalEventSystem:Bind(EventName.SET_FPS,onUpdate)
  60. onUpdate()
  61. local function on_reset( )
  62. self.all_count = 0
  63. self.all_fps = 0
  64. self:SetContent()
  65. end
  66. self.scene_complete_id = GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE, on_reset)
  67. -- local function onStoryStart()
  68. -- local UI = panelMgr:GetParent("UI")
  69. -- self.transform:SetParent(UI)
  70. -- SetLocalScale(self.transform)
  71. -- SetAnchoredPosition(self.transform, -310,340)
  72. -- end
  73. -- self.story_start_id = GlobalEventSystem:Bind(EventName.STORY_START,onStoryStart)
  74. -- local function onStoryFinish()
  75. -- local Top = panelMgr:GetParent("Top")
  76. -- self.transform:SetParent(Top)
  77. -- SetLocalScale(self.transform)
  78. -- SetAnchoredPosition(self.transform, -310,340)
  79. -- end
  80. -- self.story_finish_id = GlobalEventSystem:Bind(EventName.STORY_FINISH,onStoryFinish)
  81. end
  82. -- function LuaState:SetContent()
  83. -- local str = [[
  84. -- <color="#00ff00">FPS:{0}</color>
  85. -- dc:{1}
  86. -- batch:{2}
  87. -- tri:{3}
  88. -- ver:{4}
  89. -- dbDC:{5}
  90. -- dbt:{6}
  91. -- ]]
  92. -- local u_stats = UnityEditor.UnityStats
  93. -- self.memText.text = string.format("lua mem:%.2fk\n", collectgarbage("count")) .. Language.substitute(str, LuaFPS.FPS, u_stats.drawCalls, u_stats.batches,
  94. -- u_stats.triangles, u_stats.vertices, u_stats.dynamicBatchedDrawCalls, u_stats.dynamicBatches)
  95. -- end