-
Notifications
You must be signed in to change notification settings - Fork 457
Experimental/singleton removal merge #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
bc9cef3
d4579ba
e6bb49e
8085b11
6c41534
35f3d20
d961ec1
aa43072
1537ab6
5498470
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using MLAPI.Profiling; | ||
using MLAPI.Serialization; | ||
|
@@ -40,36 +40,38 @@ class ProfilerContainer | |
public ProfilerTick[] ticks; | ||
|
||
public byte[] ToBytes() | ||
{ | ||
BitStream stream = new BitStream(); | ||
BitWriter writer = new BitWriter(stream); | ||
writer.WriteUInt16Packed((ushort)ticks.Length); | ||
|
||
for (int i = 0; i < ticks.Length; i++) | ||
{ | ||
ticks[i].SerializeToStream(stream); | ||
} | ||
|
||
return stream.ToArray(); | ||
} | ||
|
||
public static ProfilerContainer FromBytes(byte[] bytes) | ||
{ | ||
ProfilerContainer container = new ProfilerContainer(); | ||
BitStream stream = new BitStream(bytes); | ||
BitReader reader = new BitReader(stream); | ||
ushort count = reader.ReadUInt16Packed(); | ||
container.ticks = new ProfilerTick[count]; | ||
{ | ||
BitStream stream = new BitStream(); | ||
BitWriter writer = new BitWriter(stream); | ||
writer.WriteUInt16Packed((ushort)ticks.Length); | ||
|
||
for (int i = 0; i < ticks.Length; i++) | ||
{ | ||
ticks[i].SerializeToStream(stream); | ||
} | ||
|
||
return stream.ToArray(); | ||
} | ||
|
||
public static ProfilerContainer FromBytes(byte[] bytes) | ||
{ | ||
MLAPI.NetworkingManager manager = NetworkingManagerEditor.GetAnyNetworkingManager(); | ||
|
||
ProfilerContainer container = new ProfilerContainer(); | ||
BitStream stream = new BitStream(bytes); | ||
BitReader reader = new BitReader(manager, stream); | ||
ushort count = reader.ReadUInt16Packed(); | ||
container.ticks = new ProfilerTick[count]; | ||
for (int i = 0; i < count; i++) | ||
{ | ||
container.ticks[i] = ProfilerTick.FromStream(stream); | ||
} | ||
{ | ||
container.ticks[i] = ProfilerTick.FromStream(manager, stream); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same story here, in the FromStream lambda, you can first read the NM id, then de-ref and not need to pass this in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also was able to break this dep same was as above |
||
} | ||
|
||
return container; | ||
} | ||
} | ||
return container; | ||
} | ||
} | ||
|
||
private void StopRecording() | ||
private void StopRecording() | ||
{ | ||
NetworkProfiler.Stop(); | ||
} | ||
|
@@ -124,7 +126,7 @@ private void OnGUI() | |
string path = EditorUtility.OpenFilePanel("Choose a NetworkProfiler file", "", ""); | ||
if (!string.IsNullOrEmpty(path)) | ||
{ | ||
ProfilerTick[] ticks = ProfilerContainer.FromBytes(File.ReadAllBytes(path)).ticks; | ||
ProfilerTick[] ticks = ProfilerContainer.FromBytes(File.ReadAllBytes(path)).ticks; | ||
if (ticks.Length >= 2) | ||
{ | ||
curve = AnimationCurve.Constant(ticks[0].EventId, ticks[(ticks.Length - 1)].EventId, 0); | ||
|
@@ -160,7 +162,7 @@ private void OnGUI() | |
ProfilerTick[] ticks = new ProfilerTick[ticksInRange]; | ||
for (int i = min; i < max; i++) ticks[i - min] = currentTicks[i]; | ||
string path = EditorUtility.SaveFilePanel("Save NetworkProfiler data", "", "networkProfilerData", ""); | ||
if (!string.IsNullOrEmpty(path)) File.WriteAllBytes(path, new ProfilerContainer() { ticks = ticks }.ToBytes()); | ||
if (!string.IsNullOrEmpty(path)) File.WriteAllBytes(path, new ProfilerContainer() { ticks = ticks }.ToBytes()); | ||
} | ||
|
||
EditorGUILayout.EndHorizontal(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,29 @@ public class NetworkingManagerEditor : Editor | |
private readonly List<Type> transportTypes = new List<Type>(); | ||
private string[] transportNames = new string[] { "Select transport..." }; | ||
|
||
/// <summary> | ||
/// Helper method that gets either the server or non-server NetworkingManager in the scene, or null if not present. | ||
/// </summary> | ||
public static NetworkingManager GetNetworkingManager(bool isServer) | ||
{ | ||
foreach (var manager in FindObjectsOfType<NetworkingManager>()) | ||
{ | ||
if (manager.IsServer == isServer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I am confused by the IsServer check because from what I can tell its always false? https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/495/files#diff-641f8f5b259017aefa68498910442cb599d894ed91c96e4811d0a79b5f0151feR24 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, that's for the |
||
{ | ||
return manager; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the first NetworkingManager in the scene, of any type. | ||
/// </summary> | ||
public static NetworkingManager GetAnyNetworkingManager() | ||
{ | ||
return FindObjectOfType<NetworkingManager>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I get this is just editor code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had similar discussions over at the RFC-side in case you'd like to contribute :) |
||
} | ||
|
||
private void ReloadTransports() | ||
{ | ||
transportTypes.Clear(); | ||
|
@@ -97,7 +120,7 @@ private void Init() | |
// Base properties | ||
dontDestroyOnLoadProperty = serializedObject.FindProperty("DontDestroy"); | ||
runInBackgroundProperty = serializedObject.FindProperty("RunInBackground"); | ||
logLevelProperty = serializedObject.FindProperty("LogLevel"); | ||
logLevelProperty = serializedObject.FindProperty("LogLevelLocal"); | ||
networkConfigProperty = serializedObject.FindProperty("NetworkConfig"); | ||
|
||
// NetworkConfig properties | ||
|
@@ -137,7 +160,7 @@ private void CheckNullProperties() | |
// Base properties | ||
dontDestroyOnLoadProperty = serializedObject.FindProperty("DontDestroy"); | ||
runInBackgroundProperty = serializedObject.FindProperty("RunInBackground"); | ||
logLevelProperty = serializedObject.FindProperty("LogLevel"); | ||
logLevelProperty = serializedObject.FindProperty("LogLevelLocal"); | ||
networkConfigProperty = serializedObject.FindProperty("NetworkConfig"); | ||
|
||
// NetworkConfig properties | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using MLAPI; | ||
using MLAPI; | ||
using MLAPI.LagCompensation; | ||
|
||
namespace UnityEditor | ||
|
@@ -23,7 +23,11 @@ public override void OnInspectorGUI() | |
{ | ||
Init(); | ||
base.OnInspectorGUI(); | ||
if(NetworkingManager.Singleton != null && NetworkingManager.Singleton.IsServer) | ||
|
||
//FIXME: Singleton Conversion, get all of them and be sure to get the server! | ||
NetworkingManager manager = NetworkingManagerEditor.GetNetworkingManager(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I think generally in the non-singleton case I would expect the editors to show only useful data if the actual object being selected is a NetworkManager... I just don't think that picking the first thing you see if actually useful. Also FindObjectOfType doesn't guarantee order so you could call it more than once and get different objects which doesn't seem like the desired behavior either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably the #1 unresolved issue in this addition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I called out something similar on the RFC-side, inlining my suggestions here too:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think one way or another we'll want a central table of NMs |
||
|
||
if(manager != null ) | ||
{ | ||
EditorGUILayout.LabelField("Total points: ", trackedObject.TotalPoints.ToString(), EditorStyles.label); | ||
EditorGUILayout.LabelField("Avg time between points: ", trackedObject.AvgTimeBetweenPointsMs.ToString() + " ms", EditorStyles.label); | ||
|
Uh oh!
There was an error while loading. Please reload this page.