Example #1
0
 /// <summary>
 /// 播放指定背景音乐
 /// </summary>
 /// <param name="bgm">指定背景音乐</param>
 /// <param name="loop">是否循环</param>
 public void PlayBgm(BgmType bgm, bool loop)
 {
     if (OnPlayBgm != null)
     {
         OnPlayBgm(bgm, loop);
     }
 }
Example #2
0
 public void Play(BgmType type, bool loop = true)
 {
     bgmSource.Stop();
     bgmSource.volume = SoundManager.Instance.BgmVolume;
     bgmSource.clip   = bgmClips[type];
     bgmSource.Play();
 }
Example #3
0
        /// <summary>
        /// 指定のBGMを再生します。
        /// </summary>
        /// <param name="bgm">再生したいBGM</param>
        /// <param name="isFadeIn">フェードインさせたい時trueを設定。デフォルトはfalse。</param>
        public static void PlayBGM(BgmType bgm, bool isFadeIn = false)
        {
            useFade      = isFadeIn;
            isFadingOut  = false;
            useFadeAlpha = true;

            // 同じ曲が設定されていて再生中ならなにもしない
            if (Instance.audioBGM.clip == Instance.bgmList[(int)bgm])
            {
                if (Instance.audioBGM.isPlaying)
                {
                    SetVolume();
                    return;
                }
            }
            else
            {
                // 違う曲の場合
                // 曲が設定されていたら、曲を停止
                if (Instance.audioBGM.clip != null)
                {
                    Instance.audioBGM.Stop();
                }

                // 曲を設定
                Instance.audioBGM.clip = Instance.bgmList[(int)bgm];
            }

            // 再生開始
            SetVolume();
            Instance.audioBGM.Play();
        }
Example #4
0
 public void SetGameplayAudio()
 {
     Init();
     BgmSource.clip = BattleTheme1;
     BgmSource.Play();
     BgmSource.loop   = true;
     BgmSource.time   = 0f;
     BgmSource.volume = 1f;
     m_currentBgmType = BgmType.Battle;
 }
        // BGMファイルパス取得
        public static string GetBgmFilePath(BgmType type)
        {
            var filePath = "Sounds/";

            switch (type)
            {
            case BgmType.None: break;
            }

            return(filePath);
        }
Example #6
0
    static void Init()
    {
        GameObject obj = new GameObject("SoundManager");

        obj.AddComponent <SoundManager>();
        DontDestroyOnLoad(obj);

        GameObject bgmObj = new GameObject("BGM");

        bgmSource             = bgmObj.AddComponent <AudioSource>();
        bgmSource.playOnAwake = false;
        bgmSource.loop        = true;
        bgmSource.volume      = PlayerPrefs.GetFloat("BGMVolume", 1);
        bgmObj.transform.SetParent(obj.transform);

        GameObject sfxObj = new GameObject("SFX");

        sfxSource             = sfxObj.AddComponent <AudioSource>();
        sfxSource.playOnAwake = false;
        sfxSource.volume      = PlayerPrefs.GetFloat("SFXVolume", 1);
        sfxObj.transform.SetParent(obj.transform);

        // Resource 하위의 Sound들 저장
        AudioClip[] bgmClips = Resources.LoadAll <AudioClip>("Sounds/BGM");
        for (int i = 0; i < bgmClips.Length; i++)
        {
            try
            {
                BgmType bgmType = (BgmType)Enum.Parse(typeof(BgmType), bgmClips[i].name);
                bgmClipDic.Add(bgmType, bgmClips[i]);
            }
            catch
            {
                Debug.LogError("Need BgmType enum :" + bgmClips[i].name);
            }
        }

        AudioClip[] sfxClips = Resources.LoadAll <AudioClip>("Sounds/SFX");
        for (int i = 0; i < sfxClips.Length; i++)
        {
            try
            {
                SfxType sfxType = (SfxType)Enum.Parse(typeof(SfxType), sfxClips[i].name);
                sfxClipDic.Add(sfxType, sfxClips[i]);
            }
            catch
            {
                Debug.LogError("Need SfxType enum :" + sfxClips[i].name);
            }
        }

        SceneManager.sceneLoaded += OnSceneLoadComplete;
    }
Example #7
0
        /// <summary>
        /// 播放指定背景音乐
        /// </summary>
        /// <param name="bgm">指定背景音乐</param>
        /// <param name="loop">是否循环</param>
        public void PlayBgm(BgmType bgm, bool loop)
        {
            if (debugEnable)
            {
                Debug.Log("BgAudioManageSystem.PlayBgm");
            }

            if (OnPlayBgm != null)
            {
                OnPlayBgm(bgm, loop);
            }
        }
Example #8
0
        public void Play(BgmType bgmType, bool isLoop = true)
        {
            var clip = _bgmUseCase.GetBgmClip(bgmType);

            if (clip == null || audioSource.clip == clip)
            {
                return;
            }

            audioSource.clip = clip;
            audioSource.loop = isLoop;
            audioSource.Play();
        }
Example #9
0
        public void PlayBgm(BgmType bgmType)
        {
            if (_bgmList.TryGetValue((int)bgmType, out var clip))
            {
                if (audioSource.clip == clip)
                {
                    return;
                }

                audioSource.clip = clip;
                audioSource.Play();
            }
        }
Example #10
0
    /// <summary>
    /// 指定した種類のBGMを再生
    /// </summary>
    /// <param name="bgmType"></param>
    public void PlayBGM(BgmType bgmType)
    {
        // BGM停止
        audioSource.Stop();

        // 再生するBGMを設定する
        audioSource.clip = bgms[(int)bgmType];

        // BGM再生
        audioSource.Play();

        Debug.Log("再生中のBGM : " + bgmType);
    }
Example #11
0
 public void SetMenuAudio()
 {
     Init();
     if (m_currentBgmType == BgmType.Menu)
     {
         return;
     }
     BgmSource.clip = MenuTheme1;
     BgmSource.Play();
     BgmSource.loop   = true;
     BgmSource.time   = 2f;
     BgmSource.volume = 0.4f;
     m_currentBgmType = BgmType.Menu;
 }
Example #12
0
    public void Initialize()
    {
        if (Initialized == true)
        {
            return;
        }

        Initialized = true;

        for (int i = (int)BgmType.Undefined + 1; i < (int)BgmType.End_Of_Bgm; ++i)
        {
            BgmType type = (BgmType)i;
            bgmClips.Add(type, Resources.Load <AudioClip>("Sounds/Bgm/" + type.ToString()));
        }
    }
Example #13
0
    /// <summary>
    /// BGMの再生
    /// </summary>
    /// <param name="type">再生するBGMの種類</param>
    public void PlayBgm(BgmType type)
    {
        // BGMが既に再生中(フラグが立っていれば)であれば停止する
        if (isPlayingBgm)
        {
            // 全てBGMに対してSetActiveを行いBGMを停止させる
            GeneralFuncion.SetActiveFromAllChild(parentBgm, false);
            // フラグを倒す
            isPlayingBgm = false;
        }

        // 指定のBGMを再生する
        parentBgm.GetChild((int)type).gameObject.SetActive(true);
        // フラグを起こす
        isPlayingBgm = true;
    }
Example #14
0
    public static void PlayBGM(BgmType type, float fadeTime = 0)
    {
        if (bgmSource.clip != null)
        {
            if (bgmSource.clip.name == type.ToString())
            {
                return;
            }

            if (fadeTime > 0)
            {
                bgmSource.DOFade(0, fadeTime).OnComplete(() =>
                {
                    bgmSource.clip = bgmClipDic[type];
                    bgmSource.Play();
                    bgmSource.DOFade(PlayerPrefs.GetFloat("BGMVolume", 1), fadeTime);
                });
            }
            else
            {
                bgmSource.clip = bgmClipDic[type];
                bgmSource.Play();
            }
        }
        else
        {
            bgmSource.clip = bgmClipDic[type];

            if (fadeTime > 0)
            {
                bgmSource.volume = 0;
                bgmSource.DOFade(PlayerPrefs.GetFloat("BGMVolume", 1), fadeTime);
            }
            else
            {
                bgmSource.volume = PlayerPrefs.GetFloat("BGMVolume", 1);
            }
            bgmSource.Play();
        }
    }
Example #15
0
 public AudioClip FindBgm(BgmType bgmType)
 {
     return(_bgmTable.bgmData
            .Find(x => x.bgmType == bgmType)
            .audioClip);
 }
Example #16
0
 /// <summary>
 /// 指定のBGMが再生中か判定する
 /// </summary>
 /// <param name="type">判定するBGMの種類</param>
 /// <returns></returns>
 public bool IsPlayingBgm(BgmType type)
 {
     // BGMのオブジェクトがアクティブであれば再生中
     return(parentBgm.GetChild((int)type).gameObject.activeSelf);
 }
Example #17
0
 public void PlayBgm(BgmType bgmType)
 {
     PlayBgm((long)bgmType);
 }
Example #18
0
 public AudioClip GetBgmClip(BgmType bgmType) => _soundRepository.FindBgm(bgmType);