using Unity.Entities; using Unity.Transforms; using UnityEngine; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace Rukhanka { [WorldSystemFilter(WorldSystemFilterFlags.Editor | WorldSystemFilterFlags.Default)] [UpdateInGroup(typeof(RukhankaDeformationSystemGroup))] [UpdateAfter(typeof(MeshDeformationSystem))] partial class GPUAttachmentsUpdateSystem: SystemBase { GraphicsBuffer dummyGB; EntityQuery gpuAttachmentsQuery; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override void OnCreate() { gpuAttachmentsQuery = SystemAPI.QueryBuilder() .WithAll() .Build(); RequireForUpdate(gpuAttachmentsQuery); // Make small dummy bone transform buffer to prevent "attempted to draw with missing bindings" warnings and missed meshes for GPU attachments in edit mode dummyGB = new (GraphicsBuffer.Target.Structured, GraphicsBuffer.UsageFlags.None, 1, 4); Shader.SetGlobalBuffer(GPUAnimationSystem.ShaderID_rigSpaceBoneTransformsBuf, dummyGB); Shader.SetGlobalBuffer(GPUAnimationSystem.ShaderID_boneLocalTransforms, dummyGB); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override void OnDestroy() { dummyGB.Dispose(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override void OnUpdate() { var attachmentBoneIndexUpdateJob = new UpdateGPUAttachmentBoneIndexJob() { frameOffsetsLookup = SystemAPI.GetComponentLookup(true), localTransformLookup = SystemAPI.GetComponentLookup(true), parentLookup = SystemAPI.GetComponentLookup(true), postTransformMatrixLookup = SystemAPI.GetComponentLookup(true), rigBoneRefLookup = SystemAPI.GetComponentLookup(true), gpuAttachmentTypeHandle = SystemAPI.GetComponentTypeHandle(true), gpuAttachmentBoneIndexTypeHandle = SystemAPI.GetComponentTypeHandle(), gpuAttachmentToBoneTransformTypeHandle = SystemAPI.GetComponentTypeHandle(), gpuRigEntityLocalToWorldTypeHandle = SystemAPI.GetComponentTypeHandle(), gpuRigFrameOffsetsTypeHandle = SystemAPI.GetComponentTypeHandle(true), gpuEngineTagLookup = SystemAPI.GetComponentLookup(true), entityTypeHandle = SystemAPI.GetEntityTypeHandle() }; var attachmentBoneIndexUpdateJH = attachmentBoneIndexUpdateJob.ScheduleParallel(gpuAttachmentsQuery, Dependency); Dependency = attachmentBoneIndexUpdateJH; Dependency.Complete(); } } }