SUIFPS.lua.txt 956 B

123456789101112131415161718192021222324252627282930313233343536
  1. local SUIFPS = {}
  2. local nTime = 0
  3. local nFrameCount = 0
  4. local function UpdateFPS()
  5. local textFpsCom = SUIFPS.rootPanel.transform:GetComponent("Text")
  6. nTime = nTime + CS.UnityEngine.Time.unscaledDeltaTime;
  7. nFrameCount = nFrameCount + 1
  8. if (nTime >= 1 and nFrameCount >= 1) then
  9. local fps = nFrameCount / nTime
  10. nTime = 0;
  11. nFrameCount = 0;
  12. textFpsCom.text = string.format("fps_1: %.2f", fps);
  13. end
  14. end
  15. function SUIFPS.Awake(luaRoot)
  16. SUIFPS.luaRoot = luaRoot
  17. local canvas = CS.UnityEngine.GameObject.Find("Canvas")
  18. SUIFPS._rootCanvas = canvas
  19. local prefabPanelGaming = LoadResource("Prefabs/UI/SUIFPS.prefab")
  20. local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabPanelGaming, SUIFPS._rootCanvas.transform)
  21. SUIFPS.rootPanel = rootPanel
  22. CS.UnityEngine.Object.DontDestroyOnLoad(SUIFPS.rootPanel)
  23. end
  24. function SUIFPS.Update()
  25. UpdateFPS()
  26. end
  27. return SUIFPS