添加client

This commit is contained in:
sunqinzhe committed 2025-12-15 21:13:59 +08:00
1 parent 5c4c25664d
commit 6256dcb52b
19 files changed
+310 -144

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
using System;
using GameCore.Network;
using Unity.Collections;
using Unity.Jobs;
using Unity.Networking.Transport;
using UnityEngine;
namespace ECSTest
{
public class ClientMain : MonoBehaviour
{
public string address = "127.0.0.1";
public NetworkDriverAsset driverAsset;
private NetworkDriver driver;
private NetworkPipeline unreliablePipeline;
private NetworkPipeline reliablePipeline;
private NativeReference<NetworkConnection> connection;
private JobHandle jobHandle;
private void OnEnable()
{
driver = driverAsset.CreateClientDriver(address, out var c, out unreliablePipeline, out reliablePipeline);
connection = new NativeReference<NetworkConnection>(c, Allocator.Persistent);
}
private void OnDisable()
{
jobHandle.Complete();
if (connection.IsCreated)
{
driver.Disconnect(connection.Value);
driver.ScheduleUpdate().Complete();
}
connection.Dispose();
driver.Dispose();
}
void Update()
{
jobHandle.Complete();
//TODO Render()
}
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d126d712307544dd89716677e730aa93
timeCreated: 1765786534
+26
View File
@@ -0,0 +1,26 @@
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Networking.Transport;
namespace ECSTest
{
[BurstCompile]
public struct ClientUpdateJob : IJob
{
public NetworkDriver driver;
public NetworkPipeline unreliablePipeline;
public NetworkPipeline reliablePipeline;
public NativeReference<NetworkConnection> connection;
public void Execute()
{
NetworkEvent.Type cmd;
while ((cmd = connection.Value.PopEvent(driver, out var stream, out var networkPipeline)) !=
NetworkEvent.Type.Empty)
{
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ffb4af76205e4a638c5343a82b13ce08
timeCreated: 1765789910