Skip to content

Instantly share code, notes, and snippets.

@Misterturtle
Created September 19, 2023 00:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using Unity.Physics.Systems;
using UnityEngine;
[GhostComponent(PrefabType=GhostPrefabType.AllPredicted, OwnerSendType = SendToOwnerType.SendToNonOwner)]
public struct DebugInput : IInputComponentData
{
[GhostField] public InputEvent DebugEvent;
}
public struct DebugTag : IComponentData
{
}
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation, WorldSystemFilterFlags.ClientSimulation)]
[UpdateInGroup(typeof(GhostInputSystemGroup))]
public partial struct DebugSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var commandBuffer = new EntityCommandBuffer(Allocator.TempJob);
state.Dependency.Complete();
new DebugJob
{
ECB = commandBuffer
}.Run();
state.Dependency.Complete();
commandBuffer.Playback(state.EntityManager);
}
}
[UpdateInGroup(typeof(PhysicsSystemGroup))]
[UpdateBefore(typeof(PhysicsInitializeGroup))]
[BurstCompile]
public partial struct ServerDebugSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var commandBuffer = new EntityCommandBuffer(Allocator.TempJob);
new HandleDebugJob
{
}.Schedule();
state.Dependency.Complete();
commandBuffer.Playback(state.EntityManager);
}
}
[BurstCompile]
public partial struct DebugJob : IJobEntity
{
public EntityCommandBuffer ECB;
[BurstCompile]
private void Execute(Entity entity, DebugTag debugTag, ref DebugInput debugInput)
{
Debug.Log($"Running Debug Job");
debugInput.DebugEvent.Set();
ECB.RemoveComponent<DebugTag>(entity);
}
}
[BurstCompile]
public partial struct HandleDebugJob : IJobEntity
{
[BurstCompile]
private void Execute(Entity entity, ref DebugInput debugInput)
{
Debug.Log($"Running HandleDebugJob Job");
if (debugInput.DebugEvent.IsSet)
{
Debug.Log($"Debug Event is set. Count: {debugInput.DebugEvent.Count}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment