位置频道配置
Configure positional channels for spatial audio in 3D environments.
阅读时间2 分钟最后更新于 13 天前
如果游戏加入了位置频道,则必须经常向 Vivox SDK 更新用户在与该频道关联的 3D 空间中的位置和方向。客户端通过调用
VivoxService.Instance.Set3DPosition(GameObject participantObject, string channelName)- 正向 X 轴在化身右侧。
- 正向 Y 轴从化身双脚向上穿过其头部。
- 正向 Z 轴从化身胸部到其后背。
设置并加入具有任何配置的 3D 属性的位置频道之后,随后可向 Vivox SDK 报告角色的位置和方向。
以下代码示例说明如何在位置频道中设置用户的位置:
此示例代码演示可限制发送的 3D 位置更新数量的方法。例如,更新方法中的一种简单时间跟踪技术可以将更新尝试的速率限制为每秒合理的次数。在示例方法using UnityEngine;using Unity.Services.Vivox;class PositionalChannelExample : MonoBehaviour{ . . . // For this example, _nextPosUpdate has been initialized as Time.time at // game start. _localPlayerGameObject is the GameObject controlled by the local player. void Update() { . . . if (Time.time > _nextPosUpdate) { VivoxService.Instance.Set3DPosition(_localPlayerGameObject, activePositionalChannelName); _nextPosUpdate += 0.3f; // Only update after 0.3 or more seconds } . . . } . . .}
Update3DPositionSet3DPosition