2016-01-22 79 views
0

當音頻播放時,系統應該忽略其他所有內容,直到音頻結束,但是當音頻完成並且音頻結束時存在目標時,它需要調用OnTrackingFound()函數。 如果我等待音頻完成,然後向相機顯示目標,它可以正常工作(它稱爲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
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 
} 
+0

意外符號'IEnumerator的」類,結構或接口成員聲明 它不工作 – Butrint

+0

有一個;在IEnumerator之前。 – Everts

相關問題