当播放音频时,系统应该忽略其他所有内容,直到音频结束,但是当音频结束并且音频完成时你有一个目标,它需要调用OnTrackingFound()函数。 如果我等待音频完成然后向相机显示目标,它工作正常(它调用OnTrackingFound),但是当我在播放音频时显示目标时它将忽略目标(这是可以的),但是当音频完成并且目标存在而不等待音频完成时,它不应该忽略它。
public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus,TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) {
if (notCorrect.isPlaying || correct.isPlaying || FindTheCard.isPlaying || Quiz.currentPoint.GetComponent<AudioSource>().isPlaying || tryagain.isPlaying || GameObject.Find ("LetsTryNumbers").GetComponent<AudioSource> ().isPlaying || GameObject.Find ("LetsTryLetters").GetComponent<AudioSource> ().isPlaying || GameObject.Find ("LetsTryAnother").GetComponent<AudioSource> ().isPlaying || GameObject.Find ("Correct").GetComponent<AudioSource> ().isPlaying || GameObject.Find ("CorrectAnimals").GetComponent<AudioSource> ().isPlaying || GameObject.Find ("CorrectLetters").GetComponent<AudioSource> ().isPlaying || GameObject.Find ("LetsTryAnotherModel").GetComponent<AudioSource> ().isPlaying)
{
OnTrackingLost();
}
else
{
OnTrackingFound ();
}
}
}
答案 0 :(得分:0)
public AudioSource audio;
public event Action<bool> OnPlayDone = ()=>{};
IEnumerator PlayAndWaitForAudio()
{
// Set all things off
OnPlayDone(false);
this.audio.Play(); // Considering the clip is loaded already
while(this.audio.isPlaying == true){
yield return null;
}
// Set all things on
OnPlayDone(true);
}
应该对等待作出反应的任何组件都会注册该事件。然后你可以相应地设置:
void Start(){
GetComponent<AudioController>().OnPlayDone += HandlerAudio;
}
private bool isAudioDone = false;
private void HandlerAudio(bool value){
this.isAudioDone = value;
}
public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus,TrackableBehaviour.Status newStatus)
{
if(this.isAudioDone == false){ return; }
// Rest of the method
}