| | 1 | | using DCL.Helpers; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace DCL |
| | 6 | | { |
| | 7 | | public class StatsPanelToggler : MonoBehaviour |
| | 8 | | { |
| | 9 | | const string SHORTCUT_TEXT = |
| | 10 | | "P = Toggle Panel | R = Reset Profile Data | I = Toggle Deep Msg Profiling"; |
| | 11 | |
|
| | 12 | | bool deepProfilingEnabled; |
| | 13 | | Text text; |
| | 14 | |
|
| | 15 | | public MessageBenchmarkController messageController; |
| | 16 | | public MiscBenchmarkController miscController; |
| | 17 | |
|
| | 18 | | void Start() |
| | 19 | | { |
| 0 | 20 | | text = GetComponent<Text>(); |
| 0 | 21 | | deepProfilingEnabled = true; |
| | 22 | |
|
| 0 | 23 | | EnableProfiling(); |
| 0 | 24 | | RefreshShortcutText(); |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | void Update() |
| | 28 | | { |
| 0 | 29 | | UpdateDeepProfilingInput(); |
| | 30 | |
|
| 0 | 31 | | if (Input.GetKeyUp(KeyCode.Y)) |
| | 32 | | { |
| 0 | 33 | | TogglePanel(); |
| | 34 | | } |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | private void UpdateDeepProfilingInput() |
| | 38 | | { |
| 0 | 39 | | if (Input.GetKeyUp(KeyCode.I)) |
| | 40 | | { |
| 0 | 41 | | deepProfilingEnabled = !deepProfilingEnabled; |
| | 42 | |
|
| 0 | 43 | | if (deepProfilingEnabled) |
| | 44 | | { |
| 0 | 45 | | EnableDeepProfiling(); |
| 0 | 46 | | } |
| | 47 | | else |
| | 48 | | { |
| 0 | 49 | | DisableDeepProfiling(); |
| | 50 | | } |
| | 51 | |
|
| 0 | 52 | | RefreshShortcutText(); |
| | 53 | | } |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | private void TogglePanel() |
| | 57 | | { |
| 0 | 58 | | if (deepProfilingEnabled) |
| | 59 | | { |
| 0 | 60 | | messageController.gameObject.SetActive(!messageController.gameObject.activeSelf); |
| | 61 | | } |
| | 62 | |
|
| 0 | 63 | | miscController.gameObject.SetActive(!miscController.gameObject.activeSelf); |
| 0 | 64 | | Utils.ForceRebuildLayoutImmediate(transform.parent.GetComponent<RectTransform>()); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | private void EnableDeepProfiling() |
| | 68 | | { |
| 0 | 69 | | messageController.StartProfiling(); |
| | 70 | |
|
| 0 | 71 | | if (miscController.gameObject.activeSelf) |
| | 72 | | { |
| 0 | 73 | | messageController.gameObject.SetActive(true); |
| | 74 | | } |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private void DisableDeepProfiling() |
| | 78 | | { |
| 0 | 79 | | messageController.StopProfiling(); |
| 0 | 80 | | messageController.gameObject.SetActive(false); |
| 0 | 81 | | } |
| | 82 | |
|
| | 83 | | private void EnableProfiling() |
| | 84 | | { |
| 0 | 85 | | miscController.StartProfiling(); |
| | 86 | |
|
| 0 | 87 | | if (deepProfilingEnabled) |
| | 88 | | { |
| 0 | 89 | | EnableDeepProfiling(); |
| | 90 | | } |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | void RefreshShortcutText() |
| | 94 | | { |
| 0 | 95 | | if (deepProfilingEnabled) |
| | 96 | | { |
| 0 | 97 | | text.text = $"[Deep Message Profiling Enabled]\n{SHORTCUT_TEXT}"; |
| 0 | 98 | | return; |
| | 99 | | } |
| | 100 | |
|
| 0 | 101 | | text.text = $"[Profiling Enabled]\n{SHORTCUT_TEXT}"; |
| 0 | 102 | | } |
| | 103 | | } |
| | 104 | | } |