Skip to content

Commit f3ae2fd

Browse files
[MTT-8881] Integrate proximity voice-chat (#261)
* recreation of vivox scripts from old PR * updating ServiceHelper to join channel * wip: Enable Vivox, voice and text working somehow without UI atm * wip: textchat working * feat: improve Chat * wip: Improve TextChat * wip: achitectural changes * wip: small improvements * chore: decouple TextChat from Services * chore: cleanup * feat: Block Player Input on Chat Input focused * fix: await Vivox Login * chore: remove unused files * chore: remove scene * fix: focus state on textfield * fix: improve initialization and handle session leave * chore: cleanup * wip: Add positional voice chat * chore: improve architecture * chore: add icon * fix: apply review changes * feat: seperate voice and textchat * fix: catching some potential null refs * feat: select audio device wip * fix: add missing UI * feat: Make sure to ask for Microphone permissions on MacOS * wip: VoiceChat feature complete. Needs cleanup * fix: Focus issue * chore: cleanup extract fields etc. * fix: vivox joining and leaving working * chore: remove unnecessary code, attach to device change events * docs: Update changelog * chore: final cleanup * fix: Hide UI because of Vivox bug * chore: internalize method * chore: remove buildprofile * chore: Move permission check before login * chore: change subscription to events * chore: remove UI dependency in VivoxManager * chore: remove unnecessary argument * chore: cleanup ingameMenu * fix: reapply VivoxPosition Component * fix: Make sure base is called * chore: remove unsubscription * chore: wrap everything related to mic permission into define --------- Co-authored-by: Elfi Kühndorf <[email protected]>
1 parent 374459c commit f3ae2fd

26 files changed

+876
-97
lines changed

Basic/DistributedAuthoritySocialHub/Assets/Prefabs/Characters/Avatar.prefab

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ GameObject:
1717
- component: {fileID: 539700041658036575}
1818
- component: {fileID: 4655812346339390596}
1919
- component: {fileID: 7543523986693376117}
20+
- component: {fileID: 4616764017061829939}
2021
m_Layer: 0
2122
m_Name: Avatar
2223
m_TagString: Player
@@ -53,7 +54,7 @@ MonoBehaviour:
5354
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
5455
m_Name:
5556
m_EditorClassIdentifier:
56-
GlobalObjectIdHash: 3001504883
57+
GlobalObjectIdHash: 2473698027
5758
InScenePlacedSourceGlobalObjectIdHash: 0
5859
DeferredDespawnTick: 0
5960
Ownership: 0
@@ -203,7 +204,6 @@ MonoBehaviour:
203204
m_AvatarNetworkAnimator: {fileID: 7543523986693376117}
204205
m_AnimationEventRelayer: {fileID: 3050276823525430539}
205206
m_MainCollider: {fileID: 36137897785899347}
206-
m_AvatarInputs: {fileID: 0}
207207
m_PickupLocFixedJoint: {fileID: 3522541554063944713}
208208
m_PickupLocChild: {fileID: 1191881578848548316}
209209
m_LeftHandContact: {fileID: 8336303498504233401}
@@ -297,6 +297,19 @@ MonoBehaviour:
297297
TransitionIndex: 1
298298
m_Animator: {fileID: 7006295767383679619}
299299
m_PhysicsPlayerController: {fileID: 4655812346339390596}
300+
--- !u!114 &4616764017061829939
301+
MonoBehaviour:
302+
m_ObjectHideFlags: 0
303+
m_CorrespondingSourceObject: {fileID: 0}
304+
m_PrefabInstance: {fileID: 0}
305+
m_PrefabAsset: {fileID: 0}
306+
m_GameObject: {fileID: 5478015027486214707}
307+
m_Enabled: 1
308+
m_EditorHideFlags: 0
309+
m_Script: {fileID: 11500000, guid: bee830f09ba1465fa953159de83e882e, type: 3}
310+
m_Name:
311+
m_EditorClassIdentifier:
312+
ShowTopMostFoldoutHeaderGroup: 1
300313
--- !u!1 &9009864878170659705
301314
GameObject:
302315
m_ObjectHideFlags: 0

Basic/DistributedAuthoritySocialHub/Assets/Scripts/GameManagement/GameplayEventHandler.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Unity.Netcode;
2-
using UnityEngine;
32
using System;
43
using System.Threading.Tasks;
4+
using Unity.Services.Vivox;
55
using UnityEngine.SceneManagement;
66

77
namespace Unity.Multiplayer.Samples.SocialHub.GameManagement
@@ -17,8 +17,9 @@ static class GameplayEventHandler
1717
internal static event Action OnExitedSession;
1818
internal static event Action<string, string, bool> OnTextMessageReceived;
1919
internal static event Action<string> OnSendTextMessage;
20-
internal static event Action<bool> OnBlockPlayerControls;
21-
internal static event Action<bool> OnChatIsReady;
20+
internal static event Action<bool, string> OnChatIsReady;
21+
internal static event Action<VivoxParticipant> OnParticipantJoinedVoiceChat;
22+
internal static event Action<VivoxParticipant> OnParticipantLeftVoiceChat;
2223

2324
internal static void NetworkObjectDespawned(NetworkObject networkObject)
2425
{
@@ -75,14 +76,19 @@ internal static void SendTextMessage(string message)
7576
OnSendTextMessage?.Invoke(message);
7677
}
7778

78-
public static void BlockPlayerControls(bool disable)
79+
public static void SetTextChatReady(bool enabled, string channelName)
7980
{
80-
OnBlockPlayerControls?.Invoke(disable);
81+
OnChatIsReady?.Invoke(enabled, channelName);
8182
}
8283

83-
public static void SetTextChatReady(bool enabled)
84+
public static void ParticipantJoinedVoiceChat(VivoxParticipant vivoxParticipant)
8485
{
85-
OnChatIsReady?.Invoke(enabled);
86+
OnParticipantJoinedVoiceChat?.Invoke(vivoxParticipant);
87+
}
88+
89+
public static void ParticipantLeftVoiceChat(VivoxParticipant vivoxParticipant)
90+
{
91+
OnParticipantLeftVoiceChat?.Invoke(vivoxParticipant);
8692
}
8793
}
8894
}

Basic/DistributedAuthoritySocialHub/Assets/Scripts/GameManagement/Unity.Multiplayer.Samples.SocialHub.GameManagement.asmdef

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"rootNamespace": "Unity.Multiplayer.Samples.SocialHub",
44
"references": [
55
"GUID:1491147abca9d7d4bb7105af628b223e",
6-
"GUID:c15e7f658578345fcb824b0a64d4dbe8"
6+
"GUID:c15e7f658578345fcb824b0a64d4dbe8",
7+
"GUID:6087a74f6015aae4daed9a2577a7596c"
8+
79
],
810
"includePlatforms": [],
911
"excludePlatforms": [],
@@ -14,4 +16,4 @@
1416
"defineConstraints": [],
1517
"versionDefines": [],
1618
"noEngineReferences": false
17-
}
19+
}

Basic/DistributedAuthoritySocialHub/Assets/Scripts/Player/AvatarTransform.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using Unity.Collections;
3-
using Unity.Multiplayer.Samples.SocialHub.GameManagement;
4-
using Unity.Multiplayer.Samples.SocialHub.Gameplay;
53
using UnityEngine;
64
using Unity.Multiplayer.Samples.SocialHub.Input;
75
using Unity.Multiplayer.Samples.SocialHub.Physics;
@@ -27,13 +25,16 @@ class AvatarTransform : PhysicsObjectMotion, INetworkUpdateSystem
2725
PlayersTopUIController m_TopUIController;
2826

2927
NetworkVariable<FixedString32Bytes> m_PlayerName = new NetworkVariable<FixedString32Bytes>(string.Empty, readPerm: NetworkVariableReadPermission.Everyone, writePerm: NetworkVariableWritePermission.Owner);
28+
NetworkVariable<FixedString32Bytes> m_PlayerId = new NetworkVariable<FixedString32Bytes>(string.Empty, readPerm: NetworkVariableReadPermission.Everyone, writePerm: NetworkVariableWritePermission.Owner);
29+
3030

3131
public override void OnNetworkSpawn()
3232
{
3333
gameObject.name = $"[Client-{OwnerClientId}]{name}";
3434

3535
m_TopUIController = FindFirstObjectByType<PlayersTopUIController>();
3636
m_PlayerName.OnValueChanged += OnPlayerNameChanged;
37+
m_PlayerId.OnValueChanged += OnPlayerIdChanged;
3738
OnPlayerNameChanged(string.Empty, m_PlayerName.Value);
3839

3940
if (!HasAuthority)
@@ -42,8 +43,8 @@ public override void OnNetworkSpawn()
4243
return;
4344
}
4445

45-
// a randomly-generated suffix consisting of a hash and four digits (e.g. #1234) is automatically appended to the requested name
46-
m_PlayerName.Value = new FixedString32Bytes(AuthenticationService.Instance.PlayerName.Split('#')[0]);
46+
m_PlayerId.Value = new FixedString32Bytes(AuthenticationService.Instance.PlayerId);
47+
m_PlayerName.Value = new FixedString32Bytes(UIUtils.ExtractPlayerNameFromAuthUserName(AuthenticationService.Instance.PlayerName));
4748
m_PlayerInput.enabled = true;
4849
GameInput.Actions.Player.Jump.performed += OnJumped;
4950
m_AvatarInteractions.enabled = true;
@@ -66,8 +67,6 @@ public override void OnNetworkSpawn()
6667
Debug.LogError("CameraControl not found on the Main Camera or Main Camera is missing.");
6768
}
6869

69-
GameplayEventHandler.OnBlockPlayerControls += OnBlockPlayerControls;
70-
7170
base.OnNetworkSpawn();
7271
}
7372

@@ -85,7 +84,6 @@ public override void OnNetworkDespawn()
8584
cameraControl.SetTransform(null);
8685
}
8786

88-
GameplayEventHandler.OnBlockPlayerControls -= OnBlockPlayerControls;
8987
m_TopUIController?.RemovePlayer(gameObject);
9088
}
9189

@@ -116,12 +114,12 @@ void OnTransformUpdate()
116114

117115
void OnPlayerNameChanged(FixedString32Bytes previousValue, FixedString32Bytes newValue)
118116
{
119-
m_TopUIController.AddPlayer(gameObject, newValue.Value);
117+
m_TopUIController.AddOrUpdatePlayer(gameObject, newValue.Value,m_PlayerId.Value.Value);
120118
}
121119

122-
void OnBlockPlayerControls(bool blockInput)
120+
void OnPlayerIdChanged(FixedString32Bytes previousValue, FixedString32Bytes newValue)
123121
{
124-
m_PlayerInput.enabled = !blockInput;
122+
m_TopUIController.AddOrUpdatePlayer(gameObject, m_PlayerName.Value.Value,newValue.Value);
125123
}
126124

127125
public void NetworkUpdate(NetworkUpdateStage updateStage)

Basic/DistributedAuthoritySocialHub/Assets/Scripts/Services/ServicesHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ async void LeaveSession()
129129
}
130130
}
131131

132-
void SignInFailed(RequestFailedException obj)
132+
void SignInFailed(RequestFailedException e)
133133
{
134-
Debug.LogWarning($"Sign in via Authentication failed: obj.ErrorCode {obj.ErrorCode}");
134+
Debug.LogWarning($"Sign in via Authentication failed: obj.ErrorCode {e.ErrorCode}");
135135
}
136136

137137
void RemovedFromSession()

Basic/DistributedAuthoritySocialHub/Assets/Scripts/Services/Unity.Multiplayer.Samples.SocialHub.Services.asmdef

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"GUID:6087a74f6015aae4daed9a2577a7596c",
99
"GUID:1491147abca9d7d4bb7105af628b223e",
1010
"GUID:707bb6c7c4ef140eeac239b4f8251af8",
11-
"GUID:75469ad4d38634e559750d17036d5f7c"
11+
"GUID:75469ad4d38634e559750d17036d5f7c",
12+
"GUID:86923d8926a1f4aca9fcdd3f0097bfd7"
1213
],
1314
"includePlatforms": [],
1415
"excludePlatforms": [],
@@ -19,4 +20,4 @@
1920
"defineConstraints": [],
2021
"versionDefines": [],
2122
"noEngineReferences": false
22-
}
23+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using UnityEngine;
2+
using Unity.Netcode;
3+
using Unity.Multiplayer.Samples.SocialHub.GameManagement;
4+
5+
namespace Unity.Multiplayer.Samples.SocialHub.Services
6+
{
7+
class Vivox3DPositioning : NetworkBehaviour
8+
{
9+
bool m_Initialized;
10+
float m_NextPosUpdate;
11+
12+
public override void OnNetworkSpawn()
13+
{
14+
base.OnNetworkSpawn();
15+
if (!HasAuthority)
16+
{
17+
enabled = false;
18+
return;
19+
}
20+
21+
GameplayEventHandler.OnChatIsReady += OnChatIsReady;
22+
GameplayEventHandler.OnExitedSession += OnExitSession;
23+
}
24+
25+
void OnChatIsReady(bool chatIsReady, string channelName)
26+
{
27+
m_Initialized = chatIsReady;
28+
}
29+
30+
void OnExitSession()
31+
{
32+
m_Initialized = false;
33+
}
34+
35+
void Update()
36+
{
37+
if (!m_Initialized)
38+
{
39+
return;
40+
}
41+
42+
if (Time.time > m_NextPosUpdate)
43+
{
44+
VivoxManager.Instance.SetPlayer3DPosition(gameObject);
45+
m_NextPosUpdate = Time.time + 0.3f;
46+
}
47+
}
48+
49+
public override void OnNetworkDespawn()
50+
{
51+
base.OnNetworkDespawn();
52+
GameplayEventHandler.OnChatIsReady -= OnChatIsReady;
53+
GameplayEventHandler.OnExitedSession -= OnExitSession;
54+
}
55+
}
56+
}

Basic/DistributedAuthoritySocialHub/Assets/Scripts/Services/Vivox3DPositioning.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)