DebuggerComponent.SettingsWindow.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 UnityEngine;
  8. namespace UnityGameFramework.Runtime
  9. {
  10. public sealed partial class DebuggerComponent : GameFrameworkComponent
  11. {
  12. private sealed class SettingsWindow : ScrollableDebuggerWindowBase
  13. {
  14. private DebuggerComponent m_DebuggerComponent = null;
  15. private SettingComponent m_SettingComponent = null;
  16. private float m_LastIconX = 0f;
  17. private float m_LastIconY = 0f;
  18. private float m_LastWindowX = 0f;
  19. private float m_LastWindowY = 0f;
  20. private float m_LastWindowWidth = 0f;
  21. private float m_LastWindowHeight = 0f;
  22. private float m_LastWindowScale = 0f;
  23. public override void Initialize(params object[] args)
  24. {
  25. m_DebuggerComponent = GameEntry.GetComponent<DebuggerComponent>();
  26. if (m_DebuggerComponent == null)
  27. {
  28. Log.Fatal("Debugger component is invalid.");
  29. return;
  30. }
  31. m_SettingComponent = GameEntry.GetComponent<SettingComponent>();
  32. if (m_SettingComponent == null)
  33. {
  34. Log.Fatal("Setting component is invalid.");
  35. return;
  36. }
  37. m_LastIconX = m_SettingComponent.GetFloat("Debugger.Icon.X", DefaultIconRect.x);
  38. m_LastIconY = m_SettingComponent.GetFloat("Debugger.Icon.Y", DefaultIconRect.y);
  39. m_LastWindowX = m_SettingComponent.GetFloat("Debugger.Window.X", DefaultWindowRect.x);
  40. m_LastWindowY = m_SettingComponent.GetFloat("Debugger.Window.Y", DefaultWindowRect.y);
  41. m_LastWindowWidth = m_SettingComponent.GetFloat("Debugger.Window.Width", DefaultWindowRect.width);
  42. m_LastWindowHeight = m_SettingComponent.GetFloat("Debugger.Window.Height", DefaultWindowRect.height);
  43. m_DebuggerComponent.WindowScale = m_LastWindowScale = m_SettingComponent.GetFloat("Debugger.Window.Scale", DefaultWindowScale);
  44. m_DebuggerComponent.IconRect = new Rect(m_LastIconX, m_LastIconY, DefaultIconRect.width, DefaultIconRect.height);
  45. m_DebuggerComponent.WindowRect = new Rect(m_LastWindowX, m_LastWindowY, m_LastWindowWidth, m_LastWindowHeight);
  46. }
  47. public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  48. {
  49. if (m_LastIconX != m_DebuggerComponent.IconRect.x)
  50. {
  51. m_LastIconX = m_DebuggerComponent.IconRect.x;
  52. m_SettingComponent.SetFloat("Debugger.Icon.X", m_DebuggerComponent.IconRect.x);
  53. }
  54. if (m_LastIconY != m_DebuggerComponent.IconRect.y)
  55. {
  56. m_LastIconY = m_DebuggerComponent.IconRect.y;
  57. m_SettingComponent.SetFloat("Debugger.Icon.Y", m_DebuggerComponent.IconRect.y);
  58. }
  59. if (m_LastWindowX != m_DebuggerComponent.WindowRect.x)
  60. {
  61. m_LastWindowX = m_DebuggerComponent.WindowRect.x;
  62. m_SettingComponent.SetFloat("Debugger.Window.X", m_DebuggerComponent.WindowRect.x);
  63. }
  64. if (m_LastWindowY != m_DebuggerComponent.WindowRect.y)
  65. {
  66. m_LastWindowY = m_DebuggerComponent.WindowRect.y;
  67. m_SettingComponent.SetFloat("Debugger.Window.Y", m_DebuggerComponent.WindowRect.y);
  68. }
  69. if (m_LastWindowWidth != m_DebuggerComponent.WindowRect.width)
  70. {
  71. m_LastWindowWidth = m_DebuggerComponent.WindowRect.width;
  72. m_SettingComponent.SetFloat("Debugger.Window.Width", m_DebuggerComponent.WindowRect.width);
  73. }
  74. if (m_LastWindowHeight != m_DebuggerComponent.WindowRect.height)
  75. {
  76. m_LastWindowHeight = m_DebuggerComponent.WindowRect.height;
  77. m_SettingComponent.SetFloat("Debugger.Window.Height", m_DebuggerComponent.WindowRect.height);
  78. }
  79. if (m_LastWindowScale != m_DebuggerComponent.WindowScale)
  80. {
  81. m_LastWindowScale = m_DebuggerComponent.WindowScale;
  82. m_SettingComponent.SetFloat("Debugger.Window.Scale", m_DebuggerComponent.WindowScale);
  83. }
  84. }
  85. protected override void OnDrawScrollableWindow()
  86. {
  87. GUILayout.Label("<b>Window Settings</b>");
  88. GUILayout.BeginVertical("box");
  89. {
  90. GUILayout.BeginHorizontal();
  91. {
  92. GUILayout.Label("Position:", GUILayout.Width(60f));
  93. GUILayout.Label("Drag window caption to move position.");
  94. }
  95. GUILayout.EndHorizontal();
  96. GUILayout.BeginHorizontal();
  97. {
  98. float width = m_DebuggerComponent.WindowRect.width;
  99. GUILayout.Label("Width:", GUILayout.Width(60f));
  100. if (GUILayout.RepeatButton("-", GUILayout.Width(30f)))
  101. {
  102. width--;
  103. }
  104. width = GUILayout.HorizontalSlider(width, 100f, Screen.width - 20f);
  105. if (GUILayout.RepeatButton("+", GUILayout.Width(30f)))
  106. {
  107. width++;
  108. }
  109. width = Mathf.Clamp(width, 100f, Screen.width - 20f);
  110. if (width != m_DebuggerComponent.WindowRect.width)
  111. {
  112. m_DebuggerComponent.WindowRect = new Rect(m_DebuggerComponent.WindowRect.x, m_DebuggerComponent.WindowRect.y, width, m_DebuggerComponent.WindowRect.height);
  113. }
  114. }
  115. GUILayout.EndHorizontal();
  116. GUILayout.BeginHorizontal();
  117. {
  118. float height = m_DebuggerComponent.WindowRect.height;
  119. GUILayout.Label("Height:", GUILayout.Width(60f));
  120. if (GUILayout.RepeatButton("-", GUILayout.Width(30f)))
  121. {
  122. height--;
  123. }
  124. height = GUILayout.HorizontalSlider(height, 100f, Screen.height - 20f);
  125. if (GUILayout.RepeatButton("+", GUILayout.Width(30f)))
  126. {
  127. height++;
  128. }
  129. height = Mathf.Clamp(height, 100f, Screen.height - 20f);
  130. if (height != m_DebuggerComponent.WindowRect.height)
  131. {
  132. m_DebuggerComponent.WindowRect = new Rect(m_DebuggerComponent.WindowRect.x, m_DebuggerComponent.WindowRect.y, m_DebuggerComponent.WindowRect.width, height);
  133. }
  134. }
  135. GUILayout.EndHorizontal();
  136. GUILayout.BeginHorizontal();
  137. {
  138. float scale = m_DebuggerComponent.WindowScale;
  139. GUILayout.Label("Scale:", GUILayout.Width(60f));
  140. if (GUILayout.RepeatButton("-", GUILayout.Width(30f)))
  141. {
  142. scale -= 0.01f;
  143. }
  144. scale = GUILayout.HorizontalSlider(scale, 0.5f, 4f);
  145. if (GUILayout.RepeatButton("+", GUILayout.Width(30f)))
  146. {
  147. scale += 0.01f;
  148. }
  149. scale = Mathf.Clamp(scale, 0.5f, 4f);
  150. if (scale != m_DebuggerComponent.WindowScale)
  151. {
  152. m_DebuggerComponent.WindowScale = scale;
  153. }
  154. }
  155. GUILayout.EndHorizontal();
  156. GUILayout.BeginHorizontal();
  157. {
  158. if (GUILayout.Button("0.5x", GUILayout.Height(60f)))
  159. {
  160. m_DebuggerComponent.WindowScale = 0.5f;
  161. }
  162. if (GUILayout.Button("1.0x", GUILayout.Height(60f)))
  163. {
  164. m_DebuggerComponent.WindowScale = 1f;
  165. }
  166. if (GUILayout.Button("1.5x", GUILayout.Height(60f)))
  167. {
  168. m_DebuggerComponent.WindowScale = 1.5f;
  169. }
  170. if (GUILayout.Button("2.0x", GUILayout.Height(60f)))
  171. {
  172. m_DebuggerComponent.WindowScale = 2f;
  173. }
  174. if (GUILayout.Button("2.5x", GUILayout.Height(60f)))
  175. {
  176. m_DebuggerComponent.WindowScale = 2.5f;
  177. }
  178. if (GUILayout.Button("3.0x", GUILayout.Height(60f)))
  179. {
  180. m_DebuggerComponent.WindowScale = 3f;
  181. }
  182. if (GUILayout.Button("3.5x", GUILayout.Height(60f)))
  183. {
  184. m_DebuggerComponent.WindowScale = 3.5f;
  185. }
  186. if (GUILayout.Button("4.0x", GUILayout.Height(60f)))
  187. {
  188. m_DebuggerComponent.WindowScale = 4f;
  189. }
  190. }
  191. GUILayout.EndHorizontal();
  192. if (GUILayout.Button("Reset Layout", GUILayout.Height(30f)))
  193. {
  194. m_DebuggerComponent.ResetLayout();
  195. }
  196. }
  197. GUILayout.EndVertical();
  198. }
  199. }
  200. }
  201. }