添加client
This commit is contained in:
1 parent
5c4c25664d
commit
6256dcb52b
19 files changed
+310
-144
No files matched your search
@@ -38,7 +38,6 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 705507994}
|
||||
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@@ -104,7 +103,7 @@ NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
serializedVersion: 3
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
@@ -117,7 +116,7 @@ NavMeshSettings:
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
buildHeightMesh: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
@@ -209,13 +208,13 @@ Transform:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 705507993}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||
--- !u!1 &963194225
|
||||
GameObject:
|
||||
@@ -258,9 +257,17 @@ Camera:
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_Iso: 200
|
||||
m_ShutterSpeed: 0.005
|
||||
m_Aperture: 16
|
||||
m_FocusDistance: 10
|
||||
m_FocalLength: 50
|
||||
m_BladeCount: 5
|
||||
m_Curvature: {x: 2, y: 11}
|
||||
m_BarrelClipping: 0.25
|
||||
m_Anamorphism: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
@@ -294,13 +301,13 @@ Transform:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &963194229
|
||||
MonoBehaviour:
|
||||
@@ -314,3 +321,56 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 694d8256118344eb2b130fceb1a11b7f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1936170114
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1936170116}
|
||||
- component: {fileID: 1936170115}
|
||||
m_Layer: 0
|
||||
m_Name: ServerMain
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1936170115
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1936170114}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1da32d64fdd4d41778db4fd91607ac27, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
address: 127.0.0.1
|
||||
driverAsset: {fileID: 11400000, guid: a8a5562854ecf4cc1a49700e8bd93c19, type: 2}
|
||||
--- !u!4 &1936170116
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1936170114}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1660057539 &9223372036854775807
|
||||
SceneRoots:
|
||||
m_ObjectHideFlags: 0
|
||||
m_Roots:
|
||||
- {fileID: 963194228}
|
||||
- {fileID: 705507995}
|
||||
- {fileID: 1936170116}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48c265b50587429a9a7555df18d64661
|
||||
timeCreated: 1765786522
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d126d712307544dd89716677e730aa93
|
||||
timeCreated: 1765786534
|
||||
@@ -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
|
||||
@@ -1,7 +1,7 @@
|
||||
using GameCore.TinyECS;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace GameCore.Test
|
||||
namespace ECSTest
|
||||
{
|
||||
using Entity = Entity<EntityType>;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace GameCore.Test
|
||||
namespace ECSTest
|
||||
{
|
||||
public enum EntityType
|
||||
{
|
||||
|
||||
+12
-10
@@ -1,19 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameCore.Test;
|
||||
using UnityEngine;
|
||||
|
||||
public class Main : MonoBehaviour
|
||||
namespace ECSTest
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public class Main : MonoBehaviour
|
||||
{
|
||||
TestEntityDataBlock.Run();
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
TestEntityDataBlock.Run();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using Unity.Networking.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using Unity.Networking.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ECSTest
|
||||
{
|
||||
[BurstCompile]
|
||||
public struct ServerConnectionJob : IJob
|
||||
{
|
||||
public NetworkDriver driver;
|
||||
public NativeList<NetworkConnection> connectionList;
|
||||
public NativeList<int> disconnectIndexList;
|
||||
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
// disconnect
|
||||
@@ -21,6 +22,7 @@
|
||||
var index = disconnectIndexList[i];
|
||||
connectionList.RemoveAtSwapBack(index);
|
||||
}
|
||||
|
||||
disconnectIndexList.Clear();
|
||||
|
||||
// connect
|
||||
@@ -28,7 +30,12 @@
|
||||
while ((c = driver.Accept()) != default)
|
||||
{
|
||||
connectionList.Add(c);
|
||||
Debug.Log("Accepted a connection");
|
||||
Debug.Log("[Server] Accepted a connection");
|
||||
}
|
||||
|
||||
if (connectionList.Length > disconnectIndexList.Capacity)
|
||||
disconnectIndexList.SetCapacity(connectionList.Length);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,52 +7,59 @@ using Unity.Jobs;
|
||||
using Unity.Networking.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
public class ServerMain : MonoBehaviour
|
||||
namespace ECSTest
|
||||
{
|
||||
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()
|
||||
public class ServerMain : MonoBehaviour
|
||||
{
|
||||
driver = driverAsset.CreateServerDriver(address);
|
||||
|
||||
connectionList = new NativeList<NetworkConnection>(16,Allocator.Persistent);
|
||||
disconnectIndexList = new NativeList<int>(16, Allocator.Persistent);
|
||||
}
|
||||
public string address = "127.0.0.1";
|
||||
public NetworkDriverAsset driverAsset;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
networkJobHandle.Complete();
|
||||
private NetworkDriver driver;
|
||||
private NetworkPipeline unreliablePipeline;
|
||||
private NetworkPipeline reliablePipeline;
|
||||
private JobHandle networkJobHandle;
|
||||
private NativeList<NetworkConnection> connectionList;
|
||||
private NativeList<int> disconnectIndexList;
|
||||
|
||||
driver.Dispose();
|
||||
|
||||
connectionList.Dispose();
|
||||
disconnectIndexList.Dispose();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
networkJobHandle.Complete();
|
||||
|
||||
var concurrentDriver = driver.ToConcurrent();
|
||||
|
||||
networkJobHandle = driver.ScheduleUpdate();
|
||||
networkJobHandle = new ServerConnectionJob()
|
||||
private void OnEnable()
|
||||
{
|
||||
driver = driver,
|
||||
connectionList = connectionList,
|
||||
disconnectIndexList = disconnectIndexList,
|
||||
}.Schedule(networkJobHandle);
|
||||
|
||||
networkJobHandle = new ServerReceiveJob()
|
||||
{
|
||||
driver = concurrentDriver,
|
||||
}.Schedule(connectionList, 16, networkJobHandle);
|
||||
driver = driverAsset.CreateServerDriver(address, out unreliablePipeline, out reliablePipeline);
|
||||
|
||||
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,
|
||||
connectionList = connectionList,
|
||||
disconnectIndexList = disconnectIndexList.AsParallelWriter(),
|
||||
}.Schedule(connectionList, 16, networkJobHandle);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,37 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using Unity.Networking.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
using Unity.Burst;
|
||||
using Unity.Jobs;
|
||||
using Unity.Networking.Transport;
|
||||
|
||||
namespace ECSTest
|
||||
{
|
||||
[BurstCompile]
|
||||
public struct ServerReceiveJob : IJobParallelForDefer
|
||||
{
|
||||
public NetworkDriver.Concurrent driver;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeList<NetworkConnection> connectionList;
|
||||
public NativeList<int>.ParallelWriter disconnectIndexList;
|
||||
|
||||
public void Execute(int index)
|
||||
{
|
||||
|
||||
var connection = connectionList[index];
|
||||
|
||||
NetworkEvent.Type cmd;
|
||||
while ((cmd = driver.PopEventForConnection(connection, out var stream)) !=
|
||||
NetworkEvent.Type.Empty)
|
||||
{
|
||||
if (cmd == NetworkEvent.Type.Data)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
else if (cmd == NetworkEvent.Type.Disconnect)
|
||||
{
|
||||
disconnectIndexList.AddNoResize(index);
|
||||
Debug.Log("[Server] Received a disconnection");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Jobs;
|
||||
|
||||
using Unity.Burst;
|
||||
using Unity.Jobs;
|
||||
|
||||
namespace ECSTest
|
||||
{
|
||||
[BurstCompile]
|
||||
public struct ServerSendJob : IJobParallelFor
|
||||
{
|
||||
public void Execute(int index)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using GameCore.TinyECS;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameCore.Test
|
||||
namespace ECSTest
|
||||
{
|
||||
public static class TestEntityDataBlock
|
||||
{
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameCore.Test
|
||||
{
|
||||
[BurstCompile]
|
||||
public struct TestJob : IJobParallelFor
|
||||
{
|
||||
public void Execute(int index)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68aafcef1265449e6b6b2dd81d7173a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user