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

Параметры

Параметр Описание
resetParameters Установите в true, чтобы также сбросить параметры контроллера к значениям по умолчанию. Если установить в false, будет сброшено только состояние контроллера.

Описание

Сброс параметра AnimatorController к значению по умолчанию.

Используйте этот метод для сброса слоев в AnimatorController к их состоянию по умолчанию.

using System;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

// Press the Spacebar in Play Mode to reset the AnimatorController to the default state
[RequireComponent(typeof(Animator))]
public class AnimatorControllerPlayableResetExample : MonoBehaviour
{
    // The AnimatorController to be used with the Animator component.
    public RuntimeAnimatorController m_Controller;

    Animator m_Animator;
    AnimatorControllerPlayable m_ControllerPlayable;

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

        // Set up the PlayableGraph and AnimatorControllerPlayable and play the graph.
        var graph = PlayableGraph.Create(nameof(AnimatorControllerPlayableResetExample));
        m_ControllerPlayable = AnimatorControllerPlayable.Create(graph, m_Controller);
        var output = AnimationPlayableOutput.Create(graph, nameof(AnimatorControllerPlayableResetExample), m_Animator);
        output.SetSourcePlayable(m_ControllerPlayable);
        graph.Play();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //This will reset the AnimatorController to the default state.
            m_ControllerPlayable.ResetControllerState();
        }
    }

    void OnDestroy()
    {
        // Destroy the PlayableGraph when the GameObject is destroyed.
        m_ControllerPlayable.GetGraph().Destroy();
    }
}