From 53f06143befb02caa8c415a05fb10d53bf484906 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Fri, 5 Aug 2022 17:57:01 +0100 Subject: [PATCH] fix: fixing profier behaviour - using lateUpdate instead of NewProfilerFrameRecorded. - adding #if editor to allow builds --- .../NetworkProfilerBehaviour.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Assets/Mirage.Profiler/NetworkProfilerBehaviour.cs b/Assets/Mirage.Profiler/NetworkProfilerBehaviour.cs index fbfd022..bf973ea 100644 --- a/Assets/Mirage.Profiler/NetworkProfilerBehaviour.cs +++ b/Assets/Mirage.Profiler/NetworkProfilerBehaviour.cs @@ -1,5 +1,4 @@ using Mirage.Logging; -using UnityEditorInternal; using UnityEngine; namespace Mirage.NetworkProfiler @@ -29,6 +28,11 @@ public class NetworkProfilerBehaviour : MonoBehaviour private void Start() { +#if !UNITY_EDITOR + Debug.LogWarning("NetworkProfilerBehaviour only works in editor"); + return; +#endif + Debug.Assert(Instance == null); Instance = this; DontDestroyOnLoad(this); @@ -44,19 +48,10 @@ private void Start() Client.Started.AddListener(ClientStarted); Client.Disconnected.AddListener(ClientStopped); } - - ProfilerDriver.NewProfilerFrameRecorded += NewProfilerFrameRecorded; - } - - private void NewProfilerFrameRecorded(int _connectionId, int newFrameIndex) - { - Sample(newFrameIndex); } private void OnDestroy() { - ProfilerDriver.NewProfilerFrameRecorded -= NewProfilerFrameRecorded; - if (_receivedCounter != null) NetworkDiagnostics.InMessageEvent -= _receivedCounter.OnMessage; if (_sentCounter != null) @@ -111,9 +106,16 @@ private void ClientStopped(INetworkPlayer arg0) _sentCounter = null; } + +#if UNITY_EDITOR + private void LateUpdate() + { + Debug.Log($"Sample: [LateUpdate, first {UnityEditorInternal.ProfilerDriver.firstFrameIndex}, last {UnityEditorInternal.ProfilerDriver.lastFrameIndex}]"); + Sample(UnityEditorInternal.ProfilerDriver.lastFrameIndex); + } +#endif private void Sample(int frame) { - Debug.Log($"Sample: [frame: {frame}, first {ProfilerDriver.firstFrameIndex}, last {ProfilerDriver.lastFrameIndex}]"); if (instance == null) return;