Параметры
layerIndex | Индекс слоя. |
mask | AvatarMask используется для создания новой LayerMask. |
Описание
Устанавливает маску для текущего слоя.
Эта функция создает маску слоя из указанного AvatarMask и применяет ее к указанному индексу слоя. Если вы измените AvatarMask, вам нужно снова вызвать эту функцию, чтобы обновить маску слоя.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;
public class LayerMixerPlayable : MonoBehaviour
{
public AnimationClip clip1;
public AnimationClip clip2;
public Transform leftShoulder;
PlayableGraph m_Graph;
AnimationLayerMixerPlayable m_Mixer;
public float mixLevel = 0.5f;
AvatarMask mask;
public void Start()
{
Animator animator = GetComponent<Animator>();
mask = new AvatarMask();
mask.AddTransformPath(leftShoulder, true);
m_Graph = PlayableGraph.Create();
var playableOutput = AnimationPlayableOutput.Create(m_Graph, "LayerMixer", animator);
playableOutput.SetSourcePlayable(m_Mixer);
// Create two clip playables
var clipPlayable1 = AnimationClipPlayable.Create(m_Graph, clip1);
var clipPlayable2 = AnimationClipPlayable.Create(m_Graph, clip2);
// Create mixer playable
m_Mixer = AnimationLayerMixerPlayable.Create(m_Graph, 2);
// Create two layers, second is setup to override the first layer and affect only left shoulder and childs
m_Mixer.ConnectInput(0, clipPlayable1, 0, 1.0f);
m_Mixer.ConnectInput(1, clipPlayable2, 0, mixLevel);
m_Mixer.SetLayerMaskFromAvatarMask(1, mask);
m_Graph.Play();
}
public void Update()
{
m_Mixer.SetInputWeight(1, mixLevel);
}
public void OnDestroy()
{
m_Graph.Destroy();
}
}