Esempio n. 1
0
 public void SoundEffectPlay(AudioClip clip, SoundEffectKind kind)
 {
     if (seSorce == null)
     {
         seSorce = GetComponent <AudioSource>();
     }
     seSorce.clip = clip;
     seSorce.Play();
     effectKind = kind;
 }
    public void SoundEffectStopDetection(SoundEffectKind kind)
    {
        switch (kind)
        {
        case SoundEffectKind.Walk:
            isWalkPlaying = false;
            break;

        case SoundEffectKind.HeartBeat:
            isHeartBeatPlaying = false;
            break;
        }
    }
Esempio n. 3
0
    private void Update()
    {
        if (seSorce.clip == null)
        {
            return;
        }
        if (seSorce.isPlaying != false)
        {
            return;
        }

        SEmanager.Instance.SoundEffectStopDetection(effectKind);
        seSorce.clip = null;
        effectKind   = SoundEffectKind.None;
        this.gameObject.SetActive(false);
    }
    /// <summary>
    /// 効果音に共通するコードのまとめ
    /// </summary>
    /// <param name="pos"></param>
    /// <param name="clip"></param>
    private void MusicSetObject(Vector3 pos, AudioClip clip, SoundEffectKind kind)
    {
        GameObject obj = pool.GetObject();

        obj.transform.position = pos;
        switch (kind)
        {
        case SoundEffectKind.MusicBox:
            musicBoxSe = obj;
            break;

        case SoundEffectKind.CountDown:
            coundown = obj;
            break;
        }
        obj.GetComponent <SEObject>().SoundEffectPlay(clip, kind);
    }
Esempio n. 5
0
        /// <summary>
        /// 指定した効果音を鳴らす
        /// </summary>
        /// <param name="kind">効果音の種類</param>
        public static void PlayEffect(SoundEffectKind kind)
        {
            // デバッグ時は再生しない
            if (!IsPlaySound)
            {
                return;
            }

            // Dispose用変数に格納されたAudioPlayerが終了点まで再生されていればDisposeして変数から解放する
            {
                List<IAudioPlayer> disposePlayers = new List<IAudioPlayer>();
                foreach (IAudioPlayer player in m_EffectPlayers)
                {
                    if (player.PlayedToEnd())
                    {
                        player.Stop();
                        player.Dispose();
                        disposePlayers.Add(player);
                    }
                }
                foreach (IAudioPlayer disposePlayer in disposePlayers)
                {
                    m_EffectPlayers.Remove(disposePlayer);
                }
            }

            // ファイルパスの取得
            string exePath = Environment.GetCommandLineArgs()[0];
            string exeFullPath = System.IO.Path.GetFullPath(exePath);
            string startupPath = System.IO.Path.GetDirectoryName(exeFullPath);
            string filePath = startupPath + @"\Sounds\Effects\" + StringEnumAttribute.GetStringValue(kind);

            // オブジェクトの作成
            IAudioPlayer audioPlayer;
            try
            {
                audioPlayer = new AudioPlayer(filePath);
            }
            catch (Exception)
            {
                return;
            }

            // 音量調整があれば音量を変更
            float volume = EffectVolume;
            double volumeOffset = DoubleEnumAttribute.GetDoublegValue(kind);
            if (Math.Abs(volumeOffset - DoubleEnumAttribute.NoDataValue) > 0.1)
            {
                volume *= (float)volumeOffset;
            }
            audioPlayer.Volume = volume;

            // Dispose用変数に登録してから再生
            m_EffectPlayers.Add(audioPlayer);
            audioPlayer.PlayFromStart();
        }