首页 > 解决方案 > Naudio + Unity:如何访问 DeviceCount

问题描述

我想做一个非对称游戏(VR/Gamepad)。所以我需要一些来自电视和 VR 耳机的声音。

我已经安装了 Naudio 插件以实现统一,但我无法使用此版本访问 DeviceCount 属性。然后,我尝试了普通版本。我可以访问该属性,但 Unity3D 在我对脚本进行更改后总是崩溃。

这是我使用常规 Naudio 版本的代码:

            using System.Collections;
            using System.Collections.Generic;
            using UnityEngine;
            using NAudio;
            using NAudio.Wave;

            public class Naudio : MonoBehaviour
            {
                WaveOut waveOut;
                WaveFileReader waveReader;

                // Start is called before the first frame update
                void Start()
                {
                    waveOut = new WaveOut();
                    Debug.Log("NAUDIO device " + waveOut.DeviceNumber);
                    Debug.Log("NAUDIO Count " + WaveOut.DeviceCount);

                    for (int i = -1; i < WaveOut.DeviceCount; i++)
                    {
                        var caps = WaveOut.GetCapabilities(i);
                        Debug.Log("Device Name: " + caps.ProductName);
                    }
                    waveOut = new WaveOut();
                    waveReader = new WaveFileReader("Assets/_Projet/Resources/Sounds/PowerUp.wav");
                    waveOut.DeviceNumber = -1;
                    waveOut.Init(waveReader);
                    waveOut.Play();
                }
            }

我可以在没有统一崩溃的情况下安装 Naudio,还是我唯一的选择是 Naudio-unity?

谢谢

标签: c#unity3dnaudio

解决方案


推荐阅读