Added spawn position and rotation to ConnectionApproval
This commit is contained in:
parent
3b0d7b592c
commit
21b5942106
@ -136,7 +136,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The callback to invoke during connection approval
|
/// The callback to invoke during connection approval
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<byte[], uint, Action<uint, bool>> ConnectionApprovalCallback = null;
|
public Action<byte[], uint, Action<uint, bool, Vector3, Quaternion>> ConnectionApprovalCallback = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current NetworkingConfiguration
|
/// The current NetworkingConfiguration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -586,13 +586,14 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts a Host
|
/// Starts a Host
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StartHost()
|
public void StartHost(Vector3? pos = null, Quaternion? rot = null)
|
||||||
{
|
{
|
||||||
if (isServer || isClient)
|
if (isServer || isClient)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("MLAPI: Cannot start host while an instance is already running");
|
Debug.LogWarning("MLAPI: Cannot start host while an instance is already running");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionConfig cConfig = Init(true);
|
ConnectionConfig cConfig = Init(true);
|
||||||
if (NetworkConfig.ConnectionApproval)
|
if (NetworkConfig.ConnectionApproval)
|
||||||
{
|
{
|
||||||
@ -622,7 +623,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
|
|
||||||
if(NetworkConfig.HandleObjectSpawning)
|
if(NetworkConfig.HandleObjectSpawning)
|
||||||
{
|
{
|
||||||
SpawnManager.SpawnPlayerObject(netId.GetClientId(), 0);
|
SpawnManager.SpawnPlayerObject(netId.GetClientId(), 0, pos.GetValueOrDefault(), rot.GetValueOrDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OnServerStarted != null)
|
if (OnServerStarted != null)
|
||||||
@ -952,7 +953,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HandleApproval(clientId, true);
|
HandleApproval(clientId, true, Vector3.zero, Quaternion.identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1035,7 +1036,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
|
|
||||||
if (isPlayerObject)
|
if (isPlayerObject)
|
||||||
{
|
{
|
||||||
SpawnManager.SpawnPlayerObject(ownerId, networkId);
|
SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1086,7 +1087,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
if (isPlayerObject)
|
if (isPlayerObject)
|
||||||
{
|
{
|
||||||
connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });
|
connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });
|
||||||
SpawnManager.SpawnPlayerObject(ownerId, networkId);
|
SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1161,7 +1162,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
float yRot = messageReader.ReadSingle();
|
float yRot = messageReader.ReadSingle();
|
||||||
float zRot = messageReader.ReadSingle();
|
float zRot = messageReader.ReadSingle();
|
||||||
SpawnManager.spawnedObjects[netId].transform.position = new Vector3(xPos, yPos, zPos);
|
SpawnManager.spawnedObjects[netId].transform.position = new Vector3(xPos, yPos, zPos);
|
||||||
SpawnManager.spawnedObjects[netId].transform.rotation = Quaternion.Euler(new Vector3(xRot, yRot, zRot));
|
SpawnManager.spawnedObjects[netId].transform.rotation = Quaternion.Euler(xRot, yRot, zRot);
|
||||||
SpawnManager.spawnedObjects[netId].gameObject.SetActive(true);
|
SpawnManager.spawnedObjects[netId].gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1336,7 +1337,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
if (isPlayerObject)
|
if (isPlayerObject)
|
||||||
{
|
{
|
||||||
connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });
|
connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });
|
||||||
SpawnManager.SpawnPlayerObject(ownerId, networkId);
|
SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1778,7 +1779,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleApproval(uint clientId, bool approved)
|
private void HandleApproval(uint clientId, bool approved, Vector3 position, Quaternion rotation)
|
||||||
{
|
{
|
||||||
if(approved)
|
if(approved)
|
||||||
{
|
{
|
||||||
@ -1819,7 +1820,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
if(NetworkConfig.HandleObjectSpawning)
|
if(NetworkConfig.HandleObjectSpawning)
|
||||||
{
|
{
|
||||||
uint networkId = SpawnManager.GetNetworkObjectId();
|
uint networkId = SpawnManager.GetNetworkObjectId();
|
||||||
GameObject go = SpawnManager.SpawnPlayerObject(clientId, networkId);
|
GameObject go = SpawnManager.SpawnPlayerObject(clientId, networkId, position, rotation);
|
||||||
connectedClients[clientId].PlayerObject = go;
|
connectedClients[clientId].PlayerObject = go;
|
||||||
}
|
}
|
||||||
int sizeOfStream = 17 + ((connectedClients.Count - 1) * 4);
|
int sizeOfStream = 17 + ((connectedClients.Count - 1) * 4);
|
||||||
|
@ -217,14 +217,14 @@ namespace MLAPI.NetworkingManagerComponents.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static GameObject SpawnPlayerObject(uint clientId, uint networkId)
|
internal static GameObject SpawnPlayerObject(uint clientId, uint networkId, Vector3 position, Quaternion rotation)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(netManager.NetworkConfig.PlayerPrefabName) || !netManager.NetworkConfig.NetworkPrefabIds.ContainsKey(netManager.NetworkConfig.PlayerPrefabName))
|
if (string.IsNullOrEmpty(netManager.NetworkConfig.PlayerPrefabName) || !netManager.NetworkConfig.NetworkPrefabIds.ContainsKey(netManager.NetworkConfig.PlayerPrefabName))
|
||||||
{
|
{
|
||||||
Debug.LogWarning("MLAPI: There is no player prefab in the NetworkConfig, or it's not registered at as a spawnable prefab");
|
Debug.LogWarning("MLAPI: There is no player prefab in the NetworkConfig, or it's not registered at as a spawnable prefab");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
GameObject go = MonoBehaviour.Instantiate(netManager.NetworkConfig.NetworkedPrefabs[netManager.NetworkConfig.NetworkPrefabIds[netManager.NetworkConfig.PlayerPrefabName]].prefab);
|
GameObject go = MonoBehaviour.Instantiate(netManager.NetworkConfig.NetworkedPrefabs[netManager.NetworkConfig.NetworkPrefabIds[netManager.NetworkConfig.PlayerPrefabName]].prefab, position, rotation);
|
||||||
NetworkedObject netObject = go.GetComponent<NetworkedObject>();
|
NetworkedObject netObject = go.GetComponent<NetworkedObject>();
|
||||||
if (netObject == null)
|
if (netObject == null)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user