Skip to content

Commit

Permalink
fix: fixing profier behaviour
Browse files Browse the repository at this point in the history
- using lateUpdate instead of NewProfilerFrameRecorded.
- adding #if editor to allow builds
  • Loading branch information
James-Frowen committed Aug 7, 2022
1 parent a9ce5e1 commit 53f0614
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Assets/Mirage.Profiler/NetworkProfilerBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mirage.Logging;
using UnityEditorInternal;
using UnityEngine;

namespace Mirage.NetworkProfiler
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 53f0614

Please sign in to comment.