Ensured the OwnedObject's list is filled and kept up to date
This commit is contained in:
parent
b4d0303a38
commit
85eee7b0f4
@ -15,7 +15,7 @@ namespace MLAPI.Data
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
GameObject go = Object.Instantiate(NetworkingManager.singleton.SpawnablePrefabs[prefabIndex], Vector3.zero, Quaternion.identity);
|
||||
go.GetComponent<NetworkedObject>().IsPooledObject = true;
|
||||
go.GetComponent<NetworkedObject>().isPooledObject = true;
|
||||
go.GetComponent<NetworkedObject>().PoolId = poolId;
|
||||
go.GetComponent<NetworkedObject>().Spawn();
|
||||
go.name = "Pool Id: " + poolId + " #" + i;
|
||||
|
@ -15,7 +15,7 @@ namespace MLAPI
|
||||
public bool isPlayerObject = false;
|
||||
public bool ServerOnly = false;
|
||||
[HideInInspector]
|
||||
public bool IsPooledObject = false;
|
||||
public bool isPooledObject = false;
|
||||
[HideInInspector]
|
||||
public ushort PoolId;
|
||||
public bool isLocalPlayer
|
||||
|
@ -33,6 +33,7 @@ namespace MLAPI.NetworkingManagerComponents
|
||||
internal static void RemoveOwnership(uint netId)
|
||||
{
|
||||
NetworkedObject netObject = SpawnManager.spawnedObjects[netId];
|
||||
NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId);
|
||||
netObject.OwnerClientId = -2;
|
||||
using (MemoryStream stream = new MemoryStream(8))
|
||||
{
|
||||
@ -48,6 +49,8 @@ namespace MLAPI.NetworkingManagerComponents
|
||||
internal static void ChangeOwnership(uint netId, int clientId)
|
||||
{
|
||||
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;
|
||||
using (MemoryStream stream = new MemoryStream(8))
|
||||
{
|
||||
@ -114,6 +117,11 @@ namespace MLAPI.NetworkingManagerComponents
|
||||
{
|
||||
if (!spawnedObjects.ContainsKey(networkId) || (netManager != null && !netManager.NetworkConfig.HandleObjectSpawning))
|
||||
return;
|
||||
if (spawnedObjects[networkId].OwnerClientId > -2 && !spawnedObjects[networkId].isPlayerObject)
|
||||
{
|
||||
//Someone owns it.
|
||||
NetworkingManager.singleton.connectedClients[spawnedObjects[networkId].OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == networkId);
|
||||
}
|
||||
GameObject go = spawnedObjects[networkId].gameObject;
|
||||
if (netManager != null && netManager.isServer)
|
||||
{
|
||||
@ -170,7 +178,10 @@ namespace MLAPI.NetworkingManagerComponents
|
||||
spawnedObjects.Add(netId, netObject);
|
||||
netObject.isSpawned = true;
|
||||
if (clientOwnerId != null)
|
||||
{
|
||||
netObject.OwnerClientId = clientOwnerId.Value;
|
||||
NetworkingManager.singleton.connectedClients[clientOwnerId.Value].OwnedObjects.Add(netObject);
|
||||
}
|
||||
using (MemoryStream stream = new MemoryStream(13))
|
||||
{
|
||||
using (BinaryWriter writer = new BinaryWriter(stream))
|
||||
|
Loading…
x
Reference in New Issue
Block a user