diff --git a/MLAPI/Data/NetworkPool.cs b/MLAPI/Data/NetworkPool.cs index 18fd52d..9c23e4c 100644 --- a/MLAPI/Data/NetworkPool.cs +++ b/MLAPI/Data/NetworkPool.cs @@ -14,8 +14,8 @@ namespace MLAPI.Data for (int i = 0; i < size; i++) { GameObject go = Object.Instantiate(NetworkingManager.singleton.SpawnablePrefabs[prefabIndex], Vector3.zero, Quaternion.identity); - go.GetComponent().isPooledObject = true; - go.GetComponent().PoolId = poolId; + go.GetComponent()._isPooledObject = true; + go.GetComponent().poolId = poolId; go.GetComponent().Spawn(); go.name = "Pool Id: " + poolId + " #" + i; go.SetActive(false); diff --git a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs index 8836a71..e0c199f 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs @@ -67,7 +67,7 @@ namespace MLAPI } } /// - /// The NetworkedObject that owns this NetworkedBehaviour instance + /// Gets the NetworkedObject that owns this NetworkedBehaviour instance /// public NetworkedObject networkedObject { @@ -82,7 +82,7 @@ namespace MLAPI } private NetworkedObject _networkedObject = null; /// - /// The NetworkId of the NetworkedObject that owns the NetworkedBehaviour instance + /// Gets the NetworkId of the NetworkedObject that owns the NetworkedBehaviour instance /// public uint networkId { @@ -92,7 +92,7 @@ namespace MLAPI } } /// - /// The clientId that owns the NetworkedObject + /// Gets the clientId that owns the NetworkedObject /// public int ownerClientId { diff --git a/MLAPI/MonoBehaviours/Core/NetworkedObject.cs b/MLAPI/MonoBehaviours/Core/NetworkedObject.cs index 62f9c1d..d258662 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkedObject.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkedObject.cs @@ -9,39 +9,81 @@ namespace MLAPI public class NetworkedObject : MonoBehaviour { /// - /// The unique ID of this object that is synced across the network + /// Gets the unique ID of this object that is synced across the network /// [HideInInspector] - public uint NetworkId; + public uint NetworkId + { + get + { + return networkId; + } + } + internal uint networkId; /// - /// The clientId of the owner of this NetworkedObject + /// Gets the clientId of the owner of this NetworkedObject /// [HideInInspector] - public int OwnerClientId = -2; + public int OwnerClientId + { + get + { + return ownerClientId; + } + } + internal int ownerClientId = -2; /// /// The index of the prefab used to spawn this in the spawnablePrefabs list /// [HideInInspector] - public int SpawnablePrefabIndex; + public int SpawnablePrefabIndex + { + get + { + return spawnablePrefabIndex; + } + } + internal int spawnablePrefabIndex; /// /// Gets if this object is a player object /// [HideInInspector] - public bool isPlayerObject = false; + public bool isPlayerObject + { + get + { + return _isPlayerObject; + } + } + internal bool _isPlayerObject = false; /// - /// Gets or sets if this object should be replicated across the network + /// Gets or sets if this object should be replicated across the network. Can only be changed before the object is spawned /// public bool ServerOnly = false; /// /// Gets if this object is part of a pool /// [HideInInspector] - public bool isPooledObject = false; + public bool isPooledObject + { + get + { + return _isPooledObject; + } + } + internal bool _isPooledObject = false; /// /// Gets the poolId this object is part of /// [HideInInspector] - public ushort PoolId; + public ushort PoolId + { + get + { + return poolId; + } + } + internal ushort poolId; /// /// Gets if the object is the the personal clients player object /// diff --git a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs index 034bff8..89b1848 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs @@ -17,7 +17,14 @@ namespace MLAPI /// /// A syncronized time, represents the time in seconds since the server application started. Is replicated across all clients /// - public static float NetworkTime; + public float NetworkTime + { + get + { + return networkTime; + } + } + internal float networkTime; /// /// Gets or sets if the NetworkingManager should be marked as DontDestroyOnLoad /// @@ -37,12 +44,26 @@ namespace MLAPI /// /// The singleton instance of the NetworkingManager /// - public static NetworkingManager singleton; + public static NetworkingManager singleton + { + get + { + return _singleton; + } + } + private static NetworkingManager _singleton; /// /// The clientId the server calls the local client by, only valid for clients /// [HideInInspector] - public int MyClientId; + public int MyClientId + { + get + { + return myClientId; + } + } + internal int myClientId; internal Dictionary connectedClients; /// /// Gets a dictionary of connected clients @@ -74,7 +95,14 @@ namespace MLAPI /// Gets if we are connected as a client /// [HideInInspector] - public bool IsClientConnected; + public bool IsClientConnected + { + get + { + return _isClientConnected; + } + } + internal bool _isClientConnected; /// /// The callback to invoke once a client connects /// @@ -110,7 +138,7 @@ namespace MLAPI Debug.LogWarning("MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs[i].gameObject.name); continue; } - netObject.SpawnablePrefabIndex = i; + netObject.spawnablePrefabIndex = i; } } if (DefaultPlayerPrefab != null) @@ -126,7 +154,7 @@ namespace MLAPI private ConnectionConfig Init(NetworkingConfiguration netConfig) { NetworkConfig = netConfig; - NetworkTime = 0f; + networkTime = 0f; lastSendTickTime = 0; lastEventTickTime = 0; lastReceiveTickTime = 0; @@ -360,7 +388,7 @@ namespace MLAPI Destroy(this); return; } - singleton = this; + _singleton = this; if (DontDestroy) DontDestroyOnLoad(gameObject); if (RunInBackground) @@ -369,7 +397,7 @@ namespace MLAPI private void OnDestroy() { - singleton = null; + _singleton = null; Shutdown(); } @@ -420,7 +448,7 @@ namespace MLAPI return; } else - IsClientConnected = false; + _isClientConnected = false; if (OnClientDisconnectCallback != null) OnClientDisconnectCallback.Invoke(clientId); @@ -481,7 +509,7 @@ namespace MLAPI if (isServer) OnClientDisconnect(clientId); else - IsClientConnected = false; + _isClientConnected = false; if (OnClientDisconnectCallback != null) OnClientDisconnectCallback.Invoke(clientId); @@ -497,7 +525,7 @@ namespace MLAPI NetworkedObject.InvokeSyncvarUpdate(); lastEventTickTime = Time.time; } - NetworkTime += Time.deltaTime; + networkTime += Time.deltaTime; } } @@ -673,7 +701,7 @@ namespace MLAPI { using (BinaryReader messageReader = new BinaryReader(messageReadStream)) { - MyClientId = messageReader.ReadInt32(); + myClientId = messageReader.ReadInt32(); uint sceneIndex = 0; if(NetworkConfig.EnableSceneSwitching) { @@ -709,7 +737,7 @@ namespace MLAPI int msDelay = NetworkTransport.GetRemoteDelayTimeMS(hostId, clientId, remoteStamp, out error); if ((NetworkError)error != NetworkError.Ok) msDelay = 0; - NetworkTime = netTime + (msDelay / 1000f); + networkTime = netTime + (msDelay / 1000f); connectedClients.Add(MyClientId, new NetworkedClient() { ClientId = MyClientId }); int clientCount = messageReader.ReadInt32(); @@ -745,7 +773,7 @@ namespace MLAPI } } } - IsClientConnected = true; + _isClientConnected = true; if (OnClientConnectedCallback != null) OnClientConnectedCallback.Invoke(clientId); } @@ -879,7 +907,7 @@ namespace MLAPI //We are new owner. SpawnManager.spawnedObjects[netId].InvokeBehaviourOnGainedOwnership(); } - SpawnManager.spawnedObjects[netId].OwnerClientId = ownerClientId; + SpawnManager.spawnedObjects[netId].ownerClientId = ownerClientId; } } } diff --git a/MLAPI/NetworkingManagerComponents/SpawnManager.cs b/MLAPI/NetworkingManagerComponents/SpawnManager.cs index 65cb25b..ff36530 100644 --- a/MLAPI/NetworkingManagerComponents/SpawnManager.cs +++ b/MLAPI/NetworkingManagerComponents/SpawnManager.cs @@ -34,7 +34,7 @@ namespace MLAPI.NetworkingManagerComponents { NetworkedObject netObject = SpawnManager.spawnedObjects[netId]; NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId); - netObject.OwnerClientId = -2; + netObject.ownerClientId = -2; using (MemoryStream stream = new MemoryStream(8)) { using (BinaryWriter writer = new BinaryWriter(stream)) @@ -51,7 +51,7 @@ namespace MLAPI.NetworkingManagerComponents NetworkedObject netObject = SpawnManager.spawnedObjects[netId]; NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId); NetworkingManager.singleton.connectedClients[clientId].OwnedObjects.Add(netObject); - netObject.OwnerClientId = clientId; + netObject.ownerClientId = clientId; using (MemoryStream stream = new MemoryStream(8)) { using (BinaryWriter writer = new BinaryWriter(stream)) @@ -72,16 +72,16 @@ namespace MLAPI.NetworkingManagerComponents Debug.LogWarning("MLAPI: Please add a NetworkedObject component to the root of all spawnable objects"); netObject = go.AddComponent(); } - netObject.SpawnablePrefabIndex = spawnablePrefabIndex; + netObject.spawnablePrefabIndex = spawnablePrefabIndex; if (netManager.isServer) { - netObject.NetworkId = GetNetworkObjectId(); + netObject.networkId = GetNetworkObjectId(); } else { - netObject.NetworkId = networkId; + netObject.networkId = networkId; } - netObject.OwnerClientId = ownerId; + netObject.ownerClientId = ownerId; spawnedObjects.Add(netObject.NetworkId, netObject); netObject.InvokeBehaviourNetworkSpawn(); @@ -97,16 +97,16 @@ namespace MLAPI.NetworkingManagerComponents Debug.LogWarning("MLAPI: Please add a NetworkedObject component to the root of the player prefab"); netObject = go.AddComponent(); } - netObject.OwnerClientId = clientId; + netObject.ownerClientId = clientId; if (NetworkingManager.singleton.isServer) { - netObject.NetworkId = GetNetworkObjectId(); + netObject.networkId = GetNetworkObjectId(); } else { - netObject.NetworkId = networkId; + netObject.networkId = networkId; } - netObject.isPlayerObject = true; + netObject._isPlayerObject = true; netManager.connectedClients[clientId].PlayerObject = go; spawnedObjects.Add(netObject.NetworkId, netObject); netObject.InvokeBehaviourNetworkSpawn(); @@ -179,7 +179,7 @@ namespace MLAPI.NetworkingManagerComponents netObject.isSpawned = true; if (clientOwnerId != null) { - netObject.OwnerClientId = clientOwnerId.Value; + netObject.ownerClientId = clientOwnerId.Value; NetworkingManager.singleton.connectedClients[clientOwnerId.Value].OwnedObjects.Add(netObject); } using (MemoryStream stream = new MemoryStream(13))