HKI Core
DebugSystem.cs
Go to the documentation of this file.
1 #pragma warning disable 0414
2 using UnityEngine;
3 using System.Collections;
4 
5 namespace HKI.Core.Debuging
6 {
12  public class DebugSystem : MonoBehaviour
13  {
14  // Public variables
15  [SerializeField] FPSCalc FPSCalc = new FPSCalc();
16 
17  [SerializeField] KeyCode DebugInfoAndConsoleToggleKey = KeyCode.F1;
18  [SerializeField] KeyCode FPSInfoToggleKey = KeyCode.F2;
19  [Range(0.1f, 1f)] [SerializeField] float UpdateInterval = 0.2f;
20  [SerializeField] SystemInfo SystemInfo = null;
21  [SerializeField] MemoryInfo MemoryInfo = null;
22  [SerializeField] FPSInfo FPSInfo = null;
23  [SerializeField] DebugConsole DebugConsole = null;
24 
25  [SerializeField] SimpleFPSInfo SimpleFPSInfo = null;
26 
27  [SerializeField] GameObject DebugInfoAndConsoleGO = null;
28  [SerializeField] GameObject SimpleFPSInfoGO = null;
29 
30  // Private variables
31  bool debugInfoAndCosoleVisibility = true;
32 
33  int simpleFPSInfoIndex = -1;
34 
35  WaitForSecondsRealtime efsr = null;
36  // Start function
37  public void Start()
38  {
39  FPSCalc.SetUpdateInterval = UpdateInterval;
40  FPSCalc.Init();
41  FPSInfo.Init(FPSCalc);
42  SimpleFPSInfo.Init(FPSCalc);
43  HideVisibilityDebugInfoAndConsole();
44  NextSimpleFPSInfoMode();
45 
46  efsr = new WaitForSecondsRealtime(UpdateInterval);
47  StartCoroutine(UpdateCoroutine());
48  }
49 
50  // Update function
51  void Update()
52  {
53  FPSCalc.Update();
54 
55  if(Input.GetKeyDown(DebugInfoAndConsoleToggleKey))
56  ToggleVisibilityDebugInfoAndConsole();
57 
58  if (Input.GetKeyDown(FPSInfoToggleKey))
59  NextSimpleFPSInfoMode();
60  }
61 
62  // Interface function
64  {
65  FPSCalc.ResetMinAndMaxFPS();
66  }
67 
68  // Update all infos
69  IEnumerator UpdateCoroutine()
70  {
71  while(Application.isPlaying)
72  {
73  UpdateInfos();
74  efsr.Reset();
75  yield return efsr;
76  }
77  }
78 
79  void UpdateInfos()
80  {
81  if (DebugInfoAndConsoleGO.activeSelf)
82  {
83  if(SystemInfo != null)
84  SystemInfo.UpdateInfo();
85 
86  if(MemoryInfo != null)
87  MemoryInfo.UpdateInfo();
88 
89  if(FPSInfo != null)
90  FPSInfo.UpdateInfo(FPSCalc);
91  }
92 
93  if(SimpleFPSInfo != null && SimpleFPSInfoGO.activeSelf)
94  SimpleFPSInfo.UpdateInfo(FPSCalc);
95  }
96 
97  // Helper functions
99  {
100  if(debugInfoAndCosoleVisibility)
101  HideVisibilityDebugInfoAndConsole();
102  else
103  ShowVisibilityDebugInfoAndConsole();
104  }
105 
107  {
108  DebugInfoAndConsoleGO.SetActive(true);
109 
110  debugInfoAndCosoleVisibility = true;
111  }
112 
114  {
115  DebugInfoAndConsoleGO.SetActive(false);
116 
117  debugInfoAndCosoleVisibility = false;
118  }
119 
121  {
122  simpleFPSInfoIndex = (simpleFPSInfoIndex + 1) % 3;
123 
124  switch(simpleFPSInfoIndex)
125  {
126  case 0:
127  SimpleFPSInfoGO.SetActive(false);
128  break;
129 
130  case 1:
131  SimpleFPSInfoGO.SetActive(true);
132  SimpleFPSInfo.ShowOnlyFPS();
133  break;
134 
135  case 2:
136  SimpleFPSInfoGO.SetActive(true);
137  SimpleFPSInfo.ShowFPSAndGraph();
138  break;
139  }
140  }
141  }
142 }
void Init(FPSCalc fpsCalc)
Definition: FPSInfo.cs:20
This MonoBehaviour updates the UI of the FPS only information with the FPS information calced by FPSC...
Definition: SimpleFPSInfo.cs:9
This class calcs the fps and greates the graph.
Definition: FPSCalc.cs:11
This MonoBehaviour fetches and updates the UI of the DebugSystem/Console with the system information...
Definition: SystemInfo.cs:11
void Init(FPSCalc fpsCalc)
This MonoBehaviour updates the UI of the DebugSystem/Console with the FPS information calced by FPSCa...
Definition: FPSInfo.cs:9
void UpdateInfo(FPSCalc fpsCalc)
Definition: FPSInfo.cs:25
MonoBehaviour for the debugging console
Definition: DebugConsole.cs:15
This MonoBehaviour fetches the memory info from Unity and updates the UI with this information...
Definition: MemoryInfo.cs:10
The DebugSystem controlls the pannel which includes the DebuConsole, SystemInfo, MemoryInfo and FPSIn...
Definition: DebugSystem.cs:12
void UpdateInfo(FPSCalc fpsCalc)