private void Awake() { _instance = this; _instanceInit = true; // Check this gameobject & it's children for audio input _micInput = gameObject.GetComponentInChildren <IAudioInputSource>(); // Check all roots for Mic Input JIC if (_micInput == null) { foreach (var root in gameObject.scene.GetRootGameObjects()) { _micInput = root.GetComponentInChildren <IAudioInputSource>(); if (_micInput != null) { break; } } } // Use default mic script if (_micInput == null) { _micInput = gameObject.AddComponent <Mic>(); } InitializeMicDataBuffer(); }
// Add delegates private void OnEnable() { if (_micSource == null) { _micSource = gameObject.GetComponentInChildren <IAudioInputSource>(); } if (_micSource != null) { _micSource.OnStartRecording += OnStartRecording; _micSource.OnSampleReady += OnSampleReady; _micSource.OnStopRecording += OnStopRecording; } }
private void OnEnable() { #if UNITY_EDITOR // Make sure we have a mic input after a script recompile if (null == _micInput) { _micInput = GetComponent <IAudioInputSource>(); } #endif _micInput.OnSampleReady += OnMicSampleReady; if (alwaysRecording) { StartRecording(this); } }