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.
34 lines
964 B
34 lines
964 B
|
|
using Unity.Burst; |
|
using Unity.Collections; |
|
using Unity.Jobs; |
|
using Unity.Networking.Transport; |
|
using UnityEngine; |
|
|
|
[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("Accepted a connection"); |
|
} |
|
} |
|
}
|
|
|