| | 1 | | using System; |
| | 2 | | using DCL.Bots; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Interface; |
| | 6 | | using UnityEngine.UI; |
| | 7 | | using UnityEngine; |
| | 8 | | using Object = UnityEngine.Object; |
| | 9 | |
|
| | 10 | | namespace DCL |
| | 11 | | { |
| | 12 | | public class DebugController : IDebugController |
| | 13 | | { |
| 0 | 14 | | private DebugConfig debugConfig => DataStore.i.debugConfig; |
| 531 | 15 | | private readonly PerformanceMeterController performanceMeterController = new PerformanceMeterController(); |
| | 16 | | private readonly IBotsController botsController; |
| | 17 | |
|
| | 18 | | public DebugView debugView; |
| | 19 | |
|
| | 20 | | public readonly CrashPayloadPositionTracker positionTracker; |
| | 21 | |
|
| | 22 | | public event Action OnDebugModeSet; |
| | 23 | |
|
| 531 | 24 | | public DebugController(IBotsController botsController) |
| | 25 | | { |
| 531 | 26 | | positionTracker = new CrashPayloadPositionTracker(); |
| | 27 | |
|
| 531 | 28 | | GameObject view = Object.Instantiate(UnityEngine.Resources.Load("DebugView")) as GameObject; |
| 531 | 29 | | debugView = view.GetComponent<DebugView>(); |
| 531 | 30 | | this.botsController = botsController; |
| 531 | 31 | | } |
| | 32 | |
|
| | 33 | | public void SetDebug() |
| | 34 | | { |
| 10 | 35 | | Debug.unityLogger.logEnabled = true; |
| | 36 | |
|
| 10 | 37 | | debugConfig.isDebugMode = true; |
| | 38 | |
|
| 10 | 39 | | ShowFPSPanel(); |
| | 40 | |
|
| 10 | 41 | | OnDebugModeSet?.Invoke(); |
| 10 | 42 | | } |
| | 43 | |
|
| | 44 | | public void HideFPSPanel() |
| | 45 | | { |
| 1 | 46 | | if (debugView != null) |
| 1 | 47 | | debugView.HideFPSPanel(); |
| 1 | 48 | | } |
| | 49 | |
|
| | 50 | | public void ShowFPSPanel() |
| | 51 | | { |
| 10 | 52 | | if (debugView != null) |
| 10 | 53 | | debugView.ShowFPSPanel(); |
| 10 | 54 | | } |
| | 55 | |
|
| | 56 | | public void SetSceneDebugPanel() |
| | 57 | | { |
| 0 | 58 | | if (debugView != null) |
| 0 | 59 | | debugView.SetSceneDebugPanel(); |
| 0 | 60 | | } |
| | 61 | |
|
| | 62 | | public void SetEngineDebugPanel() |
| | 63 | | { |
| 0 | 64 | | if (debugView != null) |
| 0 | 65 | | debugView.SetEngineDebugPanel(); |
| 0 | 66 | | } |
| | 67 | |
|
| 0 | 68 | | public void RunPerformanceMeterTool(float durationInSeconds) { performanceMeterController.StartSampling(duration |
| | 69 | |
|
| | 70 | | public void InstantiateBotsAtWorldPos(string configJson) |
| | 71 | | { |
| 0 | 72 | | var config = new DCL.Bots.WorldPosInstantiationConfig(); |
| 0 | 73 | | JsonUtility.FromJsonOverwrite(configJson, config); |
| | 74 | |
|
| 0 | 75 | | CoroutineStarter.Start(botsController.InstantiateBotsAtWorldPos(config)); |
| 0 | 76 | | } |
| | 77 | |
|
| | 78 | | public void InstantiateBotsAtCoords(string configJson) |
| | 79 | | { |
| 0 | 80 | | var config = new DCL.Bots.CoordsInstantiationConfig(); |
| 0 | 81 | | JsonUtility.FromJsonOverwrite(configJson, config); |
| | 82 | |
|
| 0 | 83 | | CoroutineStarter.Start(botsController.InstantiateBotsAtCoords(config)); |
| 0 | 84 | | } |
| | 85 | |
|
| 0 | 86 | | public void RemoveBot(string targetEntityId) { botsController.RemoveBot(targetEntityId); } |
| | 87 | |
|
| 0 | 88 | | public void ClearBots() { botsController.ClearBots(); } |
| | 89 | |
|
| 0 | 90 | | public List<Vector3> GetTrackedTeleportPositions() { return positionTracker.teleportPositions; } |
| | 91 | |
|
| 0 | 92 | | public List<Vector3> GetTrackedMovements() { return positionTracker.movePositions; } |
| | 93 | |
|
| | 94 | | public void Dispose() |
| | 95 | | { |
| 537 | 96 | | positionTracker.Dispose(); |
| 537 | 97 | | if (debugView != null) |
| 531 | 98 | | Object.Destroy(debugView.gameObject); |
| 537 | 99 | | } |
| | 100 | | } |
| | 101 | | } |