34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using RpcComponents;
|
|
using Unity.Burst;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.NetCode;
|
|
|
|
partial struct InitializeLocallySystem : ISystem
|
|
{
|
|
[BurstCompile]
|
|
public void OnCreate(ref SystemState state)
|
|
{
|
|
var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<GhostOwnerIsLocal>().WithNone<InitializedLocallyTag>();
|
|
state.RequireForUpdate(state.GetEntityQuery(builder));
|
|
}
|
|
|
|
[BurstCompile]
|
|
public void OnUpdate(ref SystemState state)
|
|
{
|
|
EntityCommandBuffer ecb = SystemAPI.GetSingletonRW<EndSimulationEntityCommandBufferSystem.Singleton>().ValueRW.CreateCommandBuffer(state.WorldUnmanaged);
|
|
|
|
foreach (var (character, entity) in SystemAPI.Query<FirstPersonCharacterComponent>().WithAll<GhostOwnerIsLocal>().WithNone<InitializedLocallyTag>().WithEntityAccess())
|
|
{
|
|
ecb.AddComponent(character.ViewEntity, new MainEntityCamera());
|
|
ecb.AddComponent(entity, new InitializedLocallyTag());
|
|
}
|
|
}
|
|
|
|
[BurstCompile]
|
|
public void OnDestroy(ref SystemState state)
|
|
{
|
|
|
|
}
|
|
}
|