Exemple #1
0
 public void PlaySound(AudioSoundType soundType, string pageName = "Common", bool isLoop = false)
 {
     _soundSource.clip = GetAudioByType(soundType, pageName);
     _soundSource.loop = isLoop;
     _soundSource.Play();
     //return _soundSource;
 }
Exemple #2
0
    /// <summary>
    /// 在指定物体上播放音效
    /// </summary>
    /// <param name="soundType"></param>
    /// <param name="pageName"></param>
    /// <param name="isLoop"></param>
    /// <param name="pitch">加速倍数</param>
    /// <param name="playTime">循环播放时播放的时长,isLoop为true时有效</param>
    public AudioSource PlayTempSound(AudioSoundType soundType, string pageName = null, bool isLoop = false, float pitch = 1, float playTime = 0)
    {
        if (string.IsNullOrEmpty(pageName))
        {
            pageName = PageManager.Instance.CurrentPage.GetType().ToString();
        }
        AudioSource ase;

        if (sound_clipDict.ContainsKey(soundType))
        {
            ase = tempAudioParent.Find(soundType.ToString()).GetComponent <AudioSource>();
        }
        else
        {
            ase = CreateSoundSource(soundType);
        }
        ase.clip   = GetAudioByType(soundType, pageName);
        ase.loop   = isLoop;
        ase.pitch  = pitch;
        ase.volume = _sound;
        ase.mute   = _soundSource.mute;
        ase.Play();
        if (isLoop && playTime != 0)
        {
            StartCoroutine(DelayStop(ase, playTime));
        }
        return(ase);
    }
 public AudioSource PlaySound(AudioSoundType soundType, string pageName = null, bool isLoop = false)
 {
     _soundSource.clip = GetAudioByType(soundType, pageName);
     _soundSource.loop = isLoop;
     _soundSource.Play();
     return(_soundSource);
 }
Exemple #4
0
    public void StopTargetTempSound(AudioSoundType soundType)
    {
        Transform tf = tempAudioParent.Find(soundType.ToString());

        if (tf)
        {
            AudioSource ase = tf.GetComponent <AudioSource>();
            ase.Stop();
        }
    }
Exemple #5
0
    /// <summary>
    /// 创建一个音效源
    /// </summary>
    /// <param name="soundType">音效类型</param>
    /// <returns></returns>
    AudioSource CreateSoundSource(AudioSoundType soundType)
    {
        GameObject go = new GameObject(soundType.ToString());

        go.transform.SetParent(tempAudioParent);
        AudioSource ase = go.AddComponent <AudioSource>();

        ase.playOnAwake = false;
        return(ase);
    }
    public static UGUIEventListenerContainDrag Get(GameObject go, AudioSoundType clickAudio = AudioSoundType.BtnClick)
    {
        UGUIEventListenerContainDrag listener = go.GetComponent <UGUIEventListenerContainDrag>();

        if (listener == null)
        {
            listener = go.AddComponent <UGUIEventListenerContainDrag>();
        }
        listener.m_AudioType = clickAudio;
        return(listener);
    }
Exemple #7
0
    AudioClip GetAudioByType(AudioSoundType soundType, string pageName)
    {
        AudioClip ac = null;

        if (sound_clipDict.ContainsKey(soundType))
        {
            ac = sound_clipDict[soundType];
        }
        else
        {
            ac = BundleManager.Instance.GetAudioClip(soundType.ToString(), "Sound", pageName);
            sound_clipDict.Add(soundType, ac);
        }
        return(ac);
    }
    /// <summary>
    /// 在指定物体上播放音效
    /// </summary>
    /// <param name="soundType"></param>
    /// <param name="pageName"></param>
    /// <param name="ob"></param>
    /// <param name="isLoop"></param>
    public AudioSource PlayTempSound(AudioSoundType soundType, string pageName = null, bool isLoop = false)
    {
        AudioSource ase;

        if (sound_clipDict.ContainsKey(soundType))
        {
            ase = tempAudioParent.Find(soundType.ToString()).GetComponent <AudioSource>();
        }
        else
        {
            ase = CreateSoundSource(soundType);
        }
        ase.clip   = GetAudioByType(soundType, pageName);
        ase.loop   = isLoop;
        ase.volume = _sound;
        ase.mute   = _soundSource.mute;
        ase.Play();
        return(ase);
    }
    AudioClip GetAudioByType(AudioSoundType soundType, string pageName)
    {
        AudioClip ac = null;

        if (sound_clipDict.ContainsKey(soundType))
        {
            ac = sound_clipDict[soundType];
        }
        else
        {
            AssetBundle ab = BundleManager.Instance.GetBundle((string.IsNullOrEmpty(pageName) ? "" : pageName.ToLower() + "/") + "sound/sound/" + soundType.ToString());
            if (ab != null)
            {
                ac = ab.LoadAsset <AudioClip>(soundType.ToString().ToLower());
                ab.Unload(false);
            }
            else
            {
                ac = Resources.Load <AudioClip>("Sound/Sound/" + soundType.ToString());
            }
            sound_clipDict.Add(soundType, ac);
        }
        return(ac);
    }