Beispiel #1
0
 public void Play(string animationName = null)
 {
     if (string.IsNullOrEmpty(animationName))
     {
         animationName = animations[currentAnimationIndex].name;
     }
     for (int i = 0; i < animations.Length; i++)
     {
         var animation = animations[i];
         if (animation.AnimationName == animationName)
         {
             SpriteSheetManager.SetAnimation(managedEntity, animation);
             currentAnimationIndex = i;
             return;
         }
     }
 }
Beispiel #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;
                }
            }
        }
        // we should only update the index of the changed datas for
        // indexBuffer, matrixBuffer, and colorBuffer inside a bursted
        // job to avoid overhead
        private int UpdateBuffers(int renderIndex)
        {
            SpriteSheetManager.ReleaseBuffer(renderIndex);

            RenderInformation renderInformation = SpriteSheetManager.renderInformation[renderIndex];
            int instanceCount = EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Length;

            if (instanceCount > 0)
            {
                if (renderInformation.updateUvs)
                {
                    int stride = instanceCount >= 16 ? 16 : 16 * SpriteSheetCache.GetLength(renderInformation.material);
                    SpriteSheetManager.ReleaseUvBuffer(renderIndex);
                    renderInformation.uvBuffer = new ComputeBuffer(instanceCount, stride);
                    renderInformation.uvBuffer.SetData(EntityManager.GetBuffer <UvBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
                    renderInformation.material.SetBuffer("uvBuffer", renderInformation.uvBuffer);
                    renderInformation.updateUvs = false;
                }

                renderInformation.indexBuffer = new ComputeBuffer(instanceCount, sizeof(int));
                renderInformation.indexBuffer.SetData(EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
                renderInformation.material.SetBuffer("indexBuffer", renderInformation.indexBuffer);

                renderInformation.matrixBuffer = new ComputeBuffer(instanceCount, 16);
                renderInformation.matrixBuffer.SetData(EntityManager.GetBuffer <MatrixBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
                renderInformation.material.SetBuffer("matrixBuffer", renderInformation.matrixBuffer);

                renderInformation.args[1] = (uint)instanceCount;
                renderInformation.argsBuffer.SetData(renderInformation.args);

                renderInformation.colorsBuffer = new ComputeBuffer(instanceCount, 16);
                renderInformation.colorsBuffer.SetData(EntityManager.GetBuffer <SpriteColorBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
                renderInformation.material.SetBuffer("colorsBuffer", renderInformation.colorsBuffer);
            }
            return(instanceCount);
        }
 protected override void OnDestroy()
 {
     SpriteSheetManager.CleanBuffers();
 }