Added owned objects
This commit is contained in:
parent
f83d50a2b2
commit
18da9a5978
@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MLAPI
|
namespace MLAPI
|
||||||
{
|
{
|
||||||
@ -6,5 +7,6 @@ namespace MLAPI
|
|||||||
{
|
{
|
||||||
public int ClientId;
|
public int ClientId;
|
||||||
public GameObject PlayerObject;
|
public GameObject PlayerObject;
|
||||||
|
public List<NetworkedObject> OwnedObjects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,21 @@ namespace MLAPI
|
|||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public int SpawnablePrefabIndex;
|
public int SpawnablePrefabIndex;
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public bool IsPlayerObject = false;
|
public bool isPlayerObject = false;
|
||||||
public bool ServerOnly = false;
|
public bool ServerOnly = false;
|
||||||
public bool isLocalPlayer
|
public bool isLocalPlayer
|
||||||
{
|
{
|
||||||
get
|
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;
|
internal bool isSpawned = false;
|
||||||
|
|
||||||
public void Spawn()
|
public void Spawn()
|
||||||
{
|
{
|
||||||
NetworkingManager.singleton.OnSpawnObject(this);
|
NetworkingManager.singleton.OnSpawnObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SpawnWithOwnership(int clientId)
|
||||||
|
{
|
||||||
|
NetworkingManager.singleton.OnSpawnObject(this, clientId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ namespace MLAPI
|
|||||||
{
|
{
|
||||||
netObject.NetworkId = networkId;
|
netObject.NetworkId = networkId;
|
||||||
}
|
}
|
||||||
netObject.IsPlayerObject = true;
|
netObject.isPlayerObject = true;
|
||||||
connectedClients[clientId].PlayerObject = go;
|
connectedClients[clientId].PlayerObject = go;
|
||||||
singleton.spawnedObjects.Add(netObject.NetworkId, netObject);
|
singleton.spawnedObjects.Add(netObject.NetworkId, netObject);
|
||||||
return go;
|
return go;
|
||||||
@ -834,6 +834,10 @@ namespace MLAPI
|
|||||||
if(NetworkConfig.HandleObjectSpawning)
|
if(NetworkConfig.HandleObjectSpawning)
|
||||||
{
|
{
|
||||||
Destroy(connectedClients[clientId].PlayerObject);
|
Destroy(connectedClients[clientId].PlayerObject);
|
||||||
|
for (int i = 0; i < connectedClients[clientId].OwnedObjects.Count; i++)
|
||||||
|
{
|
||||||
|
Destroy(connectedClients[clientId].OwnedObjects[i].gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
connectedClients.Remove(clientId);
|
connectedClients.Remove(clientId);
|
||||||
}
|
}
|
||||||
@ -904,7 +908,7 @@ namespace MLAPI
|
|||||||
|
|
||||||
if (pair.Value.ServerOnly)
|
if (pair.Value.ServerOnly)
|
||||||
continue;
|
continue;
|
||||||
writer.Write(pair.Value.IsPlayerObject);
|
writer.Write(pair.Value.isPlayerObject);
|
||||||
writer.Write(pair.Value.NetworkId);
|
writer.Write(pair.Value.NetworkId);
|
||||||
writer.Write(pair.Value.OwnerClientId);
|
writer.Write(pair.Value.OwnerClientId);
|
||||||
writer.Write(pair.Value.SpawnablePrefabIndex);
|
writer.Write(pair.Value.SpawnablePrefabIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user