Exemplo n.º 1
0
    public static void PlaySFX(SFXClip clip) //add volume parameter for attenuation
    {
        switch (clip)
        {
        case SFXClip.Buzz:
        {
            s_Instance.m_MusicSource.PlayOneShot(s_Instance.m_Buzz);
            break;
        }

        case SFXClip.Checkpoint:
        {
            s_Instance.m_MusicSource.PlayOneShot(s_Instance.m_Checkpoint);
            break;
        }

        case SFXClip.Magnet:
        {
            s_Instance.m_MusicSource.PlayOneShot(s_Instance.m_Magnet);
            break;
        }

        case SFXClip.Splash:
        {
            s_Instance.m_MusicSource.PlayOneShot(s_Instance.m_Splash);
            break;
        }

        default:
            break;
        }
    }
Exemplo n.º 2
0
 void TestSound(SFXClip clip)
 {
     if (sound_object != null)
     {
         clip.PlaySound(sound_object);
     }
 }
Exemplo n.º 3
0
    private void SFXChange()
    {
        //keep the label up to date
        sfxLabel = sfxType.ToString() + " SFX";

        //keep the displayed "SFX clip" up to date
        _sfxBase = sfxToPlay;
    }
Exemplo n.º 4
0
 public void playAudioClip(SFXClip clipName, Vector3 position, float volume = 1.0f)
 {
     if (audioBank == null)
     {
         gameObject.AddComponent("AudioBank");
         audioBank = GetComponent <AudioBank>();
     }
     audioBank.playClipAtPoint(clipName, position, volume);
 }
Exemplo n.º 5
0
 public void playAudioClip(SFXClip clipName, float volume = 1.0f)
 {
     if (audioBank == null)
     {
         gameObject.AddComponent("AudioBank");
         audioBank = GetComponent <AudioBank>();
     }
     audioBank.playAudioClip(clipName, volume);
 }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        SoundBank bank = target as SoundBank;

        EditorGUI.BeginDisabledGroup(true);
        EditorGUILayout.ObjectField("Script", MonoScript.FromScriptableObject(bank), typeof(MonoScript), false);
        EditorGUI.EndDisabledGroup();

        search_string = EditorGUILayout.TextField(search_string);

        SerializedProperty array = serializedObject.FindProperty("_sound_effect_list");

        for (int i = 0; i < array.arraySize; i++)
        {
            SFXClip current_clip = array.GetArrayElementAtIndex(i).objectReferenceValue as SFXClip;
            if (current_clip == null || (search_string != "" && !current_clip.codename.Contains(search_string) && !current_clip.name.Contains(search_string)))
            {
                continue;
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("X", GUILayout.MaxWidth(20f)))
            {
                if (array.GetArrayElementAtIndex(i).objectReferenceValue != null)
                {
                    array.DeleteArrayElementAtIndex(i);
                }
                array.DeleteArrayElementAtIndex(i);
                i--;
                serializedObject.ApplyModifiedProperties();
                continue;
            }

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField(array.GetArrayElementAtIndex(i).objectReferenceValue, typeof(SFXClip), false);
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
        }

        is_create_clip_folded_out = DrawLine(is_create_clip_folded_out, "Create SFXClip");
        if (is_create_clip_folded_out)
        {
            EditorGUI.indentLevel += 1;
            CreateClip(bank);
            EditorGUI.indentLevel -= 1;
        }

        is_add_clip_folded_out = DrawLine(is_add_clip_folded_out, "Add SFXClip");
        if (is_add_clip_folded_out)
        {
            EditorGUI.indentLevel += 1;
            AddClip(bank);
            EditorGUI.indentLevel -= 1;
        }
    }
Exemplo n.º 7
0
    public void playClipAtPoint(SFXClip clipName, Vector3 position, float volume = 1.0f)
    {
        AudioClip clip = null;

        clipList.TryGetValue(clipName, out clip);
        if (clip == null)
        {
            return;
        }
        AudioSource.PlayClipAtPoint(clip, position, volume);
    }
Exemplo n.º 8
0
    void AddToBank(SerializedObject bank, SFXClip sfx_clip)
    {
        SerializedObject sfx_clip_object = new SerializedObject(sfx_clip);

        sfx_clip_object.FindProperty("_codename").stringValue = SoundBank.GetCodename(sfx_clip.name);
        sfx_clip_object.ApplyModifiedProperties();

        string new_path = "Assets/SFX/Resources/" + sfx_clip.name + ".asset";

        AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(sfx_clip), new_path);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        SerializedProperty property = bank.FindProperty("_sound_effect_list");

        property.InsertArrayElementAtIndex(property.arraySize);
        property.GetArrayElementAtIndex(property.arraySize - 1).objectReferenceValue = AssetDatabase.LoadAssetAtPath <SFXClip>(new_path);

        bank.ApplyModifiedProperties();
    }
Exemplo n.º 9
0
    public static void PlaySFX(SFXClip sfx, bool waitToFinish = true, AudioSource audioSource = null)
    {
        if (audioSource == null)
        {
            audioSource = SFXManager.instance.defaultAudioSource;
        }

        if (audioSource == null)
        {
            Debug.LogError("You forgot to add a default audio source!");
            return;
        }

        if (!audioSource.isPlaying || !waitToFinish)
        {
            audioSource.clip   = sfx.clip;
            audioSource.volume = sfx.volume + Random.Range(-sfx.volumeVariation, sfx.volumeVariation);
            audioSource.pitch  = sfx.pitch + Random.Range(-sfx.pitchVariation, sfx.pitchVariation);
            audioSource.Play();
        }
    }
Exemplo n.º 10
0
    public override void OnInspectorGUI()
    {
        SFXClip clip = target as SFXClip;

        base.OnInspectorGUI();

        EditorGUILayout.Space();

        if (scene_loaded)
        {
            Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 1);
            GUI.Box(rect, "", line_style);

            if (GUILayout.Button("Test Sound"))
            {
                TestSound(clip);
            }

            sound_object.volume = EditorGUILayout.Slider("Game Volume", sound_object.volume, 0, 1);
        }
    }
Exemplo n.º 11
0
 public void PlaySong(SFXClip clip, bool loop = true)
 {
     instance.main.UnPause();
     main.loop = loop;
     if (main.clip == null || !main.isPlaying)
     {
         main.clip = clip.clip;
         if (fade_routine != null)
         {
             StopCoroutine(fade_routine);
         }
         fade_routine = StartCoroutine(FadeInMain(2f));
     }
     else
     {
         if (fade_routine != null)
         {
             StopCoroutine(fade_routine);
         }
         fade_routine = StartCoroutine(TradeOutMain(2f, clip.clip));
     }
 }
Exemplo n.º 12
0
    void CreateAndAddToBank(SerializedObject bank, AudioClip clip, string name, string codename)
    {
        string path = "Assets/SFX/Resources";

        path = AssetDatabase.GenerateUniqueAssetPath(path + "/" + name + ".asset");
        SFXClip          sfx_clip        = CreateInstance <SFXClip>();
        SerializedObject sfx_clip_object = new SerializedObject(sfx_clip);

        sfx_clip_object.FindProperty("_codename").stringValue      = codename;
        sfx_clip_object.FindProperty("_clip").objectReferenceValue = clip;
        sfx_clip_object.ApplyModifiedProperties();

        AssetDatabase.CreateAsset(sfx_clip, path);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        SerializedProperty property = bank.FindProperty("_sound_effect_list");

        property.InsertArrayElementAtIndex(property.arraySize);
        property.GetArrayElementAtIndex(property.arraySize - 1).objectReferenceValue = sfx_clip;

        bank.ApplyModifiedProperties();
    }
Exemplo n.º 13
0
    void AddClip(SoundBank bank)
    {
        EditorGUILayout.BeginHorizontal();

        add_clip = (SFXClip)EditorGUILayout.ObjectField(add_clip, typeof(SFXClip), false);

        EditorGUI.BeginDisabledGroup(add_clip == null || bank.HasSFXClip(SoundBank.GetCodename(add_clip.name)));

        if (GUILayout.Button("Add SFXClip"))
        {
            AddToBank(serializedObject, add_clip);
            add_clip = null;
        }

        EditorGUI.EndDisabledGroup();

        EditorGUILayout.EndHorizontal();

        if (add_clip != null && bank.HasSFXClip(SoundBank.GetCodename(add_clip.name)))
        {
            EditorGUILayout.LabelField(SoundBank.GetCodename(add_clip.name) + " already exists in sound bank.", error_style);
        }
    }
Exemplo n.º 14
0
 public void playAudioClip(SFXClip clipName, float volume = 1.0f)
 {
     playClipAtPoint(clipName, Camera.main.transform.position, volume);
 }
Exemplo n.º 15
0
 public void importAudioClip(SFXClip key, string filename)
 {
     clipList.Add(key, Resources.Load <AudioClip>("Audio/SFX/" + filename));
 }
Exemplo n.º 16
0
 public static void playSFXClip(SFXClip clipName, float volume = 1.0f)
 {
     primaryAudioManager.playAudioClip(clipName, volume);
 }