Unity 6.3
0 онлайн 83 гостей 3 в системе
Вход

AnimatorTransitionInfo

структура в UnityEngine

Выполнено в:UnityEngine.AnimationModule

Описание

Сведения о текущем переходе на конкретном слое машины состояний.

Использование Animator.GetAnimatorTransitionInfo для доступа к сведениям о переходе в режиме воспроизведения. Используйте эти сведения, например, чтобы проверить текущий переход и измерить его прогресс. Для измерения прогресса перехода можно использовать вес целевого состояния.

Эта структура не связана с AnimatorTransition который доступен только в редакторе и используется для создания переходов машины состояний из кода.

Дополнительные ресурсы: AnimatorStateInfo Animator.GetAnimatorTransitionInfo AnimatorControllerPlayable.GetAnimatorTransitionInfo.

using UnityEngine;

// MonoBehaviour that sets the IK position and weight of the right hand when the character transitions to a "Grab" animation
// state.
[RequireComponent(typeof(Animator))]
public class GrabBehaviour : MonoBehaviour
{
    private Animator m_Animator;

    public Transform grabTarget;

    void Start()
    {
        m_Animator = GetComponent<Animator>();
    }

    void OnAnimatorIK(int layerIndex)
    {
        float ikWeight;

        var transitionInfo = m_Animator.GetAnimatorTransitionInfo(0);
        if (transitionInfo.IsName("Locomotion -> Grab"))
        {
            // When the character transitions from "Locomotion" to "Grab" state, do not immediately 
            // set the IK weight from 0 to 1 to avoid the hand instantly snapping to the target.
            // The IK weight changes at the same rate as the animation state. For example, when the
            // transition is halfway through, the IK weight is 0.5.
            ikWeight = transitionInfo.normalizedTime;
        }
        else
        {
            // The IK weight is 0 when the "Locomotion" state is active and 1 when the "Graph" state is active.
            ikWeight = m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Grab") ? 1f : 0f;
        }

        m_Animator.SetIKPositionWeight(AvatarIKGoal.RightHand, ikWeight);
        if (ikWeight > 0f)
        {
            m_Animator.SetIKPosition(AvatarIKGoal.RightHand, grabTarget.position);
        }
    }
}

Свойства

Свойство Описание
anyStateВозвращает true, если переход происходит из узла AnyState или из узла Animator.CrossFade.
durationПродолжительность переходного периода.
durationUnitЕдиница измерения продолжительности перехода.
fullPathHashХеш-имя перехода.
nameHashУпрощенное название Перехода.
normalizedTimeНормализованное время перехода.
userNameHashЗаданное пользователем имя перехода.

Открытые методы

Метод Описание
IsNameСоответствует ли имя имени активного перехода.
IsUserNameСоответствует ли userName имени активного Перехода.