Esempio n. 1
0
    public void Play(string name, bool loop)
    {
        /*
         * Sound s = Array.Find(sounds, sound => sound.name == name);
         * if(s == null)
         * {
         *  Debug.LogWarning("Sound: " + name + "not found!");
         *  return;
         * }
         * s.source.Play();
         */
        Sound s = Array.Find(sounds, sound => sound.name == name);

        if (s == null)
        {
            Debug.LogWarning("Sound: " + name + "not found!");
            return;
        }

        if (loop)
        {
            s.stream = AndroidNativeAudio.play(s.id, loop: -1);
        }
        else
        {
            s.stream = AndroidNativeAudio.play(s.id);
        }
        AndroidNativeAudio.setVolume(s.stream, s.volume);
        s.streamSet = true;
    }
    public void PlayEffect(string effectName)
    {
        SoundEffect s       = Array.Find(effects, effect => effect.name == effectName); // this uses a Lambda Expression
        int         soundID = AndroidNativeAudio.play(s.fileID);

        AndroidNativeAudio.setVolume(soundID, s.volume * volumeControl.EffectsVolume);
    }
Esempio n. 3
0
    public void PlaySound(eSound enumS, int loop)
    {
        AndroidNativeAudio.setVolume(SoundID[(int)enumS], GameManager.Instance.AudioVolume);
        SoundID[(int)enumS] = AndroidNativeAudio.play(FileID[(int)enumS], GameManager.Instance.AudioVolume);
        AndroidNativeAudio.setVolume(SoundID[(int)enumS], GameManager.Instance.AudioVolume);

        AndroidNativeAudio.setLoop(SoundID[(int)enumS], loop);
        //for (int i = 0; i < System.Enum.GetValues(typeof(eSound)).Length; i++)
        //{
        //    SoundID[i] = AndroidNativeAudio.play(FileID[i]);
        //}
        //Debug.Log("GameManager.Instance.AudioVolume" + GameManager.Instance.AudioVolume);
    }
Esempio n. 4
0
    void ModifySound()
    {
        // These aren't necessary, but show how you could work with a loaded sound.

        AndroidNativeAudio.pause(SoundID);
        AndroidNativeAudio.resume(SoundID);
        AndroidNativeAudio.stop(SoundID);

        AndroidNativeAudio.pauseAll();
        AndroidNativeAudio.resumeAll();

        AndroidNativeAudio.setVolume(SoundID, 0.5f);
        AndroidNativeAudio.setLoop(SoundID, 3);
        AndroidNativeAudio.setPriority(SoundID, 5);
        AndroidNativeAudio.setRate(SoundID, 0.75f);
    }
    IEnumerator FadeOutSFXCorou(int id, float t)
    {
        float tt = 0;

        if (t != 0)
        {
            do
            {
                yield return(null);

                tt += TimeManager.Instance.UnscaledDeltaTime / t;
                AndroidNativeAudio.setVolume(id, Mathf.Lerp(sfxVolume, 0, tt));
            } while (tt < 1);
        }
        AndroidNativeAudio.stop(id);
    }
Esempio n. 6
0
    private IEnumerator LoadSounds()
    {
        yield return(new WaitForSeconds(0.1f));

        var allSounds = ConcatArrays(WelcomeSoundName, ButtonClickSoundName, SceneLoadSoundName, RedPlantedSoundName, BluePlantedSoundName, YellowPlantedSoundName, WinSoundName, LossSoundName, WinMusicName, LossMusicName, CorrectSoundName, IncorrectSoundName, GrowingSoundName, ShakeSoundName);

        State.loadGoals += (float)allSounds.Length;

        Debug.LogWarningFormat("Loading Goal Increased to {0}", State.loadGoals);

        // set all volumes to 0
        float tempVoiceVolume   = VoiceSource.volume;
        float tempButtonVolume  = ButtonSource.volume;
        float tempStingerVolume = StingerSource.volume;

        VoiceSource.volume   = 0;
        ButtonSource.volume  = 0;
        StingerSource.volume = 0;


#if UNITY_ANDROID && !UNITY_EDITOR
        AndroidNativeAudio.setVolume(0, 0f);
        AndroidNativeAudio.setVolume(1, 0f);
        AndroidNativeAudio.setVolume(2, 0f);
#endif

        foreach (string c in allSounds)
        {
            string path = "";


#if UNITY_ANDROID && !UNITY_EDITOR
            int soundID = AndroidNativeAudio.load(c + ".wav");
            //Debug.LogFormat("Loading Sound:SoundID {0}: {1}", c, soundID);
            if (!dictSounds.ContainsKey(c))
            {
                dictSounds.Add(c, soundID);
                //AndroidNativeAudio.play(dictSounds[c]);
                yield return(new WaitForSeconds(0.01f));
            }
#else
            path = "file://" + System.IO.Path.Combine(Application.streamingAssetsPath, c + ".wav");
            //Debug.LogFormat("Loading AudioClip {0}::{1}", c, path);

            using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV))
            {
                yield return(www.SendWebRequest());

                if (www.result == UnityWebRequest.Result.ConnectionError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
                    if (!dictClips.ContainsKey(c))
                    {
                        dictClips.Add(c, myClip);
                        yield return(new WaitForSeconds(0.01f));
                    }
                }
            }
#endif

            State.loadGoalsComplete += 1f;
        }

        // set all volumes back to what they were
        VoiceSource.volume   = tempVoiceVolume;
        ButtonSource.volume  = tempButtonVolume;
        StingerSource.volume = tempStingerVolume;

#if UNITY_ANDROID && !UNITY_EDITOR
        AndroidNativeAudio.setVolume(0, maxSoundEffectVolume);
        AndroidNativeAudio.setVolume(1, maxSoundEffectVolume);
        AndroidNativeAudio.setVolume(2, maxSoundEffectVolume);
#endif



        allAudioLoaded = true;
    }
Esempio n. 7
0
    public void PlaySound(string fileName, float volume = 1f)
    {
        int SoundID = AndroidNativeAudio.play(fileIDs[fileName]);

        AndroidNativeAudio.setVolume(SoundID, volume);
    }