void RefreshProperties() { recorder = (VORecorder)target; isPrefab = CheckIsPrefab(recorder.gameObject); source = recorder.GetComponent <AudioSource>(); recorder.clipLength = Mathf.FloorToInt(source.clip.length * 1000); frames = recorder.frames; }
public static async void PlayVOSound(Sounds sound, Action <VOPositions> onMouthChange = null, Action onComplete = null) { SoundClip soundClip = GetSoundClipForSound(sound); if (soundClip == null) { return; } VORecorder recorder = soundClip.GetComponent <VORecorder>(); try { if (recorder != null) { List <VORecorderFrame> list = recorder.frames; Queue <VORecorderFrame> frames = GetVOQue(list); VORecorderFrame frame; onMouthChange?.Invoke(VOPositions.SilentMB); OnVOPositionChanged?.Invoke(VOPositions.SilentMB, sound); OnVOStarted?.Invoke(sound); L.Log(LogEventType.INT, $"PlayVOSound: {sound}"); PlaySound(sound); while (frames.Count > 0) { frame = frames.Dequeue(); while ((soundClip.AudioSource.time * 1000) < frame.frameTime) { await Task.Delay(1); } onMouthChange?.Invoke(frame.position); OnVOPositionChanged?.Invoke(frame.position, sound); } await Task.Delay(recorder.finalFrameDelay); onComplete?.Invoke(); OnVOCompleted?.Invoke(sound); } else { L.Log(LogEventType.ERROR, $"No VORecorder component found on {soundClip.name}"); PlaySound(sound); onComplete?.Invoke(); OnVOCompleted?.Invoke(sound); } } catch (Exception err) { L.Log(LogEventType.ERROR, $"{err.Message}, {@err.StackTrace}"); } }