//============================================================================================ /** * @brief * *********************************************************************************************/ public int SetLayer(int a_layerId, AnimationClip a_clip, float a_weight = 0f, bool a_additive = false, AvatarMask a_mask = null) { if (a_clip == null) { Debug.LogError("Attempting to set a layer with a null AnimationClip.... action aborted."); return(-1); } MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.SetLayerClip(a_clip); layer.Mask = a_mask; m_animationLayerMixer.SetInputWeight(a_layerId, a_weight); m_animationLayerMixer.SetLayerAdditive((uint)a_layerId, a_additive); return(a_layerId); } else { Debug.LogError("Could not set layer. Layer does not exist."); return(-1); } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public int SetLayer(int a_layerId, ref Playable a_playable, float a_weight = 0, bool a_additive = false, AvatarMask a_mask = null) { if (!a_playable.IsValid()) { Debug.LogError("Attempting to set a layer with an Invalid Playable.... action aborted."); return(-1); } MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.SetLayerPlayable(ref a_playable); m_animationLayerMixer.SetInputWeight(a_layerId, a_weight); m_animationLayerMixer.SetLayerAdditive((uint)a_layerId, a_additive); m_animationLayerMixer.SetLayerMaskFromAvatarMask((uint)a_layerId, a_mask); return(a_layerId); } else { Debug.LogWarning("Could not set layer. Layer does not exist."); return(-1); } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public int AddLayer(Playable a_playable, float a_weight = 0f, bool a_additive = false, AvatarMask a_mask = null) { int slotToUse = -1; if (!a_playable.IsNull()) { int inputCount = m_animationLayerMixer.GetInputCount(); for (int i = 2; i < inputCount; ++i) { Playable layerPlayable = m_animationLayerMixer.GetInput(i); if (layerPlayable.IsNull()) { slotToUse = i; break; } } if (slotToUse < 0) { m_animationLayerMixer.SetInputCount(inputCount + 1); slotToUse = inputCount; } MxMLayer layer = new MxMLayer(slotToUse, ref m_animationLayerMixer, a_playable, a_mask, a_weight, a_additive); m_layers.Add(slotToUse, layer); } return(slotToUse); }
//============================================================================================ /** * @brief Returns the requested layer if it exists. * * @param [int] a_layerId - the id of the layer turn return (must be 2 or greater) * * @return [MxMLayer] - a reference to the requested layer or null if it doesn't exist * *********************************************************************************************/ public MxMLayer GetLayer(int a_layerId) { MxMLayer layer = null; m_layers.TryGetValue(a_layerId, out layer); return(layer); }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void SetLayerClip(int a_layerId, AnimationClip a_clip) { if (a_layerId > 1) { MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.SetLayerClip(a_clip); layer.PrimaryClipTime = 0f; } } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void SetLayerClip(int a_layerId, AnimationClip a_clip, AvatarMask a_mask, float a_time = 0f, float a_weight = 1f) { if (a_layerId > 1) { MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.SetLayerClip(a_clip, a_time); layer.Mask = a_mask; layer.Weight = a_weight; } } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void BlendOutLayer(int a_layerId, float a_fadeRate, float a_targetWeight = 0f) { MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { if (layer.FadeCoroutine != null) { StopCoroutine(layer.FadeCoroutine); } layer.FadeCoroutine = StartCoroutine(FadeOutLayer(a_layerId, a_fadeRate, Mathf.Clamp01(a_targetWeight))); } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void TransitionLayerPlayable(int a_layerId, ref Playable a_playable, float a_fadeRate, float a_time = 0f) { MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.TransitionToPlayable(ref a_playable, a_fadeRate, a_time); if (!m_transitioningLayers.Contains(layer)) { m_transitioningLayers.Add(layer); } } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void TransitionLayerClip(int a_layerId, AnimationClip a_clip, float a_fadeRate, float a_time = 0f) { MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.TransitionToClip(a_clip, a_fadeRate, a_time); if (!m_transitioningLayers.Contains(layer)) { m_transitioningLayers.Add(layer); } } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void SetLayerMask(int a_layerId, AvatarMask a_mask) { if (a_layerId > 1) { MxMLayer layer = null; if (m_animationLayerMixer.IsValid() && m_layers.TryGetValue(a_layerId, out layer)) { m_layers[a_layerId].Mask = a_mask; } else { Debug.LogError("Trying to set a layer mask before the playable graph is created. Aborting Operation"); } } }
//============================================================================================ /** * @brief Sets the animation mask to use for the animator controller layer if you are using * one. This enables control of masked layer animations directly through the Animator Controller * * @param [AvatarMask] a_mask - the avatar mask to use * *********************************************************************************************/ public void SetControllerMask(AvatarMask a_mask) { if (a_mask == null) { Debug.LogWarning("Cannot set animator controller mask on MxMAnimator with a null mask"); return; } MxMLayer layer = null; if (m_layers.TryGetValue(1, out layer)) { layer.Mask = a_mask; } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void SetLayerAdditive(int a_layerId, bool a_additive) { if (a_layerId == 0) { return; } MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.Additive = a_additive; } else { Debug.LogWarning("Trying to set layer additive on an MxMLayer but the layer doesn't exist"); } }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void SetLayerWeight(int a_layerId, float a_weight) { if (a_layerId == 0) { return; } MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { layer.Weight = a_weight; } else { Debug.LogWarning("Trying to set the layer weight on an MxMLayer but the layer doesn't exist"); } }
//============================================================================================ /** * @brief Removes an MxM layer from the playable graph * *********************************************************************************************/ public bool RemoveLayer(int a_layerId, bool a_destroyPlayable = true) { MxMLayer layer = null; if (m_layers.TryGetValue(a_layerId, out layer)) { m_animationLayerMixer.SetInputWeight(a_layerId, 0f); layer.ClearLayer(); m_layers.Remove(a_layerId); return(true); } else { Debug.LogWarning("Could not remove MxM Layer. The player doesn't exist"); return(false); } }
public void Initialize() { m_eventLayers = new List <EventLayerData>(4); m_mxmAnimator = GetComponent <MxMAnimator>(); if (m_mxmAnimator == null) { Debug.LogError("Could not find MxMAnimator component, MxMEventLayers component disabled"); enabled = false; return; } m_layerMixer = AnimationLayerMixerPlayable.Create(m_mxmAnimator.MxMPlayableGraph, 1); m_layerId = m_mxmAnimator.AddLayer((Playable)m_layerMixer, 0f, false, null); m_baseLayer = m_mxmAnimator.GetLayer(m_layerId); m_mxmAnimator.SetLayerWeight(m_layerId, 1f); }