ProfilerEnableControl.cs 1.7 KB

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