Megacity demo game for UOS
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

61 行
2.1 KiB

using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.MegaCity.UI;
using Unity.NetCode;
using static Unity.Entities.SystemAPI;
namespace Unity.MegaCity.Gameplay
{
public struct SetPlayerInfoRequest : IRpcCommand
{
public FixedString64Bytes Name;
public FixedString64Bytes PlayerId;
public bool IsClient;
}
public struct NameAssigned : IComponentData{}
/// <summary>
/// Send Client information when the Connection is setup
/// </summary>
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct SendPlayerInfoSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkStreamInGame>();
}
public void OnUpdate(ref SystemState state)
{
if (PlayerInfoController.Instance == null)
return;
var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
foreach (var (streaming, entity) in Query<RefRO<NetworkStreamInGame>>().WithNone<NameAssigned>().WithEntityAccess())
{
var requestEntity = commandBuffer.CreateEntity();
var requestData = new SetPlayerInfoRequest
{
Name = PlayerInfoController.Instance.Name,
// This returns [True] if the requester is not a Thin Client
IsClient = !state.World.IsThinClient(),
};
if (requestData.IsClient)
{
requestData.PlayerId = MultiverseRoomAPI.Instance.PlayerID;
// requestData.PlayerId = PlayerAuthentication.PlayerId;
}
commandBuffer.AddComponent<SendRpcCommandRequest>(requestEntity);
commandBuffer.AddComponent(requestEntity, requestData);
commandBuffer.AddComponent(entity, new NameAssigned());
}
commandBuffer.Playback(state.EntityManager);
}
}
}