| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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();
- }
- }
|