| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL; |
| | 4 | | using UnityEngine; |
| | 5 | | using Object = UnityEngine.Object; |
| | 6 | |
|
| | 7 | | internal class PreviewMenuController : IDisposable |
| | 8 | | { |
| | 9 | | internal const string MENU_VIEW_RES_PATH = "PreviewMenuView"; |
| | 10 | | internal const string TOGGLEVISIBILITY_VIEW_RES_PATH = "PreviewMenuVisibilityToggle"; |
| | 11 | | internal const string POSITION_VIEW_RES_PATH = "PreviewMenuPositionView"; |
| | 12 | |
|
| | 13 | | internal readonly PreviewMenuView menuView; |
| | 14 | |
|
| | 15 | | internal readonly PreviewMenuVisibilityToggleView showFps; |
| | 16 | | internal readonly PreviewMenuVisibilityToggleView showBoundingBox; |
| | 17 | | internal readonly PreviewMenuPositionView positionView; |
| | 18 | |
|
| 5 | 19 | | public PreviewMenuController() |
| | 20 | | { |
| 5 | 21 | | var menuViewResource = Resources.Load<PreviewMenuView>(MENU_VIEW_RES_PATH); |
| 5 | 22 | | menuView = Object.Instantiate(menuViewResource); |
| 5 | 23 | | menuView.name = "_PreviewMenu"; |
| 5 | 24 | | menuView.SetVisible(false); |
| | 25 | |
|
| 5 | 26 | | var visibilityToggleViewResource = Resources.Load<PreviewMenuVisibilityToggleView>(TOGGLEVISIBILITY_VIEW_RES_PAT |
| 5 | 27 | | showFps = Object.Instantiate(visibilityToggleViewResource); |
| 5 | 28 | | showFps.SetUp("FPS PANEL", IsFPSPanelOn, OnFPSPanelToggle); |
| | 29 | |
|
| 5 | 30 | | showBoundingBox = Object.Instantiate(visibilityToggleViewResource); |
| 5 | 31 | | showBoundingBox.SetUp("BOUNDING BOXES", IsBoundingBoxOn, OnBoundingBoxToggle); |
| | 32 | |
|
| 5 | 33 | | var positionViewResource = Resources.Load<PreviewMenuPositionView>(POSITION_VIEW_RES_PATH); |
| 5 | 34 | | positionView = Object.Instantiate(positionViewResource); |
| | 35 | |
|
| 5 | 36 | | menuView.AddMenuItem(positionView.transform); |
| 5 | 37 | | menuView.AddMenuItem(showFps.transform); |
| 5 | 38 | | menuView.AddMenuItem(showBoundingBox.transform); |
| 5 | 39 | | } |
| | 40 | |
|
| | 41 | | public void Dispose() |
| | 42 | | { |
| 5 | 43 | | positionView.Dispose(); |
| 5 | 44 | | showBoundingBox.Dispose(); |
| 5 | 45 | | showFps.Dispose(); |
| 5 | 46 | | menuView.Dispose(); |
| 5 | 47 | | } |
| | 48 | |
|
| | 49 | | private static bool IsFPSPanelOn() |
| | 50 | | { |
| 6 | 51 | | return DataStore.i.debugConfig.isFPSPanelVisible.Get(); |
| | 52 | | } |
| | 53 | |
|
| | 54 | | private static void OnFPSPanelToggle(bool isOn) |
| | 55 | | { |
| 1 | 56 | | DataStore.i.debugConfig.isFPSPanelVisible.Set(isOn); |
| 1 | 57 | | } |
| | 58 | |
|
| | 59 | | private static bool IsBoundingBoxOn() |
| | 60 | | { |
| 6 | 61 | | return DataStore.i.debugConfig.showSceneBoundingBoxes.Get() |
| 1 | 62 | | .Any(pair => pair.Value); |
| | 63 | | } |
| | 64 | |
|
| | 65 | | private static void OnBoundingBoxToggle(bool isOn) |
| | 66 | | { |
| 1 | 67 | | var sceneIds = DataStore.i.debugConfig.showSceneBoundingBoxes.Get() |
| 1 | 68 | | .Select(pair => pair.Key) |
| | 69 | | .ToArray(); |
| | 70 | |
|
| 4 | 71 | | foreach (var sceneId in sceneIds) |
| | 72 | | { |
| 1 | 73 | | DataStore.i.debugConfig.showSceneBoundingBoxes.AddOrSet(sceneId, isOn); |
| | 74 | | } |
| 1 | 75 | | } |
| | 76 | | } |