|
|
@@ -0,0 +1,53 @@
|
|
|
+using ChivaXR;
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+public class AniDriver_PlayAudioClip : AnimationDriverBase
|
|
|
+{
|
|
|
+ public AudioClip m_AudioClip;
|
|
|
+
|
|
|
+ public override void FinishedState()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void InitState()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void StartPlay(Action finishedCallBack = null)
|
|
|
+ {
|
|
|
+ if (m_AudioClip == null)
|
|
|
+ {
|
|
|
+ finishedCallBack();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ StartAniCoroutine(WaitAudioClipLength(finishedCallBack));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ IEnumerator WaitAudioClipLength(Action finishedCallBack = null)
|
|
|
+ {
|
|
|
+ GameObject tmpObj = new GameObject();
|
|
|
+
|
|
|
+ AudioSource tmpAudioSource = tmpObj.AddComponent<AudioSource>();
|
|
|
+
|
|
|
+ tmpAudioSource.playOnAwake = false;
|
|
|
+
|
|
|
+ tmpAudioSource.clip = m_AudioClip;
|
|
|
+
|
|
|
+ tmpAudioSource.Play();
|
|
|
+
|
|
|
+ yield return new WaitForSeconds(m_AudioClip.length);
|
|
|
+
|
|
|
+ tmpAudioSource.Stop();
|
|
|
+
|
|
|
+ finishedCallBack?.Invoke();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|