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 connectionList; private NativeList disconnectIndexList; private void OnEnable() { driver = driverAsset.CreateServerDriver(address); connectionList = new NativeList(16,Allocator.Persistent); disconnectIndexList = new NativeList(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); } }