Exemple #1
0
    /// <summary>
    /// 通过音频文件名称获取音频资源.
    /// </summary>
    public AudioClip GetAudioClipByName(ClipName clipName)
    {
        AudioClip temp = null;

        audioClipsDic.TryGetValue(clipName.ToString(), out temp);
        return(temp);
    }
Exemple #2
0
    /// <summary>
    ///  通过名称获取音频资源
    /// </summary>
    public AudioClip GetAudioClipByName(ClipName name)
    {
        AudioClip res = null;

        audioDic.TryGetValue(name.ToString(), out res);
        return(res);
    }
Exemple #3
0
    public AudioClip GetAudioClipByName(ClipName name)
    {
        AudioClip au = null;

        audioClipsDic.TryGetValue(name.ToString(), out au);
        return(au);
    }
    /// <summary>
    /// 通过添加组件的方式来播放声音
    /// </summary>
    /// <param name="go">要将AudioSource添加到的物体</param>
    /// <param name="audioType">声音的类型</param>
    /// <param name="isPlayOnWake">是否一开始就播放</param>
    /// <param name="isLoop">是否循环</param>
    public AudioSource PlayAudioClipByComponent(GameObject go, ClipName audioType, bool isPlayOnWake = true, bool isLoop = true)
    {
        AudioSource tempAudioSource = go.AddComponent <AudioSource>();

        tempAudioSource.clip        = GetClipAudioByName(audioType.ToString());
        tempAudioSource.playOnAwake = isPlayOnWake;
        //一开始就播放(因为虽然设置了但是需要我们手动播放一下)
        if (isPlayOnWake)
        {
            tempAudioSource.Play();
        }
        tempAudioSource.loop = isLoop;
        return(tempAudioSource);
    }
Exemple #5
0
    public void Play(ClipName p_name, Action p_completeCallBack = null)
    {
        switch (p_name)
        {
        case ClipName.Stand:
        case ClipName.Run:
        {
            if (!CurrentAnimation.IsPlaying(p_name.ToString()))
            {
                CurrentAnimation.Play(p_name.ToString(), PlayMode.StopAll);
            }
            break;
        }

        case ClipName.Attack:
        {
            CurrentAnimation.Play(p_name.ToString(), PlayMode.StopAll);
            if (p_completeCallBack != null)
            {
                StartCoroutine(AnimCompleteCallBack(CurrentAnimation.GetClip(p_name.ToString()).length,
                                                    p_completeCallBack));
            }
            CurrentAnimation.PlayQueued(ClipName.Stand.ToString(), QueueMode.CompleteOthers, PlayMode.StopAll);
            break;
        }

        case ClipName.Die:
        {
            CurrentAnimation.Play(p_name.ToString(), PlayMode.StopAll);
            if (p_completeCallBack != null)
            {
                StartCoroutine(AnimCompleteCallBack(CurrentAnimation.GetClip(p_name.ToString()).length,
                                                    p_completeCallBack));
            }
            break;
        }
        }
    }
 /// <summary>
 /// 通过PlayClipAtPoint来播放一个声音
 /// </summary>
 /// <param name="audioType">声音的枚举</param>
 /// <param name="pos">声音播放的位置</param>
 public void PlayAudioClipByName(ClipName audioType, Vector3 pos)
 {
     AudioSource.PlayClipAtPoint(GetClipAudioByName(audioType.ToString()), pos);
 }