位置频道配置

如果游戏已加入位置频道,它必须频繁地使用 Vivox SDK 更新与该频道关联的 3D 空间中的用户位置和方向。客户端通过调用VivoxService.Instance.Set3DPosition(GameObject participantObject, string channelName)方法,并使用表示场景中玩家的 GameObject 和已连接音频的活动位置频道的 channelName 来完成此操作。您还可以连接 TextState,但要设置位置,您必须连接到音频。

参与者在位置频道中的位置会影响他们可以听到的人以及其他玩家声音的感知响度和方向。在启用文本的情况下,位置会将文本消息的传递限制在发送者可听范围内的用户。

位置频道使用右手坐标系。当玩家角色正面对着前方时,将应用以下标准

  • 正 X 轴位于角色的右侧。
  • 正 Y 轴从角色的脚向上穿过头部。
  • 正 Z 轴从角色的胸部穿过背部。

当玩家加入位置频道时,玩家角色将放置在空位置,直到他们移动到某个位置。

当玩家加入位置频道时,玩家角色将放置在空位置,直到他们移动到某个位置。

Note: Unity uses a left-hand, Y-up world coordinate system (positive X-axis is to the right, positive Y-axis is up, positive Z-axis is into the screen). Do not manually perform the conversion between coordinate systems because it is handled internally by the Vivox SDK.

在您设置并加入任何配置了 3D 属性的位置频道后,您需要将角色的位置和方向报告给 Vivox SDK。

以下代码是设置用户在位置频道中的位置的示例

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
        }
        . . .
    }
    . . .
}

此示例代码演示了限制发送的 3D 位置更新数量的方法。例如,更新方法中的时间跟踪技术可以将更新尝试的速率限制为每秒合理的次数。在示例方法 Update3DPosition 中,自定义 CachedPosition 类缓存了玩家的位置和方向,这允许在值更改时进行 Set3DPosition 调用。