Exemple #1
0
        public string RandomWeightedAudioData()
        {
            // Invalid data
            if (AudioData.Count <= 1)
            {
                return(GetNextOrderedAudioData());
            }
            // If needed init AudioDataWeigt
            if (AudioDataWeight.Count <= 1 || m_AudioData.Count != AudioDataWeight.Count)
            {
                AudioDataWeight.Clear();
                for (int i = 0; i < m_AudioData.Count; i++)
                {
                    AudioDataWeight.Add(1);
                }
            }

            // Check first weight calculations
            if (m_TotalWeight == -1)
            {
                m_TotalWeight = 0;
                foreach (int weight in AudioDataWeight)
                {
                    m_TotalWeight += weight;
                }
            }

            // Ajust weight of last selected
            if (m_LastSelected != -1)
            {
                m_TotalWeight -= AudioDataWeight[m_LastSelected];
                AudioDataWeight[m_LastSelected] = 0;
            }

            int cumulative = 0;
            int diceRoll   = UnityEngine.Random.Range(0, m_TotalWeight);

            for (int i = 0; i < AudioDataWeight.Count; i++)
            {
                cumulative += m_AudioDataWeight[i];
                if (diceRoll < cumulative)
                {
                    if (m_LastSelected != -1)
                    {
                        AudioDataWeight[m_LastSelected] = 1;
                    }
                    m_LastSelected = i;
                    return(AudioData[i]);
                }
            }
            if (m_LastSelected != -1)
            {
                AudioDataWeight[m_LastSelected] = 1;
            }
            return(GetNextOrderedAudioData());
        }
Exemple #2
0
        public void RemoveAudioData(int index)
        {
            if (AudioData.Count == 0)
            {
                return;
            }
            ;

            if (AudioData.Count == 1 && index == 0)
            {
                AudioData[index]       = null;
                AudioDataWeight[index] = 1;
            }
            AudioData.RemoveAt(index);
            AudioDataWeight.RemoveAt(index);
        }
Exemple #3
0
 public void NewAudioData()
 {
     AudioData.Add(null);
     AudioDataWeight.Add(1);
 }