PlayMode
перечисление
Описание
Параметры, которые выбирают, какие анимации остановить при воспроизведении анимации.
Методы используют это перечисление, чтобы выбрать, какие анимации останавливать, — по слою или компоненту запущенной анимации. Например, Animation.Play метод использует StopSameLayer чтобы остановить анимацию на том же слое, что и начатая. Этот метод использует StopAll чтобы остановить анимацию, связанную с тем же Animation компонент в качестве начатой анимации. Дополнительные ресурсы: Animation.CrossFade, Animation.CrossFadeQueued, Animation.Play, Animation.PlayQueued.
// The following example demonstrates animation layers and how to use the PlayMode enum to animate a collectable coin. // The coin has four animation clips: // 1. Spin: A looping animation where the coin rotates on the y-axis. // 2. Slide: A looping animation where the coin moves back and forth. // 3. Bop: The coin moves upwards. // 4. Poof: The coin disappears with an effect. // The coin behaves as follows: // 1. The coin slides while spinning. // 2. If collected by the player, the coin moves upwards while spinning. // 3. If missed by the player, the coin stops spinning and disappears with an effect. using System.Collections; using UnityEngine; [RequireComponent(typeof(Animation))] public class PlayModeExample : MonoBehaviour { // Determines whether the coin was successfully collected. // True plays the coin collected animation. False plays the coin missed animation. public bool collectCoin; public float waitTime = 0.8f; // Length of the timer used for testing the coin collected and coin missed animations. Animation m_AnimComponent; void Start() { m_AnimComponent = GetComponent<Animation>(); // Slide and Bop need to be played in parallel to Spin, so they are set on different layers. // Spin is on the default layer which is 0. m_AnimComponent["Slide"].layer = 1; m_AnimComponent["Bop"].layer = 1; PlayCoinSlideAnimations(); // Ideally, PlayCoinCollectedAnimation() should be called when the player collides with the coin // and PlayCoinMissedAnimation() should be called at the end of the coin's lifetime, but // this would make the example too long. Instead, this coroutine provides a quick test while // Spin and Slide are playing. StartCoroutine(CollectOrHideCoinAfterDelay(waitTime)); } void PlayCoinSlideAnimations() { // Since no value for PlayMode is passed, PlayMode.StopSameLayer is used by default. m_AnimComponent.Play("Spin"); // Slide needs to be played concurrently to Spin, so PlayMode.StopSameLayer is used instead of PlayMode.StopAll. // StopAll would have stopped the Spin animation. m_AnimComponent.Play("Slide"); } IEnumerator CollectOrHideCoinAfterDelay(float time) { yield return new WaitForSeconds(time); if(collectCoin) PlayCoinCollectedAnimation(); else PlayCoinMissedAnimation(); } void PlayCoinCollectedAnimation() { // Since Bop is on the same layer as Slide, it stops Slide but not Spin since PlayMode.StopSameLayer is implicitly used here. m_AnimComponent.Play("Bop"); } void PlayCoinMissedAnimation() { // Since PlayMode.StopAll is used here, both Spin and Slide stop and only Poof plays. m_AnimComponent.Play("Poof", PlayMode.StopAll); } }
Свойства
| Свойство | Описание |
|---|---|
| StopSameLayer | Остановка анимации на том же слое, что и начатая анимация. Это поведение по умолчанию. |
| StopAll | Остановка анимации, воспроизводимой тем же компонентом, что и начатая анимация. |