public static void SetAnimation(EntityCommandBuffer commandBuffer, Entity e, SpriteSheetAnimationData animation, BufferHook hook) { Material oldMaterial = DynamicBufferManager.GetMaterial(hook.bufferEnityID); 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, bufferEnityID = DynamicBufferManager.GetEntityBufferID(spriteSheetMaterial) }; commandBuffer.SetSharedComponent(e, spriteSheetMaterial); commandBuffer.SetComponent(e, bh); } commandBuffer.SetComponent(e, new SpriteSheetAnimation { maxSprites = animation.sprites.Length, play = animation.playOnStart, samples = animation.samples, repetition = animation.repetition, elapsedFrames = 0 }); commandBuffer.SetComponent(e, new SpriteIndex { Value = animation.startIndex }); }
public static void SetAnimation(Entity e, SpriteSheetAnimationData animation) { int bufferEnityID = EntityManager.GetComponentData <BufferHook>(e).bufferEnityID; int bufferID = EntityManager.GetComponentData <BufferHook>(e).bufferID; Material oldMaterial = DynamicBufferManager.GetMaterial(bufferEnityID); 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, bufferEnityID = DynamicBufferManager.GetEntityBufferID(spriteSheetMaterial) }; EntityManager.SetSharedComponentData(e, spriteSheetMaterial); EntityManager.SetComponentData(e, bh); } EntityManager.SetComponentData(e, new SpriteSheetAnimation { maxSprites = animation.sprites.Length, play = animation.playOnStart, samples = animation.samples, repetition = animation.repetition, elapsedFrames = 0 }); EntityManager.SetComponentData(e, new SpriteIndex { Value = animation.startIndex }); MarkDirty <SpriteSheetColor>(e); MarkDirty <SpriteIndex>(e); MarkDirty <SpriteMatrix>(e); }