53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|