Exemplo n.º 1
0
    // Determines channel and clip to play
    public void PlaySound(AudioChannel audioChannel, string clipName, bool isPlayAfter, string nextClip)
    {
        AudioRef myRef = ParseAudioRef(clipName);

        int channelIndex = (int)audioChannel;

        StopChannel(audioChannel);

        // This will be used later to save volume

        /*if (SaveLoad.main != null)
         * {
         *  audioSources[channelIndex].volume = SaveLoad.main.gameData.masterVolume * myRef.volume;
         * }*/

        audioSources[channelIndex].clip = myRef.clipRef;
        audioSources[channelIndex].loop = myRef.isLooping;

        audioSources[channelIndex].Play();

        if (isPlayAfter == true)
        {
            StartCoroutine(WaitForSound(nextClip));
        }
    }
Exemplo n.º 2
0
    private IEnumerator WaitForSound(string clipname)
    {
        AudioRef myRef = ParseAudioRef(clipname);

        yield return(new WaitForSeconds(myRef.clipRef.length));

        PlaySound(AudioChannel.PLAYER_SOUNDS, clipname, false, null);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Transition audio play. Should be used to play context-sensitive sounds
    /// (such as changing state or vocalizations) that are expected to play once
    /// in their entirety.
    /// </summary>
    /// <param name="refIn">The State associated with the desired clip.</param>
    /// <returns>false if the audio could not be found</returns>
    public bool PlayOneShot(AudioRef refIn)
    {
        if (l_audioDictionary.ContainsKey(refIn))
        {
            return(false);
        }
        AudioClip activeClip;

        l_audioDictionary.TryGetValue(refIn, out activeClip);

        c_audioSource.PlayOneShot(activeClip);

        return(true);
    }
Exemplo n.º 4
0
    /// <summary>
    /// State-based audio play. Should be used for sounds that are associated with
    /// a given state (riding on different types of terrain, etc.) and should cleanly
    /// loop
    /// </summary>
    /// <param name="refIn">The State associated with the desired clip.</param>
    /// <returns>false if the audio could not be found</returns>
    public bool PlayAudio(AudioRef refIn)
    {
        if (l_audioDictionary.ContainsKey(refIn))
        {
            c_audioSource.Stop();
            return(false);
        }
        AudioClip activeClip;

        l_audioDictionary.TryGetValue(refIn, out activeClip);

        c_audioSource.clip = activeClip;
        c_audioSource.Play();

        return(true);
    }
Exemplo n.º 5
0
    public AudioRef GetAudioState()
    {
        AudioRef foundClip = AudioRef.ERROR_CLIP;

        StateRef airState    = c_airMachine.GetCurrentState();
        StateRef rideState   = c_accelMachine.GetCurrentState();
        StateRef turnState   = c_turnMachine.GetCurrentState();
        StateRef groundState = StateRef.TERR_SNOW; // currently always snow

        // obey the order of the tree: air, ground, turn, terre
        AudioDTree currentBranch = t_audioStateTree.GetChild(airState);

        currentBranch = currentBranch.GetChild(rideState);
        currentBranch = currentBranch.GetChild(turnState);
        currentBranch = currentBranch.GetChild(groundState);

        foundClip = currentBranch.GetLeaf();

        return(foundClip);
    }
Exemplo n.º 6
0
    // Returns a AudioRef to use based on the string
    public AudioRef ParseAudioRef(string name)
    {
        AudioRef foundRef = null;

        foreach (AudioRef audioRef in audioReferences)
        {
            if (audioRef.name == name)
            {
                foundRef = audioRef;
                break;
            }
        }

        // In case miss spelling of audio clip
        if (foundRef == null)
        {
            Debug.LogError("<b>" + name + "</b> audio effect not found!");
        }

        return(foundRef);
    }
Exemplo n.º 7
0
 // leaf constructor
 public AudioDTree(StateRef stateIn, AudioRef audioIn)
 {
     this.s_heldState = stateIn;
     this.a_clipOut   = audioIn;
 }
Exemplo n.º 8
0
 // non-leaf branch constructor
 public AudioDTree(StateRef stateIn)
 {
     this.s_heldState = stateIn;
     this.a_clipOut   = AudioRef.ERROR_CLIP;
     this.l_children  = new List <StateDTree>();
 }
Exemplo n.º 9
0
 public Message(AudioRef dataIn)
 {
     a_data = dataIn;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Updates the audio controller with the current state, playing the associated sounds
 /// </summary>
 private void UpdateAudio()
 {
     AudioRef audio = GetAudioState();
     //c_audioController.PlayAudio(GetAudioState());
 }