public static void DestroyEntity(EntityCommandBuffer commandBuffer, Entity e, BufferHook hook)
        {
            commandBuffer.DestroyEntity(e);
            Material material = DynamicBufferManager.GetMaterial(hook.bufferEntityID);

            DynamicBufferManager.RemoveBuffer(material, hook.bufferID);
        }
        public static void SetAnimation(Entity e, SpriteSheetAnimationClip animation)
        {
            int      bufferEntityID = EntityManager.GetComponentData <BufferHook>(e).bufferEntityID;
            int      bufferID       = EntityManager.GetComponentData <BufferHook>(e).bufferID;
            Material oldMaterial    = DynamicBufferManager.GetMaterial(bufferEntityID);
            string   oldAnimation   = SpriteSheetCache.GetMaterialName(oldMaterial);

            if (animation.AnimationName != oldAnimation)
            {
                Material material            = SpriteSheetCache.GetMaterial(animation.AnimationName);
                var      spriteSheetMaterial = new SpriteSheetMaterial {
                    material = material
                };

                DynamicBufferManager.RemoveBuffer(oldMaterial, bufferID);

                //use new buffer
                bufferID = DynamicBufferManager.AddDynamicBuffers(DynamicBufferManager.GetEntityBuffer(material), material);
                BufferHook bh = new BufferHook {
                    bufferID = bufferID, bufferEntityID = DynamicBufferManager.GetEntityBufferID(spriteSheetMaterial)
                };

                EntityManager.SetSharedComponentData(e, spriteSheetMaterial);
                EntityManager.SetComponentData(e, bh);
            }
            EntityManager.SetComponentData(e, new SpriteSheetAnimation {
                frameCount = animation.Sprites.Length, framesPerSecond = animation.FramesPerSecond, playMode = animation.PlayMode, elapsedTime = 0
            });
            EntityManager.SetComponentData(e, new SpriteIndex {
                Value = 0
            });
        }
        public static void SetAnimation(EntityCommandBuffer commandBuffer, Entity e, SpriteSheetAnimationClip animation, BufferHook hook)
        {
            Material oldMaterial  = DynamicBufferManager.GetMaterial(hook.bufferEntityID);
            string   oldAnimation = SpriteSheetCache.GetMaterialName(oldMaterial);

            if (animation.AnimationName != oldAnimation)
            {
                Material material            = SpriteSheetCache.GetMaterial(animation.AnimationName);
                var      spriteSheetMaterial = new SpriteSheetMaterial {
                    material = material
                };

                //clean old buffer
                DynamicBufferManager.RemoveBuffer(oldMaterial, hook.bufferID);

                //use new buffer
                int        bufferID = DynamicBufferManager.AddDynamicBuffers(DynamicBufferManager.GetEntityBuffer(material), material);
                BufferHook bh       = new BufferHook {
                    bufferID = bufferID, bufferEntityID = DynamicBufferManager.GetEntityBufferID(spriteSheetMaterial)
                };

                commandBuffer.SetSharedComponent(e, spriteSheetMaterial);
                commandBuffer.SetComponent(e, bh);
            }
            commandBuffer.SetComponent(e, new SpriteSheetAnimation {
                frameCount = animation.FrameCount, framesPerSecond = animation.FramesPerSecond, playMode = animation.PlayMode, elapsedTime = 0
            });
            commandBuffer.SetComponent(e, new SpriteIndex {
                Value = 0
            });
        }