Added owned objects

This commit is contained in:
Albin Corén 2018-01-07 07:33:55 +01:00
parent f83d50a2b2
commit 18da9a5978
3 changed files with 25 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
namespace MLAPI
{
@ -6,5 +7,6 @@ namespace MLAPI
{
public int ClientId;
public GameObject PlayerObject;
public List<NetworkedObject> OwnedObjects;
}
}

View File

@ -11,13 +11,21 @@ namespace MLAPI
[HideInInspector]
public int SpawnablePrefabIndex;
[HideInInspector]
public bool IsPlayerObject = false;
public bool isPlayerObject = false;
public bool ServerOnly = false;
public bool isLocalPlayer
{
get
{
return IsPlayerObject && (OwnerClientId == NetworkingManager.singleton.MyClientId || (OwnerClientId == -1 && NetworkingManager.singleton.isHost));
return isPlayerObject && (OwnerClientId == NetworkingManager.singleton.MyClientId || (OwnerClientId == -1 && NetworkingManager.singleton.isHost));
}
}
public bool IsOwner
{
get
{
return !isPlayerObject && (OwnerClientId == NetworkingManager.singleton.MyClientId || (OwnerClientId == -1 && NetworkingManager.singleton.isHost));
}
}
@ -27,9 +35,15 @@ namespace MLAPI
}
internal bool isSpawned = false;
public void Spawn()
{
NetworkingManager.singleton.OnSpawnObject(this);
}
public void SpawnWithOwnership(int clientId)
{
NetworkingManager.singleton.OnSpawnObject(this, clientId);
}
}
}

View File

@ -122,7 +122,7 @@ namespace MLAPI
{
netObject.NetworkId = networkId;
}
netObject.IsPlayerObject = true;
netObject.isPlayerObject = true;
connectedClients[clientId].PlayerObject = go;
singleton.spawnedObjects.Add(netObject.NetworkId, netObject);
return go;
@ -834,6 +834,10 @@ namespace MLAPI
if(NetworkConfig.HandleObjectSpawning)
{
Destroy(connectedClients[clientId].PlayerObject);
for (int i = 0; i < connectedClients[clientId].OwnedObjects.Count; i++)
{
Destroy(connectedClients[clientId].OwnedObjects[i].gameObject);
}
}
connectedClients.Remove(clientId);
}
@ -904,7 +908,7 @@ namespace MLAPI
if (pair.Value.ServerOnly)
continue;
writer.Write(pair.Value.IsPlayerObject);
writer.Write(pair.Value.isPlayerObject);
writer.Write(pair.Value.NetworkId);
writer.Write(pair.Value.OwnerClientId);
writer.Write(pair.Value.SpawnablePrefabIndex);