Beispiel #1
0
        //============================================================================================
        /**
        *  @brief Returns the id of the first available slot in the mixer or alternatively the slots
        *  with the least weight. It also clears that slot if it is occupied
        *  
        *  @return - ID of the available slot or the lowest weight slot.
        *         
        *********************************************************************************************/
        private int FindAvailableSlot()
        {
            int slotToUse = -1;
            int lowestWeightSlot = 0;
            float lowestWeight = float.MaxValue;
            for(int i=0; i < MaxClips; ++i)
            {
                var playable = Mixer.GetInput(i);

                if(playable.IsValid())
                {
                    float weight = Mixer.GetInputWeight(i);
                    if(weight < lowestWeight)
                    {
                        lowestWeightSlot = i;
                        lowestWeight = weight;
                    }
                }
                else
                {
                    slotToUse = i;
                    return slotToUse;
                }
            }

            var playableToClear = Mixer.GetInput(lowestWeightSlot);
            Mixer.DisconnectInput(lowestWeightSlot);
            ClearPlayable(ref playableToClear);

            return lowestWeightSlot;
        }
Beispiel #2
0
        //============================================================================================
        /**
        *  @brief Updates the transition fading for the layer. This is only called when IsTransitioning
        *  is set to true.
        *         
        *********************************************************************************************/
        public bool UpdateTransition()
        {
            float cumulativeWeight = 0f;
            int clipCount = 0;
            for (int i = 0; i < SubLayerWeights.Length; ++i)
            {
                float weight = SubLayerWeights[i];

                if (i == PrimaryInputId)
                {
                    weight += TransitionRate * Time.deltaTime;
                    ++clipCount;
                }
                else
                {
                    if (weight > Mathf.Epsilon)
                    {
                        ++clipCount;

                        weight -= TransitionRate * Time.deltaTime;

                        if (weight < Mathf.Epsilon)
                        {
                            //The playable at this point can be removed
                            var playable = Mixer.GetInput(i);
                            if (playable.IsValid())
                            {
                                Mixer.DisconnectInput(i);
                                ClearPlayable(ref playable);
                            }

                            weight = 0f;
                        }
                    }
                }

                SubLayerWeights[i] = weight;

                cumulativeWeight += weight;
            }

            //normalize weights and apply them
            for (int i = 0; i < SubLayerWeights.Length; ++i)
                Mixer.SetInputWeight(i, SubLayerWeights[i] / cumulativeWeight);

            if (clipCount == 1)
                return true; //Complete

            return false; //Not complete
        }
Beispiel #3
0
        //============================================================================================
        /**
        *  @brief Clears all clips from the layer but does not destroy the mixer for the layer
        *         
        *********************************************************************************************/
        private void ClearLayerPlayables()
        {
            if (!Mixer.IsValid())
                return;

            for (int i = 0; i < MaxClips; ++i)
            {
                var playable = Mixer.GetInput(i);

                if (playable.IsValid())
                    ClearPlayable(ref playable);
            }

            PrimaryInputId = 0;
            PrimaryClip = null;
        }