Skip to content

Commit 9043316

Browse files
authored
Merge pull request #168 from MidLevel/visibility
Added Visibility System
2 parents 3ee1b1c + 5628aee commit 9043316

17 files changed

+527
-394
lines changed

MLAPI-Editor/NetworkedObjectEditor.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MLAPI;
1+
using System.Collections.Generic;
2+
using MLAPI;
23
using UnityEngine;
34

45
namespace UnityEditor
@@ -9,6 +10,7 @@ public class NetworkedObjectEditor : Editor
910
{
1011
private bool initialized;
1112
private NetworkedObject networkedObject;
13+
private bool showObservers;
1214

1315
private void Init()
1416
{
@@ -24,7 +26,7 @@ public override void OnInspectorGUI()
2426
if (NetworkingManager.Singleton == null || (!NetworkingManager.Singleton.IsServer && !NetworkingManager.Singleton.IsClient))
2527
base.OnInspectorGUI(); //Only run this if we are NOT running server. This is where the ServerOnly box is drawn
2628

27-
if (!networkedObject.isSpawned && NetworkingManager.Singleton != null && NetworkingManager.Singleton.IsServer)
29+
if (!networkedObject.IsSpawned && NetworkingManager.Singleton != null && NetworkingManager.Singleton.IsServer)
2830
{
2931
EditorGUILayout.BeginHorizontal();
3032
EditorGUILayout.LabelField(new GUIContent("Spawn", "Spawns the object across the network"));
@@ -35,18 +37,40 @@ public override void OnInspectorGUI()
3537
}
3638
EditorGUILayout.EndHorizontal();
3739
}
38-
else if (networkedObject.isSpawned)
40+
else if (networkedObject.IsSpawned)
3941
{
4042
EditorGUILayout.LabelField("PrefabName: ", networkedObject.NetworkedPrefabName, EditorStyles.label);
4143
EditorGUILayout.LabelField("PrefabHash: ", networkedObject.NetworkedPrefabHash.ToString(), EditorStyles.label);
4244
EditorGUILayout.LabelField("NetworkId: ", networkedObject.NetworkId.ToString(), EditorStyles.label);
4345
EditorGUILayout.LabelField("OwnerId: ", networkedObject.OwnerClientId.ToString(), EditorStyles.label);
44-
EditorGUILayout.LabelField("isSpawned: ", networkedObject.isSpawned.ToString(), EditorStyles.label);
45-
EditorGUILayout.LabelField("isLocalPlayer: ", networkedObject.isLocalPlayer.ToString(), EditorStyles.label);
46-
EditorGUILayout.LabelField("isOwner: ", networkedObject.isOwner.ToString(), EditorStyles.label);
47-
EditorGUILayout.LabelField("isOwnedByServer: ", networkedObject.isOwnedByServer.ToString(), EditorStyles.label);
48-
EditorGUILayout.LabelField("isPoolObject: ", networkedObject.isPooledObject.ToString(), EditorStyles.label);
49-
EditorGUILayout.LabelField("isPlayerObject: ", networkedObject.isPlayerObject.ToString(), EditorStyles.label);
46+
EditorGUILayout.LabelField("IsSpawned: ", networkedObject.IsSpawned.ToString(), EditorStyles.label);
47+
EditorGUILayout.LabelField("IsLocalPlayer: ", networkedObject.IsLocalPlayer.ToString(), EditorStyles.label);
48+
EditorGUILayout.LabelField("IsOwner: ", networkedObject.IsOwner.ToString(), EditorStyles.label);
49+
EditorGUILayout.LabelField("IsOwnedByServer: ", networkedObject.IsOwnedByServer.ToString(), EditorStyles.label);
50+
EditorGUILayout.LabelField("IsPoolObject: ", networkedObject.IsPooledObject.ToString(), EditorStyles.label);
51+
EditorGUILayout.LabelField("IsPlayerObject: ", networkedObject.IsPlayerObject.ToString(), EditorStyles.label);
52+
53+
if (NetworkingManager.Singleton != null && NetworkingManager.Singleton.IsServer)
54+
{
55+
showObservers = EditorGUILayout.Foldout(showObservers, "Observers");
56+
57+
if (showObservers)
58+
{
59+
HashSet<uint>.Enumerator observerClientIds = networkedObject.GetObservers();
60+
61+
EditorGUI.indentLevel += 1;
62+
63+
while (observerClientIds.MoveNext())
64+
{
65+
if (NetworkingManager.Singleton.ConnectedClients[observerClientIds.Current].PlayerObject != null)
66+
EditorGUILayout.ObjectField("ClientId: " + observerClientIds.Current, NetworkingManager.Singleton.ConnectedClients[observerClientIds.Current].PlayerObject, typeof(GameObject), false);
67+
else
68+
EditorGUILayout.TextField("ClientId: " + observerClientIds.Current, EditorStyles.label);
69+
}
70+
71+
EditorGUI.indentLevel -= 1;
72+
}
73+
}
5074
}
5175
}
5276
}

MLAPI-Editor/NetworkingManagerEditor.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ public override void OnInspectorGUI()
124124
EditorGUILayout.PropertyField(RunInBackgroundProperty);
125125
EditorGUILayout.PropertyField(LogLevelProperty);
126126

127-
if (networkingManager.NetworkConfig.HandleObjectSpawning)
128-
{
129-
EditorGUILayout.Space();
130-
networkPrefabsList.DoLayoutList();
131-
}
127+
EditorGUILayout.Space();
128+
networkPrefabsList.DoLayoutList();
129+
132130
EditorGUILayout.Space();
133131
channelsList.DoLayoutList();
134132
EditorGUILayout.Space();

MLAPI/Data/MLAPIConstants.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,23 @@ public static class MLAPIConstants
1414
public const byte MLAPI_CONNECTION_REQUEST = 3;
1515
public const byte MLAPI_CONNECTION_APPROVED = 4;
1616
public const byte MLAPI_ADD_OBJECT = 5;
17-
public const byte MLAPI_CLIENT_DISCONNECT = 6;
18-
public const byte MLAPI_DESTROY_OBJECT = 7;
19-
public const byte MLAPI_SWITCH_SCENE = 8;
20-
public const byte MLAPI_CLIENT_SWITCH_SCENE_COMPLETED = 9;
21-
public const byte MLAPI_SPAWN_POOL_OBJECT = 10;
22-
public const byte MLAPI_DESTROY_POOL_OBJECT = 11;
23-
public const byte MLAPI_CHANGE_OWNER = 12;
24-
public const byte MLAPI_ADD_OBJECTS = 13;
25-
public const byte MLAPI_TIME_SYNC = 14;
26-
public const byte MLAPI_NETWORKED_VAR_DELTA = 15;
27-
public const byte MLAPI_NETWORKED_VAR_UPDATE = 16;
28-
public const byte MLAPI_SERVER_RPC = 17;
29-
public const byte MLAPI_SERVER_RPC_REQUEST = 18;
30-
public const byte MLAPI_SERVER_RPC_RESPONSE = 19;
31-
public const byte MLAPI_CLIENT_RPC = 20;
32-
public const byte MLAPI_CLIENT_RPC_REQUEST = 21;
33-
public const byte MLAPI_CLIENT_RPC_RESPONSE = 22;
34-
public const byte MLAPI_CUSTOM_MESSAGE = 23;
17+
public const byte MLAPI_DESTROY_OBJECT = 6;
18+
public const byte MLAPI_SWITCH_SCENE = 7;
19+
public const byte MLAPI_CLIENT_SWITCH_SCENE_COMPLETED = 8;
20+
public const byte MLAPI_SPAWN_POOL_OBJECT = 9;
21+
public const byte MLAPI_DESTROY_POOL_OBJECT = 10;
22+
public const byte MLAPI_CHANGE_OWNER = 11;
23+
public const byte MLAPI_ADD_OBJECTS = 12;
24+
public const byte MLAPI_TIME_SYNC = 13;
25+
public const byte MLAPI_NETWORKED_VAR_DELTA = 14;
26+
public const byte MLAPI_NETWORKED_VAR_UPDATE = 15;
27+
public const byte MLAPI_SERVER_RPC = 16;
28+
public const byte MLAPI_SERVER_RPC_REQUEST = 17;
29+
public const byte MLAPI_SERVER_RPC_RESPONSE = 18;
30+
public const byte MLAPI_CLIENT_RPC = 19;
31+
public const byte MLAPI_CLIENT_RPC_REQUEST = 20;
32+
public const byte MLAPI_CLIENT_RPC_RESPONSE = 21;
33+
public const byte MLAPI_CUSTOM_MESSAGE = 22;
3534
public const byte INVALID = 32;
3635

3736
public static readonly string[] MESSAGE_NAMES = {
@@ -41,7 +40,6 @@ public static class MLAPIConstants
4140
"MLAPI_CONNECTION_REQUEST",
4241
"MLAPI_CONNECTION_APPROVED",
4342
"MLAPI_ADD_OBJECT",
44-
"MLAPI_CLIENT_DISCONNECT",
4543
"MLAPI_DESTROY_OBJECT",
4644
"MLAPI_SWITCH_SCENE",
4745
"MLAPI_CLIENT_SWITCH_SCENE_COMPLETED",
@@ -51,8 +49,8 @@ public static class MLAPIConstants
5149
"MLAPI_ADD_OBJECTS",
5250
"MLAPI_TIME_SYNC",
5351
"MLAPI_NETWORKED_VAR_DELTA",
54-
"MLAPI_NETWORKED_VAR_UPDATE", // 16
55-
"MLAPI_SERVER_RPC",
52+
"MLAPI_NETWORKED_VAR_UPDATE",
53+
"MLAPI_SERVER_RPC", // 16
5654
"MLAPI_SERVER_RPC_REQUEST",
5755
"MLAPI_SERVER_RPC_RESPONSE",
5856
"MLAPI_CLIENT_RPC",

MLAPI/Data/NetworkConfig.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ public class NetworkConfig
111111
/// </summary>
112112
public int SecondsHistory = 5;
113113
/// <summary>
114-
/// Wheter or not to make the library handle object spawning
115-
/// </summary>
116-
public bool HandleObjectSpawning = true;
117-
/// <summary>
118114
/// Wheter or not to enable scene switching
119115
/// </summary>
120116
public bool EnableSceneSwitching = true;
@@ -235,7 +231,6 @@ public string ToBase64()
235231
writer.WriteInt32Packed(config.ClientConnectionBufferTimeout);
236232
writer.WriteBool(config.ConnectionApproval);
237233
writer.WriteInt32Packed(config.SecondsHistory);
238-
writer.WriteBool(config.HandleObjectSpawning);
239234
writer.WriteBool(config.EnableEncryption);
240235
writer.WriteBool(config.SignKeyExchange);
241236
writer.WriteBool(config.EnableSceneSwitching);
@@ -317,7 +312,6 @@ public void FromBase64(string base64, bool createDummyObject = false)
317312
config.ClientConnectionBufferTimeout = reader.ReadInt32Packed();
318313
config.ConnectionApproval = reader.ReadBool();
319314
config.SecondsHistory = reader.ReadInt32Packed();
320-
config.HandleObjectSpawning = reader.ReadBool();
321315
config.EnableEncryption = reader.ReadBool();
322316
config.SignKeyExchange = reader.ReadBool();
323317
config.EnableSceneSwitching = reader.ReadBool();
@@ -363,7 +357,7 @@ public ulong GetConfig(bool cache = true)
363357
}
364358
}
365359

366-
if (HandleObjectSpawning && ForceSamePrefabs)
360+
if (ForceSamePrefabs)
367361
{
368362
List<NetworkedPrefab> sortedPrefabList = NetworkedPrefabs.OrderBy(x => x.hash).ToList();
369363
for (int i = 0; i < sortedPrefabList.Count; i++)
@@ -373,7 +367,6 @@ public ulong GetConfig(bool cache = true)
373367
}
374368

375369
writer.WriteBool(ForceSamePrefabs);
376-
writer.WriteBool(HandleObjectSpawning);
377370
writer.WriteBool(EnableEncryption);
378371
writer.WriteBool(EnableSceneSwitching);
379372
writer.WriteBool(SignKeyExchange);

0 commit comments

Comments
 (0)