// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using UnityEngine;
using UnityEngine.Animations;
namespace Animancer
{
/// An which uses an .
///
/// Documentation:
///
/// Layers
///
/// https://kybernetik.com.au/animancer/api/Animancer/AnimancerLayerMixerList
public class AnimancerLayerMixerList : AnimancerLayerList
{
/************************************************************************************************************************/
/// Creates a new .
public AnimancerLayerMixerList(AnimancerGraph graph)
: base(graph)
{
LayerMixer = AnimationLayerMixerPlayable.Create(graph._PlayableGraph, 1);
Playable = LayerMixer;
}
/************************************************************************************************************************/
/// The which blends the layers.
public AnimationLayerMixerPlayable LayerMixer { get; protected set; }
/************************************************************************************************************************/
///
public override bool IsAdditive(int index)
=> LayerMixer.IsLayerAdditive((uint)index);
///
public override void SetAdditive(int index, bool value)
{
SetMinCount(index + 1);
LayerMixer.SetLayerAdditive((uint)index, value);
}
/************************************************************************************************************************/
private static AvatarMask _DefaultMask;
///
public override void SetMask(int index, AvatarMask mask)
{
var layer = this[index];
if (mask == null)
{
// If the existing mask was already null, do nothing.
// If it was destroyed, we still need to continue and set it to the default.
if (layer._Mask is null)
return;
_DefaultMask ??= new();
mask = _DefaultMask;
}
// Don't check if the same mask was already assigned because it might have been modified.
layer._Mask = mask;
LayerMixer.SetLayerMaskFromAvatarMask((uint)index, mask);
}
/************************************************************************************************************************/
}
}