diff options
| author | chai <215380520@qq.com> | 2023-05-15 09:28:11 +0800 | 
|---|---|---|
| committer | chai <215380520@qq.com> | 2023-05-15 09:28:11 +0800 | 
| commit | 3b036c6de871aa519a1f7fbfb52e09618945041f (patch) | |
| tree | d5dc6d4f1d501e4ce3c6d69ca7a698a03634490c /WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs | |
| parent | 6fb204d494b897907d655b5752196983a82ceba2 (diff) | |
*misc
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs')
| -rw-r--r-- | WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs | 39 | 
1 files changed, 34 insertions, 5 deletions
| diff --git a/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs index 315cf91..63ba394 100644 --- a/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs +++ b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs @@ -13,20 +13,49 @@ namespace WK.Rendering          #endregion          #region 公共字段 - +        public bool playing +        { +            get +            { +                return m_IsPlaying; +            } +            set +            { +                m_IsPlaying = value; +            } +        }          #endregion          #region 私有字段 - +        private SpriteRenderer m_SpriteRenderer; +        private bool m_IsPlaying;          #endregion          private void Awake()          { -            // 私有字段赋值 +            m_SpriteRenderer = GetComponent<SpriteRenderer>(); -            // 公共字段赋值 +            StartCoroutine(CoPlayAnimation(m_SpriteAnimation.duration)); -            // 初始化 +            m_IsPlaying = true; +        } + +        IEnumerator CoPlayAnimation(float duration = 1f) +        { +            int index = 0; +            while (true) +            { +                if (!playing) +                { +                    yield return null; +                    continue; +                } + +                m_SpriteRenderer.sprite = m_SpriteAnimation.sprites[index]; +                yield return new WaitForSeconds(m_SpriteAnimation.duration / m_SpriteAnimation.sprites.Count); +                index++; +                index %= m_SpriteAnimation.sprites.Count;    +            }          }      } | 
