#if !RUKHANKA_NO_DEBUG_DRAWER using Rukhanka.DebugDrawer; #endif using Unity.Burst; using Unity.Entities; using Unity.Rendering; using UnityEngine; ///////////////////////////////////////////////////////////////////////////////// namespace Rukhanka { [DisableAutoCreation] [UpdateAfter(typeof(AnimationCullingContextUpdateSystem))] partial struct AnimationCullingSystem: ISystem { EntityQuery cullAnimationTagQuery; ///////////////////////////////////////////////////////////////////////////////// [BurstCompile] public void OnCreate(ref SystemState ss) { cullAnimationTagQuery = SystemAPI.QueryBuilder() .WithAll() .WithOptions(EntityQueryOptions.IgnoreComponentEnabledState) .Build(); ss.RequireForUpdate(cullAnimationTagQuery); } ///////////////////////////////////////////////////////////////////////////////// [BurstCompile] public void OnUpdate(ref SystemState ss) { if (!SystemAPI.TryGetSingleton(out var actx)) { if (!cullAnimationTagQuery.IsEmptyIgnoreFilter) { Debug.LogError($"Animation culling config is absent on scene, but some entities request animation culling functionality. Please properly configure the culling environment!"); } return; } var resetCullingStateJob = new ResetAnimationCullingJob() { cullAnimationsTypeHandle = SystemAPI.GetComponentTypeHandle() }; var resetCullingStateJH = resetCullingStateJob.ScheduleParallel(cullAnimationTagQuery, ss.Dependency); var wrbTypeHandle = SystemAPI.GetComponentTypeHandle(true); var chunkWrbTypeHandle = SystemAPI.GetComponentTypeHandle(true); var cullAnimationsTagLookup = SystemAPI.GetComponentLookup(); var skinnedMeshTypeHandle = SystemAPI.GetComponentTypeHandle(true); var cullAnimationsJob = new CullAnimationsJob() { actx = actx, wrbTypeHandle = wrbTypeHandle, chunkWrbTypeHandle = chunkWrbTypeHandle, cullAnimationsTagLookup = cullAnimationsTagLookup, asmTypeHandle = skinnedMeshTypeHandle }; var cullQuery = SystemAPI.QueryBuilder() .WithAllChunkComponent() .WithAll() .Build(); ss.Dependency = cullAnimationsJob.ScheduleParallel(cullQuery, resetCullingStateJH); #if (RUKHANKA_DEBUG_INFO && !RUKHANKA_NO_DEBUG_DRAWER) SystemAPI.TryGetSingletonRW(out var dd); var debugDrawJob = new DebugDrawRendererBoundingBoxes() { dd = dd.ValueRW, actx = actx, wrbTypeHandle = wrbTypeHandle, chunkWrbTypeHandle = chunkWrbTypeHandle, cullAnimationsTagLookup = cullAnimationsTagLookup, asmTypeHandle = skinnedMeshTypeHandle }; ss.Dependency = debugDrawJob.ScheduleParallel(cullQuery, ss.Dependency); #endif } } }