layerIndex | 层索引。 |
mask | 用于创建新 LayerMask 的 AvatarMask。 |
设置当前层的遮罩。
此函数从指定 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(); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.