Vivox Unity SDK 16.0.0 업그레이드 가이드
Upgrade from previous Vivox versions to version 16.0.0.
읽는 시간 4분최근 업데이트: 7달 전
이 가이드는 Vivox Unity SDK 버전 16.0.0으로 업그레이드하는 방법에 대한 세부 정보를 제공하고 두 SDK 버전 간의 차이점을 중점적으로 다룹니다.
버전 16.0.0에는 단순화된 기능이 도입되었으며 다음과 관련된 영역에서도 변경이 필요합니다.
- SDK 초기화
- 로그인/로그아웃
- 플레이어 차단
- 채널에 연결
- 채널 참가자 관리
- 오디오 디바이스 관리
- 액티브 디바이스 설정
- 디바이스 게인/음량 설정
- 디바이스 음소거
SDK 설정 및 초기화
Vivox API에 액세스하려면 를 로 바꾸십시오.
using VivoxUnity;using Unity.Services.Vivox;VivoxUnity 네임스페이스는 더 이상 존재하지 않습니다.
또한 SDK를 초기화하는 원래 방법이었던 클라이언트는 더 이상 존재하지 않습니다.
Authentication 사용
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.Instance프로젝트가 Unity Dashboard 인증정보를 사용하지만 AuthenticationService 패키지를 사용하지 않는 경우 테스트 모드를 활성화하고 로그인 호출을 생략할 수 있습니다. Test Mode를 켜려면 Unity 에디터에서 Project Settings > Services > Vivox로 이동하여 Test Mode라고 레이블이 지정된 체크박스를 선택할 수 있습니다.
AuthenticationService다음은 AuthenticationService 패키지가 없고 Test Mode가 활성화된 초기화 설정을 보여 주는 예제입니다.
async void InitializeAsync(){ await UnityServices.InitializeAsync(); await VivoxService.Instance.InitializeAsync();}
Vivox 개발자 포털 인증정보 사용
레거시 Vivox 개발자 포털 인증정보가 있는 경우 를 통해 에 해당 인증정보를 제공하십시오. 이러한 인증정보에는 테스트 목적의 서명 키가 포함될 수 있습니다.
InitializationOptionsVivoxService.Instance.InitializeAsync다음은 Vivox 개발자 포털 인증정보를 사용한 초기화 설정을 보여 주는 예제입니다.
async 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();}
로그인 라이프사이클 변경 사항
ILoginSession.BeginLoginVivoxService.Instance.LoginAsync(LoginOptions options = null)LoginOptions- DisplayName
- 텍스트 투 스피치 활성화
- 새 채널에 참여할 때 자동 채널 전송 교환 비활성화
- 로그인 시 현재 플레이어에 대해 차단(교차 음소거)할 PlayerID 목록 캐싱
- SDK가 참가자 업데이트 이벤트를 수신하는 속도 설정
async void LoginToVivoxAsync(List<string> blockedList, string displayName){ LoginOptions options = new LoginOptions(); options.DisplayName = displayName; options.BlockedUserList = blockedList; await VivoxService.Instance.LoginAsync(options);}
Vivox 서비스 로그아웃을 위해 이 로 대체되었습니다.
ILoginSession.Logout()VivoxService.Instance.LogoutAsyncPropertyName이 ‘State’이고 또는 을 사용하여 이벤트에 연결된 로직을 다른 함수로 이동합니다. 다음 예제와 같이 과 에서 개별적으로 트리거되도록 로그인과 로그아웃 로직을 분할합니다.
LoginState.LoggedInLoginState.LoggedOutLoginSession.PropertyChangedVivoxService.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.ActiveChannelsVivoxParticipants이전 구현에서는 사용자가 채널에 연결되었는지 확인하기 위해 와 에 의존했습니다. 두 프로퍼티의 상태 변경을 트래킹하는 이벤트를 와 에 연결된 함수로 대체합니다.
AudioStateTextStateVivoxService.Instance.ChannelJoinedVivoxService.Instance.ChannelLeftVivoxService.Instance.ChannelJoinedVivoxService.Instance.ChannelLeft다음 코드 샘플은 이러한 변경 사항을 보여 주는 예제입니다.
void 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.}
채널 전송
기본적으로 채널 전송(말하는 채널)은 가장 최근에 참여한 채널로 전환됩니다. 를 true로 설정한 다음 해당 LoginOptions 오브젝트를 입력으로 사용하는 를 호출하면 이를 비활성화할 수 있습니다.
LoginOptions.DisableAutomaticChannelTransmissionSwapVivoxService.Instance.LoginAsyncVivoxService.Instance.SetChannelTransmissionModeAsync(TransmissionMode transmissionMode, string channelName = null)이 API는 메서드의 입력에 따라 특정 채널, 모든 채널 또는 채널 없음을 전송 채널로 설정할 수 있습니다.
채널 참가자 관리
VivoxParticipant가 ChannelParticipant를 대체했습니다.
올바른 키(채널 이름)를 사용하는 경우 인덱스에서 값을 검색하여 각 활성화된 채널의 VivoxParticipant 컬렉션에 액세스할 수 있습니다.
VivoxService.Instance.ActiveChannelsVivoxService.Instance.ParticipantAddedToChannelVivoxServince.Instance.ParticipantRemovedFromChannel이벤트는 관련 VivoxParticipant를 해당 이벤트에 바인딩된 콜백에 대한 입력으로 제공합니다. VivoxParticipant 오브젝트에는 참가자의 PlayerId에 대한 정보, 참가자가 참여했거나 나간 채널의 이름, 참가자가 로컬 플레이어인지 표시 이름인지 여부를 포함한 기타 중요한 정보가 들어 있습니다. 다음은 이러한 유형의 이벤트를 보여 주는 예제입니다.
void 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
VivoxParticipant에는 다음 이벤트도 포함되어 있습니다.
ParticipantMuteStateChangedParticipantSpeechDetectedParticipantAudioEnergyChanged
이러한 이벤트를 사용하여 기능적인 VU(음량 단위) 미터 또는 스피치 표시기를 생성할 수 있습니다. 각 참가자의 개별 UI 수준에서 이러한 이벤트를 연결합니다.
다음 샘플 클래스는 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()오디오 디바이스 관리
더 이상 클라이언트 오브젝트를 활용하여 디바이스 관리를 수행할 수 없습니다. 이제 를 사용하여 음소거, 음량 변경 또는 액티브 디바이스 전환과 같은 디바이스 조정을 수행할 수 있습니다.
VivoxService.Instance로컬 플레이어 음소거
로컬에서 스스로 음소거하기는 함수 와 를 활용하도록 변경되었습니다. 이전에는 IAudioDevice 오브젝트에서 API를 통해 이 작업을 수행하거나 채널 전송을 없음으로 전환해야 했습니다. 이러한 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)VivoxInputDevicesVivoxOutputDevicesVivoxService.Instance.AvailableInputDevicesVivoxService.Instance.AvailableOututDevices다음은 Vivox SDK 오디오 디바이스 API를 사용하여 액티브 입력 디바이스 변경 기능을 제공하는 입력 디바이스 드롭다운 목록을 채우는 방법을 보여 주는 예제입니다.
using 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()); }}