public static void RecordAnimator(SpriteSheetAnimator animator)
 {
     foreach (SpriteSheetAnimationClip 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)));
     }
 }
Exemple #2
0
        public static void Play(EntityCommandBuffer buffer, Entity e, BufferHook hook, string animationName = null)
        {
            SpriteSheetAnimator animator = SpriteSheetCache.GetAnimator(e);

            if (string.IsNullOrEmpty(animationName))
            {
                animationName = animator.animations[animator.currentAnimationIndex].name;
            }
            for (int i = 0; i < animator.animations.Length; i++)
            {
                var animation = animator.animations[i];
                if (animation.AnimationName == animationName)
                {
                    SpriteSheetManager.SetAnimation(buffer, e, animation, hook);
                    animator.currentAnimationIndex = i;
                    return;
                }
            }
        }
Exemple #3
0
 public static void AddAnimator(Entity entity, SpriteSheetAnimator animator)
 {
     entityAnimator.Add(entity, animator);
 }
        public static Entity Instantiate(EntityArchetype archetype, List <IComponentData> componentDatas, SpriteSheetAnimator animator)
        {
            Entity e = EntityManager.CreateEntity(archetype);
            SpriteSheetAnimationClip startAnim = animator.animations[animator.defaultAnimationClipIndex];
            int      maxSprites = startAnim.FrameCount;
            Material material   = SpriteSheetCache.GetMaterial(animator.animations[animator.defaultAnimationClipIndex].AnimationName);
            int      bufferID   = DynamicBufferManager.AddDynamicBuffers(DynamicBufferManager.GetEntityBuffer(material), material);

            foreach (IComponentData Idata in componentDatas)
            {
                EntityManager.SetComponentData(e, Idata);
            }

            var spriteSheetMaterial = new SpriteSheetMaterial {
                material = material
            };
            BufferHook bh = new BufferHook {
                bufferID = bufferID, bufferEntityID = DynamicBufferManager.GetEntityBufferID(spriteSheetMaterial)
            };

            EntityManager.SetComponentData(e, bh);
            EntityManager.SetComponentData(e, new SpriteSheetAnimation {
                frameCount = maxSprites, framesPerSecond = startAnim.FramesPerSecond, playMode = startAnim.PlayMode
            });
            EntityManager.SetComponentData(e, new SpriteIndex {
                Value = 0
            });
            EntityManager.SetSharedComponentData(e, spriteSheetMaterial);
            animator.managedEntity = e;
            SpriteSheetCache.AddAnimator(e, animator);
            return(e);
        }