parent
3fe3366e75
commit
5c4c25664d
17 changed files with 264 additions and 75 deletions
@ -0,0 +1,18 @@ |
|||||||
|
%YAML 1.1 |
||||||
|
%TAG !u! tag:unity3d.com,2011: |
||||||
|
--- !u!114 &11400000 |
||||||
|
MonoBehaviour: |
||||||
|
m_ObjectHideFlags: 0 |
||||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||||
|
m_PrefabInstance: {fileID: 0} |
||||||
|
m_PrefabAsset: {fileID: 0} |
||||||
|
m_GameObject: {fileID: 0} |
||||||
|
m_Enabled: 1 |
||||||
|
m_EditorHideFlags: 0 |
||||||
|
m_Script: {fileID: 11500000, guid: b79190dcfae6a2f4fbdfc9deccf00ef7, type: 3} |
||||||
|
m_Name: NetworkDriverAsset |
||||||
|
m_EditorClassIdentifier: |
||||||
|
useSimulator: 0 |
||||||
|
packetDelayMs: 500 |
||||||
|
packetJitterMs: 300 |
||||||
|
packetDropPercentage: 10 |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: a8a5562854ecf4cc1a49700e8bd93c19 |
||||||
|
NativeFormatImporter: |
||||||
|
externalObjects: {} |
||||||
|
mainObjectFileID: 11400000 |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
||||||
@ -1,18 +0,0 @@ |
|||||||
{ |
|
||||||
"name": "Game.Test", |
|
||||||
"rootNamespace": "", |
|
||||||
"references": [ |
|
||||||
"nimin.tinyecs", |
|
||||||
"Unity.Mathematics", |
|
||||||
"Unity.Burst" |
|
||||||
], |
|
||||||
"includePlatforms": [], |
|
||||||
"excludePlatforms": [], |
|
||||||
"allowUnsafeCode": false, |
|
||||||
"overrideReferences": false, |
|
||||||
"precompiledReferences": [], |
|
||||||
"autoReferenced": true, |
|
||||||
"defineConstraints": [], |
|
||||||
"versionDefines": [], |
|
||||||
"noEngineReferences": false |
|
||||||
} |
|
||||||
@ -1,6 +1,7 @@ |
|||||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||||
guid: 21d33bf0450d14e5289fe083b8566dbe |
guid: d142cdba4cc3f491d81c6e563975b2cf |
||||||
AssemblyDefinitionImporter: |
folderAsset: yes |
||||||
|
DefaultImporter: |
||||||
externalObjects: {} |
externalObjects: {} |
||||||
userData: |
userData: |
||||||
assetBundleName: |
assetBundleName: |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
|
||||||
|
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"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 11f164db7c4a4cdb9ea508c2fd4d73c8 |
||||||
|
timeCreated: 1765740990 |
||||||
@ -0,0 +1,58 @@ |
|||||||
|
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); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 1da32d64fdd4d41778db4fd91607ac27 |
||||||
|
MonoImporter: |
||||||
|
externalObjects: {} |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
|
||||||
|
using Unity.Burst; |
||||||
|
using Unity.Jobs; |
||||||
|
using Unity.Networking.Transport; |
||||||
|
|
||||||
|
[BurstCompile] |
||||||
|
public struct ServerReceiveJob : IJobParallelForDefer |
||||||
|
{ |
||||||
|
public NetworkDriver.Concurrent driver; |
||||||
|
|
||||||
|
public void Execute(int index) |
||||||
|
{ |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 8ef77fd6553341dca22f002180a6110c |
||||||
|
timeCreated: 1765741627 |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
|
||||||
|
using Unity.Burst; |
||||||
|
using Unity.Jobs; |
||||||
|
|
||||||
|
[BurstCompile] |
||||||
|
public struct ServerSendJob : IJobParallelFor |
||||||
|
{ |
||||||
|
public void Execute(int index) |
||||||
|
{ |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: ea3a154338e247378d2088203f16575c |
||||||
|
timeCreated: 1765739309 |
||||||
Loading…
Reference in new issue