2.将按钮交互声音空间化2. Spatializing button interaction sounds

概述Overview

在本教程中,你将学习如何 spatialize 按钮交互声音,还可以了解如何使用音频剪辑测试 spatialized 按钮交互。In this tutorial, you will learn how to spatialize the button interaction sounds and also learn how to use an audio clip to test spatialized button interaction.

目标Objectives

  • 添加并 Spatialize 按钮单击声音Add and Spatialize the button click sounds

添加按钮Add a button

若要添加按钮 prefab,请在 " 项目 " 窗口中选择 " 资产 ",并在搜索栏中键入 "PressableButtonHoloLens2"。To add the Button prefab, in the Project window, select Assets and type "PressableButtonHoloLens2" in the search bar.

资产中的 prefab 按钮

按钮 prefab 是由蓝色图标表示的条目。The button prefab is the entry represented by a blue icon. 单击并将 PressableButtonHoloLens2 prefab 拖到层次结构中。Click and drag the PressableButtonHoloLens2 prefab into the Hierarchy. PressableButtonHoloLens2 对象仍处于选中状态的情况下,在 "检查器" 窗口中,按如下所示配置 转换 组件:With the PressableButtonHoloLens2 object still selected, in the Inspector window, configure the Transform component as follows:

  • Position: X = 0,Y =-0.4,Z = 2Position: X = 0, Y = -0.4, Z = 2
  • 旋转:X = 0, Y = 0, Z = 0Rotation: X = 0, Y = 0, Z = 0
  • 缩放:X = 1,Y = 1,Z = 1Scale: X = 1, Y = 1, Z = 1

按钮转换

若要重点关注场景中的对象,可以双击 PressableButtonHoloLens2 对象,然后再次缩小:To focus in on the objects in the scene, you can double-click on the PressableButtonHoloLens2 object, and then zoom slightly in again:

Spatialize 按钮反馈Spatialize button feedback

在此步骤中,你将 spatialize 按钮的音频反馈。In this step, you'll spatialize the audio feedback for the button. 有关相关设计的建议,请参阅 空间音效设计For related design suggestions, see spatial sound design.

在 " 音频混音 器" 窗口中,你将定义名为 " 混音器组" 的目标,以便从 音频源 组件播放音频。In the Audio Mixer window you will define destinations called Mixer Groups, for audio playback from Audio Source components.

若要打开 "音频混音 器" 窗口,请在 Unity 菜单中选择 "窗口 > 音频 > 混音 器:  打开音频混音器" 窗口To open the Audio Mixer window, In the Unity menu, select Window > Audio > Audio Mixer: Open Audio Mixer Window

单击 " Mixers " 旁边的 "+" 并向混音器输入合适的名称(例如,空间音频混合器),创建 混音 器。Create a Mixer by clicking the '+' next to Mixers and enter a suitable name to the Mixer for example, Spatial Audio Mixer. 新混音器将包含一个名为 Master 的默认 The new mixer will include a default Group called Master.

带有第一个混音器的混音器面板

备注

在5章节中启用回响后 :使用回音向空间音频添加距离,混音器的音量指示器不显示通过 Microsoft Spatializer 播放的声音的活动Until reverb is enabled in 5th Chapter: Using reverb to add distance to spatial audio, the mixer's volume meter doesn't show activity for sounds played through the Microsoft Spatializer

在 "层次结构" 窗口中,选择 " PressableButtonHoloLens2 ",然后在 "检查器" 窗口中找到 " 音频源 " 组件,并按如下所示配置音频源组件:In the Hierarchy window, select the PressableButtonHoloLens2 then in the Inspector window find the Audio Source component and Configure the Audio Source component as follows:

  1. 对于 " 输出 " 属性,单击选择器并选择已创建的 混音 器。For the Output property, click the selector and choose the Mixer that you created.
  2. 选中 " Spatialize " 复选框。Check the Spatialize checkbox.
  3. 空间 Blend 滑块移动到 3d (1) 。Move the Spatial Blend slider to 3D (1).

按钮音频源

备注

如果将 空间混合 移动到 1 (3d) 而不选中 Spatialize 复选框,则 Unity 将使用其平移 spatializer,而不是 Microsoft spatializer with HRTFs。If you move Spatial Blend to 1 (3D) without checking the Spatialize checkbox, Unity will use its panning spatializer, instead of the Microsoft Spatializer with HRTFs.

调整音量曲线Adjust the Volume curve

默认情况下,在从侦听器获得更远的距离时,Unity 将衰减 spatialized 声音。By default, Unity will attenuate spatialized sounds as they get farther from the listener. 如果此衰减应用于交互反馈声音,则接口可能会变得更难以使用。When this attenuation is applied to interaction feedback sounds, the interface can become more difficult to use.

若要禁用此衰减,需调整 音频源 组件中的 音量 曲线。To disable this attenuation, you need to adjust the Volume curve In the Audio Source component.

在 "层次结构" 窗口中,选择 " PressableButtonHoloLens2 ",然后在 "检查器" 窗口中,导航到 "音频源 > 3d 声音设置",并按如下In the Hierarchy window, select the PressableButtonHoloLens2 then in the Inspector window navigate to Audio Source > 3D Sound Settings and Configure as follows:

  1. Volume Rolloff 属性设置为线性 RolloffSet the Volume Rolloff property to Linear Rolloff
  2. 曲线上的终结点从 y 轴上的 "0") (红色曲线上,直到 "1"Drag the endpoint on the Volume curve (the red curve) from '0' on the y axis up to '1'
  3. 若要将 音量 曲线的形状调整为平面,请拖动 "白色曲线" 形状控件,使其平行于 X 轴To adjust the shape of the Volume curve to be flat, drag the white curve shape control to be parallel to the X axis

按钮三维声音设置

测试 spatialize 音频Testing the spatialize audio

若要在 unity 编辑器中测试 spatialize 音频,必须在 PressableButtonHoloLens2 对象上 的 "已签入" "循环" 选项中添加音频剪辑。To test the spatialize audio in the unity editor you have to add an audio clip in the Audio Source component with Loop option checked in on PressableButtonHoloLens2 object.

在播放模式下,将 PressableButtonHoloLens2 对象从左到右移动,并在工作站上比较和不启用空间音频。In the play mode move the PressableButtonHoloLens2 object from left to right and compare with and without spatial audio enabled on your workstation. 还可以通过以下方式更改用于测试的音频源设置:You can also change the Audio Source settings for testing by:

  • 空间 Blend 属性移动到 0-1 (2d 非 Spatialized 和 3d spatialized 声音) Moving the Spatial Blend property between 0 - 1 (2D non-spatialized and 3D spatialized sound)
  • 选中和取消选中 Spatialize 属性Checking and unchecking the Spatialize property

试用 HoloLens 2 上的应用。Try out the app on HoloLens 2. 在应用程序中,可以单击按钮并听到 spatialized 按钮交互声音。In the app, you can click the button and hear the spatialized button interaction sounds.

提示

要查看提示了解如何生成 Unity 项目并将其部署到 HoloLens 2,可参阅在 HoloLens 2 上构建应用中的说明。For a reminder on how to build and deploy your Unity project to HoloLens 2, you can refer to the Building your app to your HoloLens 2 instructions.

祝贺Congratulations

在本教程中,你已了解到 spatialize 按钮交互声音,并使用音频剪辑测试 spatialized 按钮交互。In this tutorial you have learnt to spatialize the button interaction sounds and to use an audio clip to test spatialized button interaction. 在下一教程中,你将学习如何从视频源 spatialize 音频。In the next tutorial you will learn how to spatialize audio from an video source.