/// <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
    }
Ejemplo n.º 4
0
 public void PlayExplosions(SFXGroup DesiredSFX)
 {
     SFXManager.Main.Play(DesiredSFX, 0.5f, 0.2f);
 }
Ejemplo n.º 5
0
 /// <summary>Plays the SFXGroup in 3D space.</summary>
 /// <param name="SFX">The SFXGroup that will be played.</param>
 /// <param name="Position">The position in 3D space to play the SFXGroup at.</param>
 /// <param name="DelayDuration">Duration of the global delay for the SFXGroup.</param>
 /// <param name="Volume">The volume multiplier of the SFXObject to be used.</param>
 /// <param name="Pitch">The pitch multiplier of the SFXObject to be used.</param>
 /// <param name="Parent">Parent transform to assign to the SFXGroup (Optional).</param>
 /// <param name="IsGlobalPosition">If the position to play the SFXObject at is global or local to the parent.</param>
 /// <returns>The Coroutine for delaying the SFXObject played (null if no delay is applied).</returns>
 public Coroutine Play(SFXGroup SFX, Vector3 Position, float DelayDuration, float Volume, float Pitch, Transform Parent = null, bool IsGlobalPosition = true)
 {
     return(SFX.Play(Position, DelayDuration, Volume, Pitch, Parent, IsGlobalPosition));
 }
Ejemplo n.º 6
0
 public void Play(SFXGroup DesiredSFX)
 {
     SFXManager.Main.Play(DesiredSFX);
 }
Ejemplo n.º 7
0
 /// <summary>Plays the SFXGroup with the default delay settings in 3D space.</summary>
 /// <param name="SFX">The SFXGroup that will be played.</param>
 /// <param name="Position">The position in 3D space to play the SFXGroup at.</param>
 /// <param name="Parent">Parent transform to assign to the SFXGroup (Optional).</param>
 /// <param name="IsGlobalPosition">If the position to play the SFXObject at is global or local to the parent.</param>
 /// <returns>The Coroutine for delaying the SFXObject played (null if no delay is applied).</returns>
 public Coroutine Play(SFXGroup SFX, Vector3 Position, Transform Parent = null, bool IsGlobalPosition = true)
 {
     return(SFX.Play(Position, Parent, IsGlobalPosition));
 }
Ejemplo n.º 8
0
 /// <summary>Plays the SFXGroup.</summary>
 /// <param name="SFX">The SFXGroup that will be played.</param>
 /// <param name="DelayDuration">Duration of the global delay for the SFXGroup.</param>
 /// <param name="Volume">The volume multiplier of the SFXObject to be used.</param>
 /// <param name="Pitch">The pitch multiplier of the SFXObject to be used.</param>
 /// <returns>The Coroutine for delaying the SFXObject played (null if no delay is applied).</returns>
 public Coroutine Play(SFXGroup SFX, float DelayDuration, float Volume, float Pitch)
 {
     return(SFX.Play(DelayDuration, Volume, Pitch));
 }
Ejemplo n.º 9
0
 /// <summary>Plays the SFXGroup.</summary>
 /// <param name="SFX">The SFXGroup that will be played.</param>
 /// <param name="DelayDuration">Duration of the global delay for the SFXGroup.</param>
 /// <returns>The Coroutine for delaying the SFXObject played (null if no delay is applied).</returns>
 public Coroutine Play(SFXGroup SFX, float DelayDuration)
 {
     return(SFX.Play(DelayDuration));
 }
Ejemplo n.º 10
0
 /// <summary>Plays the SFXGroup with the default delay settings.</summary>
 /// <param name="SFX">The SFXGroup that will be played.</param>
 /// <returns>The Coroutine for delaying the SFXObject played (null if no delay is applied).</returns>
 public Coroutine Play(SFXGroup SFX)
 {
     return(SFX.Play());
 }
Ejemplo n.º 11
0
    private void ShowSoundFXGroupsList()
    {
        EditorGUILayout.BeginVertical();
        {
            EditorGUI.indentLevel++;
            if (script.helpOn)
            {
                EditorGUILayout.HelpBox("SFX Groups are used to:\n1. Access random clips in a set.\n2. Apply specific cap amounts to clips when using SoundManager.PlayCappedSFX." +
                                        "\n\n-Setting the cap amount to -1 will make a group use the default SFX Cap Amount\n\n-Setting the cap amount to 0 will make a group not use a cap at all.", MessageType.Info);
            }
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Group Name:", GUILayout.ExpandWidth(true));
                EditorGUILayout.LabelField("Cap:", GUILayout.Width(40f));
                bool helpOn = script.helpOn;
                helpOn = GUILayout.Toggle(helpOn, "?", GUI.skin.button, GUILayout.Width(35f));
                if (helpOn != script.helpOn)
                {
                    SoundManagerEditorTools.RegisterObjectChange("Change SFXGroup Help", script);
                    script.helpOn = helpOn;
                    EditorUtility.SetDirty(script);
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("", GUILayout.Width(10f));
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
            }
            EditorGUILayout.EndHorizontal();

            for (int i = 0; i < script.sfxGroups.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    SFXGroup grp = script.sfxGroups[i];

                    if (grp != null)
                    {
                        EditorGUILayout.LabelField(grp.groupName, GUILayout.ExpandWidth(true));
                        int  specificCapAmount = grp.specificCapAmount;
                        bool isAuto = false, isNo = false;

                        if (specificCapAmount == -1)
                        {
                            isAuto = true;
                        }
                        else if (specificCapAmount == 0)
                        {
                            isNo = true;
                        }

                        bool newAuto = GUILayout.Toggle(isAuto, "Auto Cap", GUI.skin.button, GUILayout.ExpandWidth(false));
                        bool newNo   = GUILayout.Toggle(isNo, "No Cap", GUI.skin.button, GUILayout.ExpandWidth(false));

                        if (newAuto != isAuto && newAuto)
                        {
                            specificCapAmount = -1;
                        }
                        if (newNo != isNo && newNo)
                        {
                            specificCapAmount = 0;
                        }

                        specificCapAmount = EditorGUILayout.IntField(specificCapAmount, GUILayout.Width(40f));
                        if (specificCapAmount < -1)
                        {
                            specificCapAmount = -1;
                        }

                        if (specificCapAmount != grp.specificCapAmount)
                        {
                            SoundManagerEditorTools.RegisterObjectChange("Change Group Cap", script);
                            grp.specificCapAmount = specificCapAmount;
                            EditorUtility.SetDirty(script);
                        }

                        EditorGUILayout.LabelField("", GUILayout.Width(10f));
                        GUI.color = Color.red;
                        if (GUILayout.Button("X", GUILayout.Width(20f)))
                        {
                            RemoveGroup(i);
                            return;
                        }
                        GUI.color = Color.white;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            ShowAddGroup();
            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
        }
        EditorGUILayout.EndVertical();
    }