Пример #1
0
    public void UpdateFrame()
    {
        if (CurrentSequence == null)
        {
            return;
        }
        Sprite sprite;

        if (CurrentSequence.UseFrames)
        {
            CurrentFrameIndex = Mathf.Clamp(CurrentFrameIndex, 0, CurrentSequence.frames.Length - 1);
            sprite            = CurrentSequence.frames[CurrentFrameIndex].sprite;
        }
        else
        {
            CurrentFrameIndex = Mathf.Clamp(CurrentFrameIndex, 0, CurrentSequence.sprites.Length - 1);
            sprite            = CurrentSequence.sprites[CurrentFrameIndex];
        }

        if (sr != null)
        {
            sr.sprite = sprite;
            sr.flipX  = flipX;

            if (Application.isPlaying)
            {
                sr.material.SetInt("_FlipX", flipX ? 1 : 0);
            }
            else
            {
                sr.sharedMaterial.SetInt("_FlipX", flipX ? 1 : 0);
            }
        }
        if (image != null)
        {
            image.enabled = sprite != null;
            image.sprite  = sprite;
        }

        if (CurrentSequence.UseFrames)
        {
            AnimFrame af = CurrentSequence.GetKeyFrame(CurrentFrameIndex);
            foreach (var afp in af.point)
            {
                Transform child = transform.Find(afp.name);
                if (child != null)
                {
                    if (flipX)
                    {
                        Vector3 lpos = afp.point;
                        lpos.x = -lpos.x;
                        child.localPosition = lpos;
                    }
                    else
                    {
                        child.localPosition = afp.point;
                    }
                }
            }
        }
    }