Esempio n. 1
0
        //============================================================================================
        /**
        *  @brief Constructor for the MxMLayer class which takes a playable instead of an animation clip. 
        *  Sets up all initial values and creates the layer's mixer.
        *  
        *  @param [int] a_id - the layer id (lowest layer value is 2 for MxMLayers)
        *  @param [int] a_maxClips - the maximum number of clips that can be blended on this layer
        *  @param [ref PlayableGraph] a_playableGraph - the playable graph that this layer lives on
        *  @param [Playable] a_playable - the playable to use for this layer
        *  @param [AvatarMask] a_mask - the mask to use with this player (Default null)
        *  @param [float] a_weight - the starting weight of this layer (Default 0)
        *  @param [bool] a_additive - whether the layer is additive or not (Default false)
        *         
        *********************************************************************************************/
        public MxMLayer(int a_id, int a_maxClips, ref AnimationLayerMixerPlayable a_layerMixer,
           Playable a_playable, AvatarMask a_mask = null, float a_weight = 0f, bool a_additive = false)
        {
            if(!a_playable.IsValid())
                Debug.LogError("Error: Attempting to create an MxMLayer with an invalid playable");

            if (!a_layerMixer.IsValid())
                Debug.LogError("Error: Attempting to create an MxMLayer with an invalid layerMixer.");

            m_layerMixer = a_layerMixer;
            m_playableGraph = m_layerMixer.GetGraph();
            

            Id = a_id;
            MaxClips = a_maxClips;

            PrimaryInputId = 0;

            Mixer = AnimationMixerPlayable.Create(m_playableGraph, a_maxClips, true);

            m_layerMixer.ConnectInput(Id, Mixer, 0);

            Mixer.ConnectInput(0, a_playable, 0);
            Mixer.SetInputWeight(0, 1f);

            Mask = a_mask;

            m_layerMixer.SetLayerAdditive((uint)Id, a_additive);
            m_layerMixer.SetInputWeight(Id, Mathf.Clamp01(a_weight));

            SubLayerWeights = new float[a_maxClips];
            SubLayerWeights[0] = 1f;
        }
Esempio n. 2
0
        //============================================================================================
        /**
        *  @brief Instantly sets the layer to a premade and passed playable with a weight of 1
        *         
        *********************************************************************************************/
        public void SetLayerPlayable(ref Playable a_playable)
        {
            if(!a_playable.IsValid())
            {
                Debug.LogWarning("Attempting to set an MxMLayer playable with an invalid playable... action aborded");
                return;
            }

            ClearLayerPlayables();
            PrimaryClip = null;

            Mixer.ConnectInput(0, a_playable, 0);
            Mixer.SetInputWeight(0, 1f);
        }
Esempio n. 3
0
        //============================================================================================
        /**
        *  @brief Triggers a transition of the layer from one playable to another over time
        *  
        *  @param [ref playable] a_playable - a reference to the playable to transition
        *  @param [float] a_fadeRate - the rate at which to blend the clip in
        *         
        *********************************************************************************************/
        public void TransitionToPlayable(ref Playable a_playable, float a_fadeRate, float a_time = 0f)
        {
            if(!a_playable.IsValid())
            {
                Debug.LogWarning("Trying to transition MxMLayer to a new playable, but the playable is invalid. Aborting operation.");
                return;
            }

            int slotToUse = FindAvailableSlot();

            Mixer.ConnectInput(slotToUse, a_playable, 0);
            Mixer.SetInputWeight(slotToUse, 0f);
            a_playable.SetTime(a_time);
            a_playable.SetTime(a_time);

            PrimaryInputId = slotToUse;
            TransitionRate = a_fadeRate;
        }
Esempio n. 4
0
        //============================================================================================
        /**
        *  @brief Instantly sets the layer clip  with a full weight of 1
        *  
        *  @param [AnimationClip] a_clip - the clip to set
        *         
        *********************************************************************************************/
        public void SetLayerClip(AnimationClip a_clip, float a_time = 0f)
        {
            if (a_clip == null)
            {
                Debug.LogWarning("Attempting to set an MxMLayer clip with a null clip... action aborted");
                return;
            }

            ClearLayerPlayables();
            PrimaryClip = a_clip;
 
            var clipPlayable = AnimationClipPlayable.Create(m_playableGraph, PrimaryClip);
            
            Mixer.ConnectInput(0, clipPlayable, 0);
            Mixer.SetInputWeight(0, 1f);
            clipPlayable.SetTime(a_time);
            clipPlayable.SetTime(a_time);
        }
Esempio n. 5
0
        //============================================================================================
        /**
        *  @brief Triggers a transition of the layer from one clip to another over time
        *  
        *  @param [AnimationClip] a_clip - the clip to blend in
        *  @param [float] a_fadeRate - the rate at which to blend the clip in
        *         
        *********************************************************************************************/
        public void TransitionToClip(AnimationClip a_clip, float a_fadeRate, float a_time = 0f)
        {
            if(a_clip == null)
            {
                Debug.LogWarning("Trying to transition MxMLayer to a new clip, but the clip is null. Aborting operation.");
                return;
            }

            int slotToUse = FindAvailableSlot();
            
            var clipPlayable = AnimationClipPlayable.Create(m_playableGraph, a_clip);
            Mixer.ConnectInput(slotToUse, clipPlayable, 0);
            Mixer.SetInputWeight(slotToUse, 0f);
            clipPlayable.SetTime(a_time);
            clipPlayable.SetTime(a_time);

            PrimaryInputId = slotToUse;
            TransitionRate = a_fadeRate;
        }