/// <summary>
        /// Determines whether the specified cappedID is at capacity.
        /// </summary>
        private bool IsAtCapacity(string cappedID, string clipName)
        {
            int thisCapAmount = capAmount;

            // Check if in a group and has a specific cap amount
            SFXGroup grp = GetGroupForClipName(clipName);

            if (grp != null)
            {
                if (grp.specificCapAmount == 0) // If no cap amount on this group
                {
                    return(false);
                }
                if (grp.specificCapAmount != -1) // If it is a specific cap amount
                {
                    thisCapAmount = grp.specificCapAmount;
                }
            }

            // If there are no other capped objects with this cappedID, then it can't be at capacity
            if (!cappedSFXObjects.ContainsValue(cappedID))
            {
                return(false);
            }

            // Check the count of capped objects with the same cappedID, if >= return true
            int count = 0;

            foreach (string id in cappedSFXObjects.Values)
            {
                if (id == cappedID)
                {
                    count++;
                    if (count >= thisCapAmount)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void RemoveClipFromGroup(string clipName)
        {
            // if not in a group, do nothing
            SFXGroup grp = GetGroupForClipName(clipName);

            if (grp == null)
            {
                return;
            }
            else
            {
                // if in a group, remove it
                grp.clips.Remove(Load(clipName));
                clipsInGroups.Remove(clipName);
            }

#if UNITY_EDITOR
            int index = clipToGroupKeys.IndexOf(clipName);
            clipToGroupKeys.RemoveAt(index);
            clipToGroupValues.RemoveAt(index);
#endif
        }
Ejemplo n.º 3
0
        /* these functions convert the editor dictionaries to efficient dictionaries while in play */
        private void SetupDictionary()
        {
            allClips.Clear();
            prepools.Clear();
            baseVolumes.Clear();
            volumeVariations.Clear();
            pitchVariations.Clear();
            for (int i = 0; i < storedSFXs.Count; i++)
            {
                if (storedSFXs[i] == null)
                {
                    continue;
                }
                string clipName = storedSFXs[i].name;
                allClips.Add(clipName, storedSFXs[i]);
                prepools.Add(clipName, sfxPrePoolAmounts[i]);
                baseVolumes.Add(clipName, sfxBaseVolumes[i]);
                volumeVariations.Add(clipName, sfxVolumeVariations[i]);
                pitchVariations.Add(clipName, sfxPitchVariations[i]);
            }
#if !UNITY_EDITOR
            storedSFXs.Clear();
#endif

            if (clipToGroupKeys.Count != clipToGroupValues.Count) //this should never be the case, but in case they are out of sync, sync them.
            {
                if (clipToGroupKeys.Count > clipToGroupValues.Count)
                {
                    clipToGroupKeys.RemoveRange(clipToGroupValues.Count, clipToGroupKeys.Count - clipToGroupValues.Count);
                }
                else if (clipToGroupValues.Count > clipToGroupKeys.Count)
                {
                    clipToGroupValues.RemoveRange(clipToGroupKeys.Count, clipToGroupValues.Count - clipToGroupKeys.Count);
                }
            }

            clipsInGroups.Clear();
            groups.Clear();

            for (int i = 0; i < clipToGroupValues.Count; i++)
            {
                if (!ClipNameIsValid(clipToGroupKeys[i]))
                {
                    continue;
                }

                // Set up clipsInGroups, which maps clip names to group names if they are in a group
                clipsInGroups.Add(clipToGroupKeys[i], clipToGroupValues[i]);

                // Set up groups, which maps group names to SFXGroups and populates the clip lists
                if (!groups.ContainsKey(clipToGroupValues[i]))
                {
                    groups.Add(clipToGroupValues[i], new SFXGroup(clipToGroupValues[i], new AudioClip[] { Load(clipToGroupKeys[i]) }));
                }
                else
                {
                    if (groups[clipToGroupValues[i]] == null)
                    {
                        groups[clipToGroupValues[i]] = new SFXGroup(clipToGroupValues[i], new AudioClip[] { Load(clipToGroupKeys[i]) });
                    }
                    else
                    {
                        groups[clipToGroupValues[i]].clips.Add(Load(clipToGroupKeys[i]));
                    }
                }
            }

            foreach (SFXGroup sfxGroup in sfxGroups)
            {
                if (sfxGroup != null && groups.ContainsKey(sfxGroup.groupName))
                {
                    groups[sfxGroup.groupName].specificCapAmount = sfxGroup.specificCapAmount;
                }
            }
#if !UNITY_EDITOR
            sfxGroups.Clear();
#endif
        }