Esempio n. 1
0
    public static bool PlaySound(string se_name, bool se_flag = true)
    {
        if (ResourcesLoader.ContainsKey(se_name) == false)
        {
            return(false);
        }

        if (se_flag)
        {
            if (SoundPlayerObj == null)
            {
                SoundPlayerObj   = new GameObject("SoundPlayer");
                SoundAudioSource = SoundPlayerObj.AddComponent <AudioSource>();
            }
            SoundAudioSource.PlayOneShot(ResourcesLoader.GetObjectHandle(se_name));
        }
        else
        {
            if (BGMPlayerObj == null)
            {
                BGMPlayerObj          = new GameObject("BGMPlayer");
                BGMAudioSource        = BGMPlayerObj.AddComponent <AudioSource>();
                BGMAudioSource.clip   = ResourcesLoader.GetObjectHandle(se_name);
                BGMAudioSource.volume = 1.0f;
                BGMAudioSource.loop   = true;
                BGMAudioSource.Play();
            }
            else
            {
                if (BGMAudioSource)
                {
                    if (BGMAudioSource.isPlaying)
                    {
                        BGMAudioSource.Stop();
                    }
                    else
                    {
                        BGMAudioSource.Play();
                    }
                }
                else
                {
                    BGMAudioSource = BGMPlayerObj.AddComponent <AudioSource>();
                    if (BGMAudioSource)
                    {
                        BGMAudioSource.clip   = ResourcesLoader.GetObjectHandle(se_name);
                        BGMAudioSource.volume = 1.0f;
                        BGMAudioSource.loop   = true;
                        BGMAudioSource.Play();
                    }
                }
            }
        }

        return(true);
    }
Esempio n. 2
0
    //------------------------------------------------------------------------

    /*!
     *          @brief		定期更新処理
     */
    //------------------------------------------------------------------------
    void Update()
    {
        if (!LocalSaveManager.HasInstance)
        {
            return;
        }

        //--------------------------------------------------------------------
        //	Mute設定
        //--------------------------------------------------------------------
        if (mIsMute == false)
        {
            LocalSaveOption cOption = LocalSaveManager.Instance.LoadFuncOption();
            if (cOption != null)
            {
                bool bOptionActiveBGM = (cOption.m_OptionBGM == (int)LocalSaveDefine.OptionBGM.OFF);
                Mute(bOptionActiveBGM);
            }
        }
        else
        {
            Mute(true);
        }

        //--------------------------------------------------------------------
        // 再生リクエスト処理
        //--------------------------------------------------------------------
        BGMPlayData data = null;

        for (int i = 0; i < m_BGMPlayData.Length; i++)
        {
            data = m_BGMPlayData[i];
            if (data == null)
            {
                continue;
            }


            if (data.dataUsing == false)
            {
                continue;
            }


            // 再生クラスの空きを検索
            BGMAudioSource audio = null;
            for (int j = 0; j < m_BGMAudioSource.Length; j++)
            {
                audio = m_BGMAudioSource[j];
                if (audio == null)
                {
                    continue;
                }


                if (audio.playState != BGMPlayState.BGM_STATE_NONE)
                {
                    continue;
                }

                // 再生
                audio.Play(data);
                data.Clear();
                break;
            }
        }


        //--------------------------------------------------------------------
        //	ダッキング処理
        //--------------------------------------------------------------------
        if (mDuckingTime != 0.0f &&
            mDuckingTime > AudioSettings.dspTime)
        {
            if (mDuckingEnable == false)
            {
                StartCoroutine(TransVolume(1.0f, 0.5f, 0.05f, true));
            }
        }
        else
        {
            if (mDuckingEnable == true)
            {
                StartCoroutine(TransVolume(0.5f, 1.0f, 0.6f, false));
            }
        }



        //--------------------------------------------------------------------
        //	再生管理クラス更新
        //--------------------------------------------------------------------
        for (int i = 0; i < m_BGMAudioSource.Length; i++)
        {
            BGMAudioSource audio = m_BGMAudioSource[i];
            if (audio == null)
            {
                continue;
            }


            if (audio.playState != BGMPlayState.BGM_STATE_READY &&
                audio.playState != BGMPlayState.BGM_STATE_PLAYING &&
                audio.playState != BGMPlayState.BGM_STATE_FADEIN &&
                audio.playState != BGMPlayState.BGM_STATE_FADEOUT)
            {
                continue;
            }

            // 再生情報更新
            audio.Update();

            //	ダッキング処理
            audio.duckingScale = mDuckingVolumeScale;
        }
    }