コード例 #1
0
    private IEnumerator PlayOneShotSoundAtCoroutine(SoundNames name, AudioSource audioSource, float delay)
    {
        if (delay > 0)
        {
            yield return(new WaitForSeconds(delay));
        }
        CorrectedSoundClip clip = null;
        float minPitch          = 0;
        float maxPitch          = 0;

        for (int i = 0; i < sounds.Length; i++)
        {
            Sound sound = sounds[i];
            if (sounds[i].name == name)
            {
                clip     = sound.audioClips[UnityEngine.Random.Range(0, sound.audioClips.Length)];
                minPitch = sound.minPitch; maxPitch = sound.maxPitch;
            }
        }
        if (clip == null)
        {
            Debug.LogError("NO SOUND FOUND!");
        }
        else
        {
            audioSource.clip   = clip.clip;
            audioSource.pitch  = UnityEngine.Random.Range(minPitch, maxPitch);
            audioSource.volume = clip.volume;
            audioSource.Play();
        }
    }
コード例 #2
0
    /// <summary>
    /// Stops the sound
    /// </summary>
    /// <param name="soundName">Name of the sound that needs to be stopped</param>
    public void StopSound(SoundNames soundName)
    {
        SoundData soundData = m_AudioData.Find(x => x.SoundID == soundName);

        if (soundData.AudioSource != null)
        {
            soundData.AudioSource.Stop();
        }
    }
コード例 #3
0
    // SOUNDS
    public void PlaySound(SoundNames soundID)
    {
        SoundSO sound = Sounds.Find(s => s.SoundID == soundID);

        if (sound != null)
        {
            StartCoroutine(PlayingSound(sound));
        }
    }
コード例 #4
0
ファイル: SoundManager.cs プロジェクト: ReemHA/GD_Test
 public void PlaySFX(SoundNames soundName)
 {
     for (int i = 0; i < sounds.Length; i++)
     {
         if (sounds[i].name == soundName)
         {
             audioSource.PlayOneShot(sounds[i].audioClip);
         }
     }
 }
コード例 #5
0
    /// <summary>
    /// Plays a sound by name
    /// </summary>
    /// <param name="soundName">Name of the sound to play</param>
    /// <param name="loop">Loop the sound?</param>
    public void PlaySound(SoundNames soundName, bool loop = false)
    {
        SoundData soundData = m_AudioData.Find(x => x.SoundID == soundName);

        if (soundData.AudioSource != null)
        {
            soundData.AudioSource.loop = loop;
            soundData.AudioSource.Play();
        }
    }
コード例 #6
0
        public sound_cache_file_gestalt(CacheBase Cache, int Address)
        {
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region Codec Chunk
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Codecs.Add(new Codec(Cache, iOffset + 3 * i));
            }
            #endregion

            #region SoundName Chunk
            Reader.SeekTo(Address + 36);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                SoundNames.Add(new SoundName(Cache, iOffset + 4 * i));
            }
            #endregion

            #region Playback Chunk
            Reader.SeekTo(Address + 72);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                PlayBacks.Add(new Playback(Cache, iOffset + 12 * i));
            }
            #endregion

            #region SoundPermutation Chunk
            Reader.SeekTo(Address + 84);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                SoundPermutations.Add(new SoundPermutation(Cache, iOffset + 16 * i));
            }
            #endregion

            #region Raw Chunks
            Reader.SeekTo(Address + 160);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                RawChunks.Add(new RawChunk(Cache, iOffset + 20 * i));
            }
            #endregion
        }
コード例 #7
0
    public void Play(SoundNames soundName)
    {
        var s = Array.Find(sounds, sound => sound.SoundName == soundName);

        if (s == null)
        {
            Debug.LogWarning("Sound " + name + " not found!");
            return;
        }
        s.Source.Play();
    }
コード例 #8
0
    public void PlaySound(SoundNames soundName)
    {
        AudioClip audioClip = audioClipSilent;

        switch (soundName)
        {
        case SoundNames.Miss:
            audioClip = audioClipMiss;
            break;
        }
        this.GetComponent <AudioSource>().PlayOneShot(audioClip);
    }
コード例 #9
0
    /// <summary>
    /// Is the sound playing?
    /// </summary>
    /// <param name="soundName">Name of the sound</param>
    /// <returns>Whether the sound is playing or not</returns>
    public bool IsSoundPlaying(SoundNames soundName)
    {
        SoundData soundData = m_AudioData.Find(x => x.SoundID == soundName);

        if (soundData.AudioSource != null)
        {
            return(soundData.AudioSource.isPlaying);
        }
        else
        {
            return(false);
        }
    }
コード例 #10
0
    private static SoundAudioClip GetChosenSoundByName(SoundNames soundName)
    {
        for (int i = 0; i < Sounds.Instance.SoundsAudioClips.Length; i++)
        {
            if (Sounds.Instance.SoundsAudioClips[i].SoundName == soundName)
            {
                return(Sounds.Instance.SoundsAudioClips[i]);
            }
        }

        Debug.LogError("Sound " + soundName + " not found!");
        return(null);
    }
コード例 #11
0
    private void DoCollisionViewStuff(bool hardCollision)
    {
        int currentFrameCount = Time.frameCount;

        if (currentFrameCount == frameCount)
        {
            return;
        }
        frameCount = currentFrameCount;
        animator.SetTrigger("Bounce");
        collisionParticles.Play();
        //SoundManager.PlayOneShotSoundAt(SoundNames.WallHit, audioSource);
        SoundNames soundName = hardCollision ? SoundNames.LowGlocken : SoundNames.AllGlocken;

        SoundManager.PlayOneShotSoundAt(soundName, transform.position);
    }
コード例 #12
0
 /// <summary>
 /// Generate default name lists, based on Descent 2's HAM file. Must be called after reading the data file.
 /// </summary>
 public void GenerateDefaultNamelists()
 {
     for (int i = 0; i < BaseFile.VClips.Count; i++)
     {
         VClips[i].Name = ElementLists.GetVClipName(i);
     }
     for (int i = 0; i < BaseFile.EClips.Count; i++)
     {
         EClips[i].Name = ElementLists.GetEClipName(i);
     }
     for (int i = 0; i < BaseFile.Robots.Count; i++)
     {
         Robots[i].Name = ElementLists.GetRobotName(i);
     }
     for (int i = 0; i < BaseFile.Weapons.Count; i++)
     {
         Weapons[i].Name = ElementLists.GetWeaponName(i);
     }
     for (int i = 0; i < BaseFile.Sounds.Length; i++)
     {
         SoundNames.Add(ElementLists.GetSoundName(i));
     }
     if (BaseFile.Version >= 3)
     {
         for (int i = 0; i < BaseFile.Models.Count; i++)
         {
             Models[i].Name = ElementLists.GetModelName(i);
         }
     }
     else
     {
         for (int i = 0; i < BaseFile.Models.Count; i++)
         {
             Models[i].Name = ElementLists.GetDemoModelName(i);
         }
     }
     for (int i = 0; i < BaseFile.Powerups.Count; i++)
     {
         Powerups[i].Name = ElementLists.GetPowerupName(i);
     }
     for (int i = 0; i < BaseFile.Reactors.Count; i++)
     {
         Reactors[i].Name = ElementLists.GetReactorName(i);
     }
 }
コード例 #13
0
    private IEnumerator PlayOneShotSoundAtCoroutine(SoundNames name, Vector3 position, float delay)
    {
        if (delay > 0)
        {
            yield return(new WaitForSeconds(delay));
        }
        CorrectedSoundClip clip  = null;
        float minPitch           = 0;
        float maxPitch           = 0;
        float volumeModification = 0;

        for (int i = 0; i < sounds.Length; i++)
        {
            Sound sound = sounds[i];
            if (sounds[i].name == name)
            {
                int clipIndex = 0;
                for (int j = 0; j < 8; j++)
                {
                    clipIndex = UnityEngine.Random.Range(0, sound.audioClips.Length);
                    if (!sound.audioClips[clipIndex].ignoreMe)
                    {
                        break;
                    }
                }
                clip               = sound.audioClips[clipIndex];
                minPitch           = sound.minPitch; maxPitch = sound.maxPitch;
                volumeModification = UnityEngine.Random.Range(0, sound.volumeModifier);
            }
        }
        if (clip == null)
        {
            Debug.LogError("NO SOUND FOUND: " + name.ToString());
        }
        else
        {
            AudioSource oneShotSound = GetAvailableAudioSource();
            oneShotSound.transform.position = position;
            oneShotSound.clip   = clip.clip;
            oneShotSound.pitch  = UnityEngine.Random.Range(minPitch, maxPitch);
            oneShotSound.volume = clip.volume + volumeModification;
            oneShotSound.Play();
        }
    }
コード例 #14
0
    public void Play(SoundNames sound_name)
    {
        Sound sound_found = null;

        if (Array.Find(sounds_array, sound => sound.name == sound_name).clip)
        {
            sound_found = Array.Find(sounds_array, sound => sound.name == sound_name);
        }

        if (sound_found == null || sound_found.audio_source.isPlaying)
        {
            return;
        }

        if (sound_found.clip)
        {
            sound_found.audio_source.Play();
        }
    }
コード例 #15
0
        public void playSound(Stream s = null, SoundNames soundName = 0)
        {
            if (InvokeRequired)
            {
                Invoke(new Action <Stream, SoundNames>(playSound), new object[] { s, soundName });
                return;
            }
            switch (soundName)
            {
            case SoundNames.Waka:
                samplePlayer.playWaka(false);
                break;

            default:

                SoundPlayer player = new SoundPlayer(s);
                player.Play();
                break;
            }
        }
コード例 #16
0
    public void PlaySound(SoundNames soundName)
    {
        SoundAudioClip chosenSound = GetChosenSoundByName(soundName);
        AudioSource    source      = chosenSound.AudioSource;

        if (soundName == SoundNames.Jump)
        {
            source.pitch = 1 + (Random.Range(-JumpPitchAlteration, JumpPitchAlteration));
        }
        else if (soundName == SoundNames.CollectCorrect)
        {
            source.pitch = goodCollectionPitch;
        }
        else
        {
            source.pitch = 1;
        }

        source.loop   = chosenSound.Loop;
        source.volume = chosenSound.Volume;
        source.clip   = chosenSound.AudioClip;
        source.Play();
    }
コード例 #17
0
 public static void PlayOneShotSoundAt(SoundNames name, Vector3 position, float delay = 0)
 {
     instance.StartCoroutine(instance.PlayOneShotSoundAtCoroutine(name, position, delay));
 }
コード例 #18
0
 public static void PlayOneShotSoundAt(SoundNames name, AudioSource audioSource, float delay = 0)
 {
     instance.StartCoroutine(instance.PlayOneShotSoundAtCoroutine(name, audioSource, delay));
 }
コード例 #19
0
    public void StopSound(SoundNames soundName)
    {
        SoundAudioClip chosenSound = GetChosenSoundByName(soundName);

        chosenSound.AudioSource.Stop();
    }