ProfilerEnableControl.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. namespace SRDebugger.UI.Controls
  2. {
  3. using Internal;
  4. using SRF;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. #if UNITY_5_5_OR_NEWER
  8. using UnityEngine.Profiling;
  9. #endif
  10. public class ProfilerEnableControl : SRMonoBehaviourEx
  11. {
  12. private bool _previousState;
  13. [RequiredField] public Text ButtonText;
  14. [RequiredField] public UnityEngine.UI.Button EnableButton;
  15. [RequiredField] public Text Text;
  16. protected override void Start()
  17. {
  18. base.Start();
  19. if (!Profiler.supported)
  20. {
  21. Text.text = SRDebugStrings.Current.Profiler_NotSupported;
  22. EnableButton.gameObject.SetActive(false);
  23. enabled = false;
  24. return;
  25. }
  26. if (!Application.HasProLicense())
  27. {
  28. Text.text = SRDebugStrings.Current.Profiler_NoProInfo;
  29. EnableButton.gameObject.SetActive(false);
  30. enabled = false;
  31. return;
  32. }
  33. UpdateLabels();
  34. }
  35. protected void UpdateLabels()
  36. {
  37. if (!Profiler.enabled)
  38. {
  39. Text.text = SRDebugStrings.Current.Profiler_EnableProfilerInfo;
  40. ButtonText.text = "Enable";
  41. }
  42. else
  43. {
  44. Text.text = SRDebugStrings.Current.Profiler_DisableProfilerInfo;
  45. ButtonText.text = "Disable";
  46. }
  47. _previousState = Profiler.enabled;
  48. }
  49. protected override void Update()
  50. {
  51. base.Update();
  52. if (Profiler.enabled != _previousState)
  53. {
  54. UpdateLabels();
  55. }
  56. }
  57. public void ToggleProfiler()
  58. {
  59. Debug.Log("Toggle Profiler");
  60. Profiler.enabled = !Profiler.enabled;
  61. }
  62. }
  63. }