// 添加背景音乐播放
    public override void play(System.String clipName, callback method = null)
    {
        if (audioPlayers.Count <= 0 || clips.Count <= 0)
        {
            return;
        }
        float       maxTime = -1;
        AudioSource player  = _atom;

        switch (clipName)
        {
        case "":
            player.clip = null;
            return;
        }

        AudioPlayObj obj = new AudioPlayObj(selectClip(clipName), this, player, maxTime);

        AudioPlayCtrl.getInstance().addBackgroundObj(obj);

        if (method != null)
        {
            AudioPlayCtrl.getInstance().addCallbackToBackgroundClip(clipName, method);
        }
    }
示例#2
0
    // 因为音频播放是异步的,方便及时增加播放后的回调内容
    public void addCallbackToEffectClip(System.String clipName = "", callback method = null)
    {
        if (method == null)
        {
            ProjectUtils.Warn("addCallbackToEffectClip Lost method");
            return;
        }
        ;

        // 适配,当 audio 刚刚加入队列时, _effectClipObj 并未被赋值
        if (!clipName.Trim().Equals(""))
        {
            // 避免同名对象进入而使得 callback 没有成功绑定
            for (int i = _effectClipPlayList.Count - 1; i >= 0; i--)
            {
                AudioPlayObj obj = _effectClipPlayList[i];

                if (obj.clip.name == clipName)
                {
                    obj.handle += method;
                    return;
                }
            }
        }
    }
示例#3
0
    public override void play(String clipName, callback method = null)
    {
        if (audioPlayers.Count <= 0 || clips.Count <= 0)
        {
            return;
        }
        float       maxTime = -1;
        AudioSource player  = _center;

        // specific clip data. switch 的传入判断值必须在运行时就已经是既定值,即 const 不能作为判断对象。
        switch (clipName)
        {
        case PlayerAudioData.SWITCH_OBSTACLE_CLIP:
            player = _switch;
            break;

        default: break;
        }

        AudioPlayObj obj = new AudioPlayObj(selectClip(clipName), this, player, maxTime);

        AudioPlayCtrl.getInstance().addEffectObj(obj);
        if (method != null)
        {
            AudioPlayCtrl.getInstance().addCallbackToEffectClip(clipName, method);
        }
    }
示例#4
0
    // 这个功能是有可复用性的,只是针对 playeAudioCtrl 并不有效
    public virtual void play(String clipName, callback method = null)
    {
        if (audioPlayers.Count > 0 && clips.Count > 0)
        {
            AudioPlayObj obj = new AudioPlayObj(selectClip(clipName), this, audioPlayers[0], 3.5f);
            AudioPlayCtrl.getInstance().addEffectObj(obj);

            if (method != null)
            {
                AudioPlayCtrl.getInstance().addCallbackToEffectClip(clipName, method);
            }
        }
    }
示例#5
0
    // 值传递对象
    private void autoPlay(ref List <AudioPlayObj> clipList, ref AudioPlayObj clipObj)
    {
        if (clipList.Count <= 0)
        {
            return;
        }

        if (removeCurObj(ref clipList, ref clipObj))
        {
            clipObj             = clipList[0];
            clipObj.player.clip = clipObj.clip;
            clipObj.player.time = 0;
            clipObj.player.Play();
            Debug.Log("clipObj MaxTime: " + clipObj.maxTime);
        }
    }
    public override void play(System.String clipName, callback method = null)
    {
        if (clips.Count <= 0)
        {
            return;
        }
        float       maxTime = -1;
        AudioSource player  = manager;

        AudioPlayObj obj = new AudioPlayObj(selectClip(clipName), this, player, maxTime);

        AudioPlayCtrl.getInstance().addEffectObj(obj);

        if (method != null)
        {
            AudioPlayCtrl.getInstance().addCallbackToEffectClip(clipName, method);
        }
    }
示例#7
0
    // 停止播放
    public void stopEffect()
    {
        if (_effectClipObj == null)
        {
            return;
        }
        // To Stop current Playing
        if (_effectClipObj.player.isPlaying)
        {
            _effectClipObj.player.Stop();

            if (_effectClipObj.handle != null)
            {
                _effectClipObj.handle();
            }

            _effectClipPlayList.RemoveAt(0);
            _effectClipObj = null;
        }
    }
示例#8
0
    private bool removeCurObj(ref List <AudioPlayObj> clipList, ref AudioPlayObj clipObj)
    {
        if (clipObj == null)
        {
            return(true);
        }

        // 判断当前播放时间是否超过规定时间
        clipObj.maxTime -= Time.deltaTime;

        if (clipObj.maxTime <= 0)
        {
            Debug.Log("RemoveCur Obj Name: " + clipObj.clip.name);
            clipObj.player.Stop();
            clipList.RemoveAt(0);
            clipObj.handle();
            clipObj = null;
        }

        return(false);
    }
示例#9
0
    // background 控制对象添加 callback
    public void addCallbackToBackgroundClip(System.String clipName = "", callback method = null)
    {
        if (method == null)
        {
            ProjectUtils.Warn("addCallbackToBackgroundClip Lost method");
            return;
        }
        ;

        if (!clipName.Trim().Equals(""))
        {
            for (int i = _backgroundClipPlayList.Count - 1; i >= 0; i--)
            {
                AudioPlayObj obj = _backgroundClipPlayList[i];

                if (obj.clip.name == clipName)
                {
                    obj.handle += method;
                    return;
                }
            }
        }
    }
示例#10
0
    public void playAudio(ArrowDir dir)
    {
        String name = selectedDir(dir);

        System.String clipName = "";
        AudioPlayObj  obj      = null;

        if (dir == ArrowDir.FRONT)
        {
            clipName = "frontSword";
            obj      = new AudioPlayObj(selectClip(clipName), this, selectSource(name));
        }
        else
        {
            clipName = "bow";
            obj      = new AudioPlayObj(selectClip(clipName), this, selectSource(name));
        }

        AudioPlayCtrl.getInstance().addEffectObj(obj);

        // 教学音频设计需要
        if (GameManagerGlobalData.isFirstMeetObstacle)
        {
            PlayerAudioCtrl.getInstance().play(PlayerAudioData.PARRY_TO_FRONT_TIPS, () => {
                Parry.getInstance().setParry(true);
                GameManagerGlobalData.isFirstMeetObstacle = false;
            });
        }
        else if (GameManagerGlobalData.isSecondMeetObstacle)
        {
            PlayerAudioCtrl.getInstance().play(PlayerAudioData.PARRY_TO_LEFT_TIPS, () => {
                Parry.getInstance().setParry(true);
                GameManagerGlobalData.isSecondMeetObstacle = false;
            });
        }
    }
示例#11
0
 public void addBackgroundObj(AudioPlayObj clipObj)
 {
     _backgroundClipPlayList.Add(clipObj);
 }
示例#12
0
 // 添加需要播放的音效当队列中
 public void addEffectObj(AudioPlayObj clipObj)
 {
     _effectClipPlayList.Add(clipObj);
 }