RKGlobalFpsModule.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityEngine;
  2. namespace Rokid.UXR.Module
  3. {
  4. public class RKGlobalFpsModule : MonoSingleton<RKGlobalFpsModule>
  5. {
  6. #if !UNITY_EDITOR
  7. private const string SYS_PROP_OPM_FUNC_CONFIG = "persist.sys.rokid.opm.config";
  8. private const int FUNC_NONE = 0;
  9. private const int FUNC_SERVICE_START = 0x08000000;
  10. private const int FUNC_FPS = 0x00000001;
  11. private static int currentFuncConfig = 0;
  12. #endif
  13. private GameObject fpsCanvas;
  14. private bool isActived = false;
  15. protected override void OnSingletonInit()
  16. {
  17. base.OnSingletonInit();
  18. this.gameObject.name = "RKGlobalFpsModule";
  19. DontDestroyOnLoad(transform);
  20. RKLog.Info("RKGlobalFpsModule OnSingletonInit init");
  21. }
  22. protected override void OnDestroy()
  23. {
  24. base.OnDestroy();
  25. RKLog.Info("RKGlobalFpsModule OnDestroy");
  26. }
  27. public bool IsEnableAPM()
  28. {
  29. bool result = false;
  30. #if !UNITY_EDITOR
  31. try
  32. {
  33. var systemProperties = new AndroidJavaClass("android.os.SystemProperties");
  34. string prop = systemProperties.CallStatic<string >("get", SYS_PROP_OPM_FUNC_CONFIG);
  35. if (!string.IsNullOrEmpty(prop)) {
  36. currentFuncConfig = int.Parse(prop);
  37. }
  38. result = (currentFuncConfig & FUNC_SERVICE_START) == FUNC_SERVICE_START;
  39. RKLog.Info("RKGlobalFpsModule IsEnableAPM prop="+prop+", currentFuncConfig = "+ currentFuncConfig + ", result="+result);
  40. }
  41. catch (System.Exception e)
  42. {
  43. RKLog.Error("RKGlobalFpsModule IsEnableAPM error = "+ e.Message);
  44. }
  45. #endif
  46. return result;
  47. }
  48. public void DestroyInstance()
  49. {
  50. RKLog.Info("RKGlobalFpsModule DestroyInstance");
  51. if (fpsCanvas != null)
  52. {
  53. Destroy(fpsCanvas);
  54. }
  55. Destroy(gameObject);
  56. }
  57. public void SetActive(bool active)
  58. {
  59. RKLog.Info("RKGlobalFpsModule SetActive active="+active);
  60. if (active)
  61. {
  62. if (!isActived)
  63. {
  64. fpsCanvas = Instantiate(Resources.Load<GameObject>("Prefabs/UI/UIComponents/RKFPSCanvas"));
  65. fpsCanvas?.transform.SetParent(transform);
  66. isActived = true;
  67. }
  68. }
  69. else
  70. {
  71. isActived = false;
  72. DestroyInstance();
  73. }
  74. }
  75. }
  76. }