コード例 #1
0
    /// <summary>
    /// Adds an Audio Source to the list managed by AudioManager.
    /// </summary>
    /// <param name="aObject"></param>
    public void addAudioSource(CGameObject aObject)
    {
        CAudioSource source = new CAudioSource(aObject);

        source.setAs3DSource();
        addAudioSource(aObject, source);
    }
コード例 #2
0
    /// <summary>
    /// Adds an Audio Source to the list managed by AudioManager.
    /// </summary>
    /// <param name="aObject"></param>
    public CAudioSource addAudioSource(CGameObject aObject)
    {
        CAudioSource source = new CAudioSource(aObject);

        source.setAs3DSource();
        addAudioSource(aObject, source);

        return(source);
    }
コード例 #3
0
    /// <summary>
    /// Sets the Cameras Audio Listener and Audio Sources for Music and SFX.
    /// </summary>
    /// <param name="aObject"></param>
    public void setAudioListener(CGameObject aObject)
    {
        if (mAudioListener == null)
        {
            mAudioListener = new CAudioListener(aObject);
        }

        mListenerSourceFX = new CAudioSource(aObject);
        mListenerSourceFX.setAs2DSource();

        mListenerSourceMusic = new CAudioSource(aObject);
        mListenerSourceMusic.setAs2DSource();
        mListenerSourceMusic.component.loop = true;
    }
コード例 #4
0
    public void Awake()
    {
        if (_inst != null && _inst != this)
        {
            Destroy(this.gameObject);
            return;
        }

        _inst = this;
        //_sfxKeys = new List<string>();

        //Setup music.
        _music = new CAudioSource("music", _volumeMusic, gameObject);
        //_sfx = new CAudioSource(_volumeSfx, gameObject);
    }
コード例 #5
0
    private void createSfx(string aId, AudioClip aSfx, float aVolume = 1)
    {
        string id = aId;
        int    i  = 0;

        while (isSfxPlaying(id))
        {
            i += 1;
            id = aId + i.ToString();
        }

        CAudioSource source = new CAudioSource(id, aVolume, gameObject);

        source.playAudio(aSfx, false);
        _sfxs.Add(source);
    }
コード例 #6
0
    public void Update()
    {
        for (int i = _sfxs.Count - 1; i >= 0; i--)
        {
            CAudioSource source = _sfxs[i];

            if (source.finishedPlaying())
            {
                source.destroy();
                _sfxs.Remove(source);
            }
        }

        if (_music.isPlaying() && _music.finishedPlaying())
        {
            //_music.
            Debug.Log("music ended!");
        }
    }
コード例 #7
0
    /// <summary>
    /// Used for 3D sounds. Plays a random sound at a desired Objects location.
    /// Example, PlayRandomRange(object, "foot_pasto_", 0, 11);
    /// Assumes files to be named: sound_name_number
    /// </summary>
    /// <param name="aObject">Object to play at</param>
    /// <param name="aSoundName">Prefix of sound name</param>
    /// <param name="aStart">First file starting number</param>
    /// <param name="aEnd">Last file starting number</param>
    public void playRandomRangeAt(CGameObject aObject, string aSoundName, int aStart, int aEnd)
    {
        mTestTimer += Time.deltaTime;
        //@Fernando: Added null check in case the audiosource wasn't registered. -Mauri
        CAudioSource csource = getAudioSource(aObject);

        if (csource == null)
        {
            return;
        }
        AudioSource source = csource.component;
        AudioClip   clip   = getAudioClip(aSoundName + CMath.randomIntBetween(aStart, aEnd));

        if (mTestTimer + CMath.randomFloatBetween(-0.1f, 0.1f) > 0.3f)
        {
            // Apply random volume.
            float vol = CMath.randomFloatBetween(0.7f, 1.0f);
            // Apply random pitch.
            source.pitch = CMath.randomFloatBetween(0.75f, 1.25f);

            source.PlayOneShot(clip, vol);
            mTestTimer = 0.0f;
        }
    }
コード例 #8
0
 private void addAudioSource(CGameObject aKey, CAudioSource aProduct)
 {
     mAudioSources.Add(aKey, aProduct);
 }