DebuggerComponent.ScreenInformationWindow.cs 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using UnityEngine;
  9. namespace UnityGameFramework.Runtime
  10. {
  11. public sealed partial class DebuggerComponent : GameFrameworkComponent
  12. {
  13. private sealed class ScreenInformationWindow : ScrollableDebuggerWindowBase
  14. {
  15. protected override void OnDrawScrollableWindow()
  16. {
  17. GUILayout.Label("<b>Screen Information</b>");
  18. GUILayout.BeginVertical("box");
  19. {
  20. DrawItem("Current Resolution", GetResolutionString(Screen.currentResolution));
  21. DrawItem("Screen Width", Utility.Text.Format("{0} px / {1} in / {2} cm", Screen.width.ToString(), Utility.Converter.GetInchesFromPixels(Screen.width).ToString("F2"), Utility.Converter.GetCentimetersFromPixels(Screen.width).ToString("F2")));
  22. DrawItem("Screen Height", Utility.Text.Format("{0} px / {1} in / {2} cm", Screen.height.ToString(), Utility.Converter.GetInchesFromPixels(Screen.height).ToString("F2"), Utility.Converter.GetCentimetersFromPixels(Screen.height).ToString("F2")));
  23. DrawItem("Screen DPI", Screen.dpi.ToString("F2"));
  24. DrawItem("Screen Orientation", Screen.orientation.ToString());
  25. DrawItem("Is Full Screen", Screen.fullScreen.ToString());
  26. #if UNITY_2018_1_OR_NEWER
  27. DrawItem("Full Screen Mode", Screen.fullScreenMode.ToString());
  28. #endif
  29. DrawItem("Sleep Timeout", GetSleepTimeoutDescription(Screen.sleepTimeout));
  30. #if UNITY_2019_2_OR_NEWER
  31. DrawItem("Brightness", Screen.brightness.ToString("F2"));
  32. #endif
  33. DrawItem("Cursor Visible", Cursor.visible.ToString());
  34. DrawItem("Cursor Lock State", Cursor.lockState.ToString());
  35. DrawItem("Auto Landscape Left", Screen.autorotateToLandscapeLeft.ToString());
  36. DrawItem("Auto Landscape Right", Screen.autorotateToLandscapeRight.ToString());
  37. DrawItem("Auto Portrait", Screen.autorotateToPortrait.ToString());
  38. DrawItem("Auto Portrait Upside Down", Screen.autorotateToPortraitUpsideDown.ToString());
  39. #if UNITY_2017_2_OR_NEWER && !UNITY_2017_2_0
  40. DrawItem("Safe Area", Screen.safeArea.ToString());
  41. #endif
  42. #if UNITY_2019_2_OR_NEWER
  43. DrawItem("Cutouts", GetCutoutsString(Screen.cutouts));
  44. #endif
  45. DrawItem("Support Resolutions", GetResolutionsString(Screen.resolutions));
  46. }
  47. GUILayout.EndVertical();
  48. }
  49. private string GetSleepTimeoutDescription(int sleepTimeout)
  50. {
  51. if (sleepTimeout == SleepTimeout.NeverSleep)
  52. {
  53. return "Never Sleep";
  54. }
  55. if (sleepTimeout == SleepTimeout.SystemSetting)
  56. {
  57. return "System Setting";
  58. }
  59. return sleepTimeout.ToString();
  60. }
  61. private string GetResolutionString(Resolution resolution)
  62. {
  63. return Utility.Text.Format("{0} x {1} @ {2}Hz", resolution.width.ToString(), resolution.height.ToString(), resolution.refreshRate.ToString());
  64. }
  65. private string GetCutoutsString(Rect[] cutouts)
  66. {
  67. string[] cutoutStrings = new string[cutouts.Length];
  68. for (int i = 0; i < cutouts.Length; i++)
  69. {
  70. cutoutStrings[i] = cutouts[i].ToString();
  71. }
  72. return string.Join("; ", cutoutStrings);
  73. }
  74. private string GetResolutionsString(Resolution[] resolutions)
  75. {
  76. string[] resolutionStrings = new string[resolutions.Length];
  77. for (int i = 0; i < resolutions.Length; i++)
  78. {
  79. resolutionStrings[i] = GetResolutionString(resolutions[i]);
  80. }
  81. return string.Join("; ", resolutionStrings);
  82. }
  83. }
  84. }
  85. }