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.
50 lines
1.3 KiB
50 lines
1.3 KiB
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() |
|
} |
|
} |
|
} |