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;
        }