You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Unity.Burst;
|
|
|
|
|
using Unity.Collections;
|
|
|
|
|
using Unity.Jobs;
|
|
|
|
|
using Unity.Networking.Transport;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace ECSTest
|
|
|
|
|
{
|
|
|
|
|
[BurstCompile]
|
|
|
|
|
public struct ServerConnectionJob : IJob
|
|
|
|
|
{
|
|
|
|
|
public NetworkDriver driver;
|
|
|
|
|
public NativeList<NetworkConnection> connectionList;
|
|
|
|
|
public NativeList<int> disconnectIndexList;
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
{
|
|
|
|
|
// disconnect
|
|
|
|
|
disconnectIndexList.Sort();
|
|
|
|
|
for (int i = disconnectIndexList.Length - 1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
var index = disconnectIndexList[i];
|
|
|
|
|
connectionList.RemoveAtSwapBack(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disconnectIndexList.Clear();
|
|
|
|
|
|
|
|
|
|
// connect
|
|
|
|
|
NetworkConnection c;
|
|
|
|
|
while ((c = driver.Accept()) != default)
|
|
|
|
|
{
|
|
|
|
|
connectionList.Add(c);
|
|
|
|
|
Debug.Log("[Server] Accepted a connection");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (connectionList.Length > disconnectIndexList.Capacity)
|
|
|
|
|
disconnectIndexList.SetCapacity(connectionList.Length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|