// 添加背景音乐播放 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); } }
// 因为音频播放是异步的,方便及时增加播放后的回调内容 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; } } } }
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); } }
// 这个功能是有可复用性的,只是针对 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); } } }
// 值传递对象 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); } }
// 停止播放 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; } }
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); }
// 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; } } } }
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; }); } }
public void addBackgroundObj(AudioPlayObj clipObj) { _backgroundClipPlayList.Add(clipObj); }
// 添加需要播放的音效当队列中 public void addEffectObj(AudioPlayObj clipObj) { _effectClipPlayList.Add(clipObj); }