Vivox Unity SDK 16.0.0 アップグレードガイド
Upgrade from previous Vivox versions to version 16.0.0.
読み終わるまでの所要時間 6 分最終更新 23日前
このガイドには Vivox Unity SDK バージョン 16.0.0 にアップグレードする方法に関する詳細と、2 つのバージョンの SDK の違いが示されています。
バージョン 16.0.0 は機能が簡略化されているほか、以下の関連する領域にも変更が必要です。
- SDK の初期化
- ログイン/ログアウト
- プレイヤーのブロック
- チャンネルへの接続
- チャンネル参加者の管理
- オーディオデバイスの管理
- アクティブなデバイスの設定
- デバイスのゲイン/音量の設定
- デバイスのミュート
SDK の設定と初期化
Vivox API にアクセスするために、using VivoxUnity;using Unity.Services.Vivox;認証の使用
Unity Authentication パッケージを使用している場合は、以下の例に示すように、まずは
await UnityServices.InitializeAsync()await AuthenticationService.Instance.SignInAnonymously()await VivoxService.Instance.InitializeAsync()async void InitializeAsync(){ await UnityServices.InitializeAsync(); await AuthenticationService.Instance.SignInAnonymouslyAsync(); await VivoxService.Instance.InitializeAsync();}
AuthenticationService.InstanceAuthenticationService
以下の例は、AuthenticationService パッケージを使用せず、かつ テストモード がオンになっている初期化の設定を示します。
async void InitializeAsync(){ await UnityServices.InitializeAsync(); await VivoxService.Instance.InitializeAsync();}
Vivox デベロッパーポータルの認証情報の使用
Vivox デベロッパーポータルの従来の認証情報がある場合は、それらの認証情報をInitializationOptionsVivoxService.Instance.InitializeAsyncasync void InitializeAsync(){ InitializationOptions options = new InitalizationOptions(); // _key can be excluded from SetVivoxCredentials if an implementation of IVivoxTokenProvider has been provided to the SDK. options.SetVivoxCredentials(_server, _domain, _issuer, _key); await UnityServices.InitializeAsync(options); await VivoxService.Instance.InitializeAsync();}
サインインのライフサイクルの変更
Vivox サービスにサインインするためのILoginSession.BeginLoginVivoxService.Instance.LoginAsync(LoginOptions options = null)LoginOptions- DisplayName
- テキスト音声変換を有効にする
- 新しいチャンネルに参加するときに自動チャンネル伝送スワップを無効にする
- サインイン時に現在のプレイヤーのブロック (クロスミュート) 対象の PlayerID のリストをキャッシュする
- SDK が参加者の更新イベントを受け取る頻度を設定する
Vivox サービスからサインアウトするためのasync void LoginToVivoxAsync(List<string> blockedList, string displayName){ LoginOptions options = new LoginOptions(); options.DisplayName = displayName; options.BlockedUserList = blockedList; await VivoxService.Instance.LoginAsync(options);}
ILoginSession.Logout()VivoxService.Instance.LogoutAsyncLoginSession.PropertyChangedLoginState.LoggedInLoginState.LoggedOutVivoxService.Instance.LoggedInVivoxService.Instance.LoggedOutvoid Start(){ VivoxService.Instance.LoggedIn += OnUserLoggedIn; VivoxService.Instance.LoggedOut += OnUserLoggedOut;}void OnDestroy(){ //Cleanup events if the GameObject is destroyed to prevent unexpected behavior. VivoxService.Instance.LoggedIn -= OnUserLoggedIn; VivoxService.Instance.LoggedOut -= OnUserLoggedOut;}void OnUserLoggedIn(){ Debug.Log("The user has successfully logged in"); // Other logic such as attempting a default channel join or changing the state of voice UIs to indicate the character is logged in can be done here.}void OnUserLoggedOut(){ Debug.Log("The user has logged out"); // The LoggedOut event will fire after a VivoxService.Instance.LogoutAsync call has been completed successfully // or after an internet disruption has caused Automatic Connection Recovery to declare the attempted recovery a failure.}
プレイヤーのブロック
ILoginSession.SetCrossMutedCommunicationsVivoxServince.Instance.BlockPlayerAsync(string playerId)VivoxService.Instance.UnblockPlayerAsync(string playerId)AccountIdplayerIdチャンネルのライフサイクルの変更
チャンネルへの参加と退出
ChannelSession.BeginConnectJoinGroupChannelAsync(string channelName, ChatCapability chatCapability, ChannelOptions channelOptions = null);JoinPositionalChannelAsync(string channelName, ChatCapability chatCapability, Channel3DProperties positionalChannelProperties, ChannelOptions channelOptions = null);JoinEchoChannelAsync(string channelName, ChatCapability chatCapability, ChannelOptions channelOptions = null);
ChannelSession.Disconnect()- - 特定のチャンネルから退出する。
VivoxService.Instance.LeaveChannelAsync(string channelName) - - すべてのアクティブなチャンネルから退出する。このメソッドは、タイミングを問わずシングルチャンネルのみに参加した場合に使用することをお勧めします。
VivoxService.Instance.LeaveAllChannelsAsync()
ILoginSession.ChannelSessionsVivoxService.Instance.ActiveChannelsVivoxService.Instance.ActiveChannelsVivoxParticipantsAudioStateTextStateVivoxService.Instance.ChannelJoinedVivoxService.Instance.ChannelLeftVivoxService.Instance.ChannelJoinedVivoxService.Instance.ChannelLeftvoid BindToChannelActions(){ //Connecting/Disconnecting channel actions can be done upon VivoxService.Instance.LoggedIn and LoggedOut events being fired, respectively, //for basic lifecycle control VivoxService.Instance.ChannelJoined += OnChannelJoined; VivoxService.Instance.ChannelLeft += OnChannelLeft;}void UnbindChannelActions(){ VivoxService.Instance.ChannelJoined -= OnChannelJoined; VivoxService.Instance.ChannelLeft -= OnChannelLeft;}void OnChannelJoined(string channelName){ //The channel with name channelName has been successfully joined, and any UI updates should be done for it //Additionally, if multiple channels are being handled, keeping track of the channelName and knowing which channel is for which purpose should be done //on the side of the implementation based on this event.}void OnChannelLeft(string channelName){ //The channel with name channelName has been successfully left, and any UI updates should be done for it //This also means that the channelName can likely be safely lost, although if the channelName is specific and might be rejoined, //it should be held on to by the implementation.}
チャンネルの伝送
デフォルトでは、チャンネルの伝送 (発話しているチャンネル) は直近で参加したチャンネルに切り替わります。その LoginOptions オブジェクトを入力として使用してVivoxService.Instance.LoginAsyncLoginOptions.DisableAutomaticChannelTransmissionSwapVivoxService.Instance.SetChannelTransmissionModeAsync(TransmissionMode transmissionMode, string channelName = null)チャンネル参加者の管理
ChannelParticipant は VivoxParticipant に置き換わっています。 アクティブな各チャンネルの VivoxParticipant のコレクションは、正しいキー (チャンネル名) が使用されている条件で、VivoxService.Instance.ActiveChannelsVivoxService.Instance.ParticipantAddedToChannelVivoxServince.Instance.ParticipantRemovedFromChannelvoid BindToParticipantEvents(){ //These events can be connected at the same time as the channel events from the previous sections for convenience purposes VivoxService.Instance.ParticipantAddedToChannel += OnParticipantAdded; VivoxService.Instance.ParticipantRemovedFromChannel += OnParticipantRemoved;}void UnbindParticipantEvents(){ VivoxService.Instance.ParticipantAddedToChannel -= OnParticipantAdded; VivoxService.Instance.ParticipantRemovedFromChannel -=OnParticipantRemoved;}void OnParticipantAdded(VivoxParticipant participant){ // Use VivoxParticipant to establish some UI element tied to that specific VivoxParticipant, which can then be used to control things such as muting // volume, and blocking, along with UI that can track certain states - such as whether the player is currently muted or is currently speaking.}void OnParticipantRemoved(VivoxParticipant participant){ // At this point, any UI created to display information about this VivoxParticipant can be safely disposed of.}
VivoxParticipant オブジェクト
VivoxParticipant- 。参加者がローカルプレイヤーであるかどうかを示します。
VivoxParticipant.IsSelf - 。参加者のオーディオエネルギーが Vivox SDK によって音声と見なされるしきい値を超えているかどうかを示します。
VivoxParticipant.SpeechDetected
ParticipantMuteStateChangedParticipantSpeechDetectedParticipantAudioEnergyChanged
以下のサンプルクラスは、ChatChannelSample 内の RosterItem の簡略化されたバージョンです。
public class RosterItem : MonoBehaviour{ public VivoxParticipant Participant; public Text PlayerNameText; public void SetupRosterItem(VivoxParticipant participant) { Participant = participant; PlayerNameText.text = Participant.DisplayName; Participant.ParticipantMuteStateChanged += OnMuteStateChanged; Participant.ParticipantSpeechDetected += OnSpeechDetected; } void OnMuteStateChanged() { if(Participant.IsMuted) { //Participant has been muted } else { //Participant has been unmuted } } void OnSpeechDetected() { //Participant AudioEnergy has exceeded the value required to be considered speech }}
チャンネル参加者のミュート
VivoxParticipant.MutePlayerLocally()VivoxParticipant.UnmutePlayerLocally()オーディオデバイスの管理
Client オブジェクトを利用してデバイスを管理できなくなりました。ミュート、音量変更、アクティブデバイスの切り替えなどのデバイスの調整は、VivoxService.Instanceローカルプレイヤーのミュート
自分をローカルでミュートする方法が、IAudioDevice オブジェクトで API を使用して行うのではなく、関数VivoxService.Instance.MuteInputDevice()VivoxService.Instance.UnmuteInputDevice()入出力デバイスの音量調整
VivoxService.Instance.SetInputDeviceVolume(int value)VivoxService.Instance.SetOutputDeviceVolume(int value)アクティブな入出力デバイスの変更
VivoxService.Instance.SetActiveOutputDeviceAsync(VivoxOutputDevice device)VivoxService.Instance.SetActiveInputDeviceAsync(VivoxInputDevice device)VivoxService.Instance.AvailableInputDevicesVivoxService.Instance.AvailableOututDevicesVivoxInputDevicesVivoxOutputDevicesusing System.Linq;using Unity.Services.Vivox;using UnityEngine;using UnityEngine.UI;public class AudioDeviceSettings : MonoBehaviour{ public Dropdown InputDeviceDropdown; private void Start() { VivoxService.Instance.AvailableInputDevicesChanged += RefreshInputDeviceList; InputDeviceDropdown.onValueChanged.AddListener((i) => { InputDeviceValueChanged(i); }); } void OnEnable() { RefreshInputDeviceList(); } void OnDestroy() { // Unbind all UI actions InputDeviceDropdown.onValueChanged.RemoveAllListeners(); VivoxService.Instance.AvailableInputDevicesChanged -= RefreshInputDeviceList; } private void RefreshInputDeviceList() { InputDeviceDropdown.Hide(); InputDeviceDropdown.ClearOptions(); InputDeviceDropdown.options.AddRange(VivoxService.Instance.AvailableInputDevices.Select(v => new Dropdown.OptionData() { text = v.DeviceName })); InputDeviceDropdown.SetValueWithoutNotify(InputDeviceDropdown.options.FindIndex(option => option.text == VivoxService.Instance.ActiveInputDevice.DeviceName)); InputDeviceDropdown.RefreshShownValue(); } void InputDeviceValueChanged(int index) { VivoxService.Instance.SetActiveInputDeviceAsync(VivoxService.Instance.AvailableInputDevices.Where(device => device.DeviceName == InputDeviceDropdown.options[index].text).First()); }}