Progress character customization

This commit is contained in:
Lauchstange committed 2025-01-30 21:02:41 +01:00
1 parent bf545f3baf
commit 5708c0bbbd
20 files changed
+327 -191

No files matched your search

@@ -1,5 +1,6 @@
using Common;
using RpcComponents;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
@@ -15,14 +16,15 @@ namespace Server
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<TdPrefabs>();
var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<TdTeamRequest, ReceiveRpcCommandRequest>();
state.RequireForUpdate(state.GetEntityQuery(builder));
state.RequireForUpdate<TdPrefabs>();
}
public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(Allocator.Temp);
var ecb = new EntityCommandBuffer(Allocator.Temp);
var characterPrefab = SystemAPI.GetSingleton<TdPrefabs>().Character;
foreach (var (teamRequest, requestSource, requestEntity) in SystemAPI.Query<TdTeamRequest, ReceiveRpcCommandRequest>().WithEntityAccess())
@@ -35,20 +37,37 @@ namespace Server
var requestedTeam = teamRequest.Value;
var requestedColor = teamRequest.Color;
var clientId = SystemAPI.GetComponent<NetworkId>(requestSource.SourceConnection).Value;
Debug.Log($"Server is assigning ClientId {clientId} to team {requestedTeam}");
float3 spawnPosition = float3.zero;
var newCharacter = ecb.Instantiate(characterPrefab);
var spawnPosition = new float3(0f, 1f, 0f);
var newTransform = LocalTransform.FromPosition(spawnPosition);
var clientId = SystemAPI.GetComponent<NetworkId>(requestSource.SourceConnection).Value;
switch (clientId)
{
case 1:
spawnPosition = new float3(0f, 1f, 0f);
break;
case 2:
spawnPosition = new float3(2f, 1f, 0f);
break;
}
ecb.SetComponent(newCharacter, newTransform);
Debug.Log($"Server is assigning ClientId {clientId} to team {requestedTeam}");
var newCharacter = ecb.Instantiate(characterPrefab);
ecb.SetName(newCharacter, "Character");
var newTransform = LocalTransform.FromPosition(spawnPosition);
ecb.SetComponent(newCharacter, newTransform);
ecb.SetComponent(newCharacter, new TdTeam { Value = requestedTeam });
ecb.AddComponent(newCharacter, new GhostOwner { NetworkId = clientId});
ecb.SetComponent(newCharacter, new GhostOwner { NetworkId = clientId});
ecb.SetComponent(newCharacter, new TdTeam { Value = requestedTeam });
ecb.SetComponent(newCharacter, new CharacterConfig
{
Color = requestedColor
});
//Destroy character prefab, when client disconnects
ecb.AppendToBuffer(requestSource.SourceConnection, new LinkedEntityGroup{Value = newCharacter});
}