Initial import
This commit is contained in:
52
Assets/Scripts/NetCode/GoInGameClientSystem.cs
Normal file
52
Assets/Scripts/NetCode/GoInGameClientSystem.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
|
||||
namespace EE2Clone.NetCode
|
||||
{
|
||||
/// <summary>
|
||||
/// RPC sent by the client to request going in-game.
|
||||
/// </summary>
|
||||
public struct GoInGameRequest : IRpcCommand
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client-side system: when a connection is established and the streaming is done,
|
||||
/// send a GoInGameRequest RPC to the server.
|
||||
/// </summary>
|
||||
[BurstCompile]
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
|
||||
public partial struct GoInGameClientSystem : ISystem
|
||||
{
|
||||
[BurstCompile]
|
||||
public void OnCreate(ref SystemState state)
|
||||
{
|
||||
state.RequireForUpdate<NetworkId>();
|
||||
}
|
||||
|
||||
[BurstCompile]
|
||||
public void OnUpdate(ref SystemState state)
|
||||
{
|
||||
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
||||
|
||||
foreach (var (networkId, entity) in
|
||||
SystemAPI.Query<RefRO<NetworkId>>()
|
||||
.WithNone<NetworkStreamInGame>()
|
||||
.WithEntityAccess())
|
||||
{
|
||||
ecb.AddComponent<NetworkStreamInGame>(entity);
|
||||
|
||||
var requestEntity = ecb.CreateEntity();
|
||||
ecb.AddComponent(requestEntity, new GoInGameRequest());
|
||||
ecb.AddComponent(requestEntity, new SendRpcCommandRequest { TargetConnection = entity });
|
||||
|
||||
UnityEngine.Debug.Log($"[Client] Sending GoInGame request (NetworkId={networkId.ValueRO.Value})");
|
||||
}
|
||||
|
||||
ecb.Playback(state.EntityManager);
|
||||
ecb.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user