Skip to content

Commit 7079765

Browse files
committed
Enforced get/set rules on all library properties
1 parent 7b42bbf commit 7079765

File tree

5 files changed

+110
-40
lines changed

5 files changed

+110
-40
lines changed

MLAPI/Data/NetworkPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal NetworkPool(int prefabIndex, uint size, ushort poolIndex)
1414
for (int i = 0; i < size; i++)
1515
{
1616
GameObject go = Object.Instantiate(NetworkingManager.singleton.SpawnablePrefabs[prefabIndex], Vector3.zero, Quaternion.identity);
17-
go.GetComponent<NetworkedObject>().isPooledObject = true;
18-
go.GetComponent<NetworkedObject>().PoolId = poolId;
17+
go.GetComponent<NetworkedObject>()._isPooledObject = true;
18+
go.GetComponent<NetworkedObject>().poolId = poolId;
1919
go.GetComponent<NetworkedObject>().Spawn();
2020
go.name = "Pool Id: " + poolId + " #" + i;
2121
go.SetActive(false);

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected bool isHost
6767
}
6868
}
6969
/// <summary>
70-
/// The NetworkedObject that owns this NetworkedBehaviour instance
70+
/// Gets the NetworkedObject that owns this NetworkedBehaviour instance
7171
/// </summary>
7272
public NetworkedObject networkedObject
7373
{
@@ -82,7 +82,7 @@ public NetworkedObject networkedObject
8282
}
8383
private NetworkedObject _networkedObject = null;
8484
/// <summary>
85-
/// The NetworkId of the NetworkedObject that owns the NetworkedBehaviour instance
85+
/// Gets the NetworkId of the NetworkedObject that owns the NetworkedBehaviour instance
8686
/// </summary>
8787
public uint networkId
8888
{
@@ -92,7 +92,7 @@ public uint networkId
9292
}
9393
}
9494
/// <summary>
95-
/// The clientId that owns the NetworkedObject
95+
/// Gets the clientId that owns the NetworkedObject
9696
/// </summary>
9797
public int ownerClientId
9898
{

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,81 @@ namespace MLAPI
99
public class NetworkedObject : MonoBehaviour
1010
{
1111
/// <summary>
12-
/// The unique ID of this object that is synced across the network
12+
/// Gets the unique ID of this object that is synced across the network
1313
/// </summary>
1414
[HideInInspector]
15-
public uint NetworkId;
15+
public uint NetworkId
16+
{
17+
get
18+
{
19+
return networkId;
20+
}
21+
}
22+
internal uint networkId;
1623
/// <summary>
17-
/// The clientId of the owner of this NetworkedObject
24+
/// Gets the clientId of the owner of this NetworkedObject
1825
/// </summary>
1926
[HideInInspector]
20-
public int OwnerClientId = -2;
27+
public int OwnerClientId
28+
{
29+
get
30+
{
31+
return ownerClientId;
32+
}
33+
}
34+
internal int ownerClientId = -2;
2135
/// <summary>
2236
/// The index of the prefab used to spawn this in the spawnablePrefabs list
2337
/// </summary>
2438
[HideInInspector]
25-
public int SpawnablePrefabIndex;
39+
public int SpawnablePrefabIndex
40+
{
41+
get
42+
{
43+
return spawnablePrefabIndex;
44+
}
45+
}
46+
internal int spawnablePrefabIndex;
2647
/// <summary>
2748
/// Gets if this object is a player object
2849
/// </summary>
2950
[HideInInspector]
30-
public bool isPlayerObject = false;
51+
public bool isPlayerObject
52+
{
53+
get
54+
{
55+
return _isPlayerObject;
56+
}
57+
}
58+
internal bool _isPlayerObject = false;
3159
/// <summary>
32-
/// Gets or sets if this object should be replicated across the network
60+
/// Gets or sets if this object should be replicated across the network. Can only be changed before the object is spawned
3361
/// </summary>
3462
public bool ServerOnly = false;
3563
/// <summary>
3664
/// Gets if this object is part of a pool
3765
/// </summary>
3866
[HideInInspector]
39-
public bool isPooledObject = false;
67+
public bool isPooledObject
68+
{
69+
get
70+
{
71+
return _isPooledObject;
72+
}
73+
}
74+
internal bool _isPooledObject = false;
4075
/// <summary>
4176
/// Gets the poolId this object is part of
4277
/// </summary>
4378
[HideInInspector]
44-
public ushort PoolId;
79+
public ushort PoolId
80+
{
81+
get
82+
{
83+
return poolId;
84+
}
85+
}
86+
internal ushort poolId;
4587
/// <summary>
4688
/// Gets if the object is the the personal clients player object
4789
/// </summary>

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ public class NetworkingManager : MonoBehaviour
1717
/// <summary>
1818
/// A syncronized time, represents the time in seconds since the server application started. Is replicated across all clients
1919
/// </summary>
20-
public static float NetworkTime;
20+
public float NetworkTime
21+
{
22+
get
23+
{
24+
return networkTime;
25+
}
26+
}
27+
internal float networkTime;
2128
/// <summary>
2229
/// Gets or sets if the NetworkingManager should be marked as DontDestroyOnLoad
2330
/// </summary>
@@ -37,12 +44,26 @@ public class NetworkingManager : MonoBehaviour
3744
/// <summary>
3845
/// The singleton instance of the NetworkingManager
3946
/// </summary>
40-
public static NetworkingManager singleton;
47+
public static NetworkingManager singleton
48+
{
49+
get
50+
{
51+
return _singleton;
52+
}
53+
}
54+
private static NetworkingManager _singleton;
4155
/// <summary>
4256
/// The clientId the server calls the local client by, only valid for clients
4357
/// </summary>
4458
[HideInInspector]
45-
public int MyClientId;
59+
public int MyClientId
60+
{
61+
get
62+
{
63+
return myClientId;
64+
}
65+
}
66+
internal int myClientId;
4667
internal Dictionary<int, NetworkedClient> connectedClients;
4768
/// <summary>
4869
/// Gets a dictionary of connected clients
@@ -74,7 +95,14 @@ public bool isHost
7495
/// Gets if we are connected as a client
7596
/// </summary>
7697
[HideInInspector]
77-
public bool IsClientConnected;
98+
public bool IsClientConnected
99+
{
100+
get
101+
{
102+
return _isClientConnected;
103+
}
104+
}
105+
internal bool _isClientConnected;
78106
/// <summary>
79107
/// The callback to invoke once a client connects
80108
/// </summary>
@@ -110,7 +138,7 @@ private void OnValidate()
110138
Debug.LogWarning("MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs[i].gameObject.name);
111139
continue;
112140
}
113-
netObject.SpawnablePrefabIndex = i;
141+
netObject.spawnablePrefabIndex = i;
114142
}
115143
}
116144
if (DefaultPlayerPrefab != null)
@@ -126,7 +154,7 @@ private void OnValidate()
126154
private ConnectionConfig Init(NetworkingConfiguration netConfig)
127155
{
128156
NetworkConfig = netConfig;
129-
NetworkTime = 0f;
157+
networkTime = 0f;
130158
lastSendTickTime = 0;
131159
lastEventTickTime = 0;
132160
lastReceiveTickTime = 0;
@@ -360,7 +388,7 @@ private void OnEnable()
360388
Destroy(this);
361389
return;
362390
}
363-
singleton = this;
391+
_singleton = this;
364392
if (DontDestroy)
365393
DontDestroyOnLoad(gameObject);
366394
if (RunInBackground)
@@ -369,7 +397,7 @@ private void OnEnable()
369397

370398
private void OnDestroy()
371399
{
372-
singleton = null;
400+
_singleton = null;
373401
Shutdown();
374402
}
375403

@@ -420,7 +448,7 @@ private void Update()
420448
return;
421449
}
422450
else
423-
IsClientConnected = false;
451+
_isClientConnected = false;
424452

425453
if (OnClientDisconnectCallback != null)
426454
OnClientDisconnectCallback.Invoke(clientId);
@@ -481,7 +509,7 @@ private void Update()
481509
if (isServer)
482510
OnClientDisconnect(clientId);
483511
else
484-
IsClientConnected = false;
512+
_isClientConnected = false;
485513

486514
if (OnClientDisconnectCallback != null)
487515
OnClientDisconnectCallback.Invoke(clientId);
@@ -497,7 +525,7 @@ private void Update()
497525
NetworkedObject.InvokeSyncvarUpdate();
498526
lastEventTickTime = Time.time;
499527
}
500-
NetworkTime += Time.deltaTime;
528+
networkTime += Time.deltaTime;
501529
}
502530
}
503531

@@ -673,7 +701,7 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
673701
{
674702
using (BinaryReader messageReader = new BinaryReader(messageReadStream))
675703
{
676-
MyClientId = messageReader.ReadInt32();
704+
myClientId = messageReader.ReadInt32();
677705
uint sceneIndex = 0;
678706
if(NetworkConfig.EnableSceneSwitching)
679707
{
@@ -709,7 +737,7 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
709737
int msDelay = NetworkTransport.GetRemoteDelayTimeMS(hostId, clientId, remoteStamp, out error);
710738
if ((NetworkError)error != NetworkError.Ok)
711739
msDelay = 0;
712-
NetworkTime = netTime + (msDelay / 1000f);
740+
networkTime = netTime + (msDelay / 1000f);
713741

714742
connectedClients.Add(MyClientId, new NetworkedClient() { ClientId = MyClientId });
715743
int clientCount = messageReader.ReadInt32();
@@ -745,7 +773,7 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
745773
}
746774
}
747775
}
748-
IsClientConnected = true;
776+
_isClientConnected = true;
749777
if (OnClientConnectedCallback != null)
750778
OnClientConnectedCallback.Invoke(clientId);
751779
}
@@ -879,7 +907,7 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
879907
//We are new owner.
880908
SpawnManager.spawnedObjects[netId].InvokeBehaviourOnGainedOwnership();
881909
}
882-
SpawnManager.spawnedObjects[netId].OwnerClientId = ownerClientId;
910+
SpawnManager.spawnedObjects[netId].ownerClientId = ownerClientId;
883911
}
884912
}
885913
}

MLAPI/NetworkingManagerComponents/SpawnManager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal static void RemoveOwnership(uint netId)
3434
{
3535
NetworkedObject netObject = SpawnManager.spawnedObjects[netId];
3636
NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId);
37-
netObject.OwnerClientId = -2;
37+
netObject.ownerClientId = -2;
3838
using (MemoryStream stream = new MemoryStream(8))
3939
{
4040
using (BinaryWriter writer = new BinaryWriter(stream))
@@ -51,7 +51,7 @@ internal static void ChangeOwnership(uint netId, int clientId)
5151
NetworkedObject netObject = SpawnManager.spawnedObjects[netId];
5252
NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId);
5353
NetworkingManager.singleton.connectedClients[clientId].OwnedObjects.Add(netObject);
54-
netObject.OwnerClientId = clientId;
54+
netObject.ownerClientId = clientId;
5555
using (MemoryStream stream = new MemoryStream(8))
5656
{
5757
using (BinaryWriter writer = new BinaryWriter(stream))
@@ -72,16 +72,16 @@ internal static GameObject SpawnObject(int spawnablePrefabIndex, uint networkId,
7272
Debug.LogWarning("MLAPI: Please add a NetworkedObject component to the root of all spawnable objects");
7373
netObject = go.AddComponent<NetworkedObject>();
7474
}
75-
netObject.SpawnablePrefabIndex = spawnablePrefabIndex;
75+
netObject.spawnablePrefabIndex = spawnablePrefabIndex;
7676
if (netManager.isServer)
7777
{
78-
netObject.NetworkId = GetNetworkObjectId();
78+
netObject.networkId = GetNetworkObjectId();
7979
}
8080
else
8181
{
82-
netObject.NetworkId = networkId;
82+
netObject.networkId = networkId;
8383
}
84-
netObject.OwnerClientId = ownerId;
84+
netObject.ownerClientId = ownerId;
8585

8686
spawnedObjects.Add(netObject.NetworkId, netObject);
8787
netObject.InvokeBehaviourNetworkSpawn();
@@ -97,16 +97,16 @@ internal static GameObject SpawnPlayerObject(int clientId, uint networkId)
9797
Debug.LogWarning("MLAPI: Please add a NetworkedObject component to the root of the player prefab");
9898
netObject = go.AddComponent<NetworkedObject>();
9999
}
100-
netObject.OwnerClientId = clientId;
100+
netObject.ownerClientId = clientId;
101101
if (NetworkingManager.singleton.isServer)
102102
{
103-
netObject.NetworkId = GetNetworkObjectId();
103+
netObject.networkId = GetNetworkObjectId();
104104
}
105105
else
106106
{
107-
netObject.NetworkId = networkId;
107+
netObject.networkId = networkId;
108108
}
109-
netObject.isPlayerObject = true;
109+
netObject._isPlayerObject = true;
110110
netManager.connectedClients[clientId].PlayerObject = go;
111111
spawnedObjects.Add(netObject.NetworkId, netObject);
112112
netObject.InvokeBehaviourNetworkSpawn();
@@ -179,7 +179,7 @@ internal static void OnSpawnObject(NetworkedObject netObject, int? clientOwnerId
179179
netObject.isSpawned = true;
180180
if (clientOwnerId != null)
181181
{
182-
netObject.OwnerClientId = clientOwnerId.Value;
182+
netObject.ownerClientId = clientOwnerId.Value;
183183
NetworkingManager.singleton.connectedClients[clientOwnerId.Value].OwnedObjects.Add(netObject);
184184
}
185185
using (MemoryStream stream = new MemoryStream(13))

0 commit comments

Comments
 (0)