浏览代码

Adding in Vivox package. There is now a basic voice channel while in a lobby, but not yet volume controls or other Vivox features. (There are some TODOs of details to follow up on as well.)

/main/staging/vivox_package_integration
nathaniel.buck@unity3d.com 3 年前
当前提交
cfa8d7ab
共有 8 个文件被更改,包括 138 次插入6 次删除
  1. 11
      Assets/Scripts/Game/GameManager.cs
  2. 4
      Assets/Scripts/LobbyRelaySample.asmdef
  3. 1
      Packages/manifest.json
  4. 18
      Packages/packages-lock.json
  5. 8
      Assets/Scripts/Vivox.meta
  6. 91
      Assets/Scripts/Vivox/VivoxSetup.cs
  7. 11
      Assets/Scripts/Vivox/VivoxSetup.cs.meta

11
Assets/Scripts/Game/GameManager.cs


private LobbyContentHeartbeat m_lobbyContentHeartbeat = new LobbyContentHeartbeat();
private RelayUtpSetup m_relaySetup;
private RelayUtpClient m_relayClient;
private vivox.VivoxSetup m_vivoxSetup = new vivox.VivoxSetup();
/// <summary>Rather than a setter, this is usable in-editor. It won't accept an enum, however.</summary>
public void SetLobbyColorFilter(int color)

m_localUser.ID = Locator.Get.Identity.GetSubIdentity(Auth.IIdentityType.Auth).GetContent("id");
m_localUser.DisplayName = NameGenerator.GetName(m_localUser.ID);
m_localLobby.AddPlayer(m_localUser); // The local LobbyUser object will be hooked into UI before the LocalLobby is populated during lobby join, so the LocalLobby must know about it already when that happens.
m_vivoxSetup.Initialize(null);
}
private void BeginObservers()

m_lobbyContentHeartbeat.BeginTracking(m_localLobby, m_localUser);
SetUserLobbyState();
StartRelayConnection();
m_vivoxSetup.JoinLobbyChannel(m_localLobby.LobbyID);
}
private void OnLeftLobby()

m_lobbyContentHeartbeat.EndTracking();
LobbyAsyncRequests.Instance.EndTracking();
m_vivoxSetup.LeaveLobbyChannel();
{
Component.Destroy(m_relaySetup);
{ Component.Destroy(m_relaySetup);
{
Component.Destroy(m_relayClient);
{ Component.Destroy(m_relayClient);
m_relayClient = null;
}
}

4
Assets/Scripts/LobbyRelaySample.asmdef


"GUID:5540e30183c82e84b954c033c388e06c",
"GUID:fe25561d224ed4743af4c60938a59d0b",
"GUID:4c3f49d89436d478ea78315c03159dcc",
"GUID:f2d49d9fa7e7eb3418e39723a7d3b92f"
"GUID:f2d49d9fa7e7eb3418e39723a7d3b92f",
"GUID:060a730ab4d4804498f4a3146ed6f776",
"GUID:6087a74f6015aae4daed9a2577a7596c"
],
"includePlatforms": [],
"excludePlatforms": [],

1
Packages/manifest.json


"com.unity.services.core": "1.0.0",
"com.unity.services.lobby": "1.0.0-pre.4",
"com.unity.services.relay": "1.0.1-pre.1",
"com.unity.services.vivox": "15.1.150000-pre.6",
"com.unity.sysroot.linux-x86_64": "0.1.15-preview",
"com.unity.test-framework": "1.1.27",
"com.unity.textmeshpro": "3.0.6",

18
Packages/packages-lock.json


},
"url": "https://packages.unity.com"
},
"com.unity.services.vivox": {
"version": "15.1.150000-pre.6",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.settings-manager": "1.0.3",
"com.unity.services.core": "1.1.0-pre.8",
"com.unity.nuget.newtonsoft-json": "2.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.settings-manager": {
"version": "1.0.3",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.sysroot": {
"version": "0.1.19-preview",
"depth": 1,

8
Assets/Scripts/Vivox.meta


fileFormatVersion: 2
guid: 679d3159a518edc44a3d0ec4a97e0645
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

91
Assets/Scripts/Vivox/VivoxSetup.cs


using System;
using Unity.Services.Vivox;
using VivoxUnity;
namespace LobbyRelaySample.vivox
{
/// <summary>
/// Handles setting up a voice channel once inside a lobby.
/// </summary>
public class VivoxSetup
{
private bool m_hasInitialized = false;
private bool m_isMidInitialize = false;
private ILoginSession m_loginSession = null;
private IChannelSession m_channelSession = null;
/// <summary>
/// Initialize the Vivox service, before actually joining any audio channels.
/// </summary>
/// <param name="onComplete">Called on complete, whether successful or not. Not called if already in the middle of a previous Initialize call.</param>
public void Initialize(Action onComplete)
{
if (m_isMidInitialize)
return;
m_isMidInitialize = true;
VivoxService.Instance.Initialize();
Account account = new Account(Locator.Get.Identity.GetSubIdentity(Auth.IIdentityType.Auth).GetContent("id"));
m_loginSession = VivoxService.Instance.Client.GetLoginSession(account);
m_loginSession.BeginLogin(m_loginSession.GetLoginToken(), SubscriptionMode.Accept, null, null, null, result =>
{
try
{
m_loginSession.EndLogin(result);
m_hasInitialized = true;
}
catch
{
throw;
}
finally
{
m_isMidInitialize = false;
onComplete?.Invoke(); // TODO: Is BeginLogin guaranteed to call this callback?
}
});
}
/// <summary>
/// Once in a lobby, start joining a voice channel for that lobby. Be sure to complete Initialize first.
/// </summary>
public void JoinLobbyChannel(string lobbyId)
{
if (!m_hasInitialized || m_loginSession.State != LoginState.LoggedIn)
{
UnityEngine.Debug.LogWarning("Can't join a Vivox audio channel, as Vivox login hasn't completed yet.");
return;
}
ChannelType channelType = ChannelType.NonPositional;
Channel channel = new Channel(lobbyId + "_voice", channelType, null);
m_channelSession = m_loginSession.GetChannelSession(channel);
m_channelSession.BeginConnect(true, false, true, m_channelSession.GetConnectToken(), result =>
{
m_channelSession.EndConnect(result); // TODO: Error handling?
});
}
/// <summary>
/// To be called when leaving a lobby.
/// </summary>
public void LeaveLobbyChannel()
{
ChannelId id = m_channelSession.Channel;
m_channelSession?.Disconnect(
(result) => { m_loginSession.DeleteChannelSession(id); }); // TODO: What about if this is called while also trying to connect?
}
/// <summary>
/// To be called on quit, this will disconnect the player from Vivox entirely instead of just leaving any open lobby channels.
/// </summary>
public void Uninitialize()
{
if (!m_hasInitialized)
return;
m_loginSession.Logout();
}
}
}

11
Assets/Scripts/Vivox/VivoxSetup.cs.meta


fileFormatVersion: 2
guid: c03a71d8e07097647ae53b5f0b98d69d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存