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.
58 lines
1.5 KiB
58 lines
1.5 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using GameCore.Network; |
|
using Unity.Collections; |
|
using Unity.Jobs; |
|
using Unity.Networking.Transport; |
|
using UnityEngine; |
|
|
|
public class ServerMain : MonoBehaviour |
|
{ |
|
public string address = "127.0.0.1"; |
|
public NetworkDriverAsset driverAsset; |
|
|
|
private NetworkDriver driver; |
|
private JobHandle networkJobHandle; |
|
private NativeList<NetworkConnection> connectionList; |
|
private NativeList<int> disconnectIndexList; |
|
|
|
private void OnEnable() |
|
{ |
|
driver = driverAsset.CreateServerDriver(address); |
|
|
|
connectionList = new NativeList<NetworkConnection>(16,Allocator.Persistent); |
|
disconnectIndexList = new NativeList<int>(16, Allocator.Persistent); |
|
} |
|
|
|
private void OnDisable() |
|
{ |
|
networkJobHandle.Complete(); |
|
|
|
driver.Dispose(); |
|
|
|
connectionList.Dispose(); |
|
disconnectIndexList.Dispose(); |
|
} |
|
|
|
void Update() |
|
{ |
|
networkJobHandle.Complete(); |
|
|
|
var concurrentDriver = driver.ToConcurrent(); |
|
|
|
networkJobHandle = driver.ScheduleUpdate(); |
|
networkJobHandle = new ServerConnectionJob() |
|
{ |
|
driver = driver, |
|
connectionList = connectionList, |
|
disconnectIndexList = disconnectIndexList, |
|
}.Schedule(networkJobHandle); |
|
|
|
networkJobHandle = new ServerReceiveJob() |
|
{ |
|
driver = concurrentDriver, |
|
}.Schedule(connectionList, 16, networkJobHandle); |
|
|
|
} |
|
}
|
|
|