public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem)
        {
            instance  = this;
            archetype = eManager.CreateArchetype(
                typeof(Position2D),
                typeof(Rotation2D),
                typeof(Scale),
                //required params
                typeof(SpriteIndex),
                typeof(SpriteSheetAnimation),
                typeof(SpriteSheetMaterial),
                typeof(SpriteSheetColor),
                typeof(SpriteMatrix),
                typeof(BufferHook)
                );

            NativeArray <Entity> entities = new NativeArray <Entity>(spriteCount, Allocator.Temp);

            eManager.CreateEntity(archetype, entities);

            //only needed for first tiem material baking
            KeyValuePair <Material, float4[]> atlasData = SpriteSheetCache.BakeSprites(sprites, "emoji");
            SpriteSheetMaterial material = new SpriteSheetMaterial {
                material = atlasData.Key
            };

            DynamicBufferManager.manager = eManager;
            DynamicBufferManager.GenerateBuffers(material, entities.Length);
            DynamicBufferManager.BakeUvBuffer(material, atlasData);

            Rect   area      = GetSpawnArea();
            Random rand      = new Random((uint)UnityEngine.Random.Range(0, int.MaxValue));
            int    cellCount = atlasData.Value.Length;

            for (int i = 0; i < entities.Length; i++)
            {
                Entity e = entities[i];
                eManager.SetComponentData(e, new SpriteIndex {
                    Value = rand.NextInt(0, cellCount)
                });
                eManager.SetComponentData(e, new Scale {
                    Value = 10
                });
                eManager.SetComponentData(e, new Position2D {
                    Value = rand.NextFloat2(area.min, area.max)
                });
                eManager.SetComponentData(e, new SpriteSheetAnimation {
                    maxSprites = cellCount, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10
                });
                var color            = UnityEngine.Random.ColorHSV(.15f, .75f);
                SpriteSheetColor col = new SpriteSheetColor {
                    color = new float4(color.r, color.g, color.b, color.a)
                };
                eManager.SetComponentData(e, col);
                eManager.SetComponentData(e, new BufferHook {
                    bufferID = i, bufferEnityID = DynamicBufferManager.GetEntityBufferID(material)
                });
                eManager.SetSharedComponentData(e, material);
            }
        }
    public static void RecordSpriteSheet(Sprite[] sprites, string spriteSheetName, int spriteCount = 0)
    {
        KeyValuePair <Material, float4[]> atlasData = SpriteSheetCache.BakeSprites(sprites, spriteSheetName);
        SpriteSheetMaterial material = new SpriteSheetMaterial {
            material = atlasData.Key
        };

        DynamicBufferManager.GenerateBuffers(material, spriteCount);
        DynamicBufferManager.BakeUvBuffer(material, atlasData);
        renderInformation.Add(new RenderInformation(material.material, DynamicBufferManager.GetEntityBuffer(material.material)));
    }
 public static void RecordAnimator(SpriteSheetAnimator animator)
 {
     foreach (SpriteSheetAnimationData animation in animator.animations)
     {
         KeyValuePair <Material, float4[]> atlasData = SpriteSheetCache.BakeSprites(animation.sprites, animation.animationName);
         SpriteSheetMaterial material = new SpriteSheetMaterial {
             material = atlasData.Key
         };
         DynamicBufferManager.GenerateBuffers(material);
         DynamicBufferManager.BakeUvBuffer(material, atlasData);
         renderInformation.Add(new RenderInformation(material.material, DynamicBufferManager.GetEntityBuffer(material.material)));
     }
 }
        public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem)
        {
            var archetype = eManager.CreateArchetype(
                typeof(Position2D),
                typeof(Rotation2D),
                typeof(Scale),
                //typeof(Bound2D),
                typeof(SpriteSheet),
                typeof(SpriteSheetAnimation),
                typeof(SpriteSheetMaterial),
                typeof(UvBuffer),
                typeof(SpriteSheetColor),
                typeof(RenderData)
                );

            NativeArray <Entity> entities = new NativeArray <Entity>(spriteCount, Allocator.Temp);

            eManager.CreateEntity(archetype, entities);

            KeyValuePair <Material, float4[]> atlasData = SpriteSheetCache.BakeSprites(sprites);
            int cellCount = atlasData.Value.Length;

            Random rand = new Random((uint)UnityEngine.Random.Range(0, int.MaxValue));
            Rect   area = GetSpawnArea();
            SpriteSheetMaterial material = new SpriteSheetMaterial {
                material = atlasData.Key
            };

            for (int i = 0; i < entities.Length; i++)
            {
                Entity e = entities[i];

                SpriteSheet sheet = new SpriteSheet {
                    spriteIndex = rand.NextInt(0, cellCount), maxSprites = cellCount
                };
                Scale scale = new Scale {
                    Value = rand.NextFloat(minScale, maxScale)
                };
                Position2D pos = new Position2D {
                    Value = rand.NextFloat2(area.min, area.max)
                };
                SpriteSheetAnimation anim = new SpriteSheetAnimation {
                    play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10
                };
                var color            = UnityEngine.Random.ColorHSV(.15f, .75f);
                SpriteSheetColor col = new SpriteSheetColor {
                    value = new float4(color.r, color.g, color.b, color.a)
                };
                eManager.SetComponentData(e, sheet);
                eManager.SetComponentData(e, scale);
                eManager.SetComponentData(e, pos);
                eManager.SetComponentData(e, anim);
                eManager.SetComponentData(e, col);
                eManager.SetSharedComponentData(e, material);

                // Fill uv buffer
                var buffer = eManager.GetBuffer <UvBuffer>(entities[i]);
                for (int j = 0; j < atlasData.Value.Length; j++)
                {
                    buffer.Add(atlasData.Value[j]);
                }
            }
        }