浏览代码

Local User Audio UI hooked into listening for LocalUser.HasVoice.

Added Mute Toggle Button,
Added Volume Button
/main/staging/vivox_UI
当前提交
60ca6111
共有 11 个文件被更改,包括 169 次插入73 次删除
  1. 63
      Assets/Prefabs/UI/UserCardPanel.prefab
  2. 10
      Assets/Scenes/mainScene.unity
  3. 4
      Assets/Scripts/Game/GameManager.cs
  4. 58
      Assets/Scripts/Game/LobbyUser.cs
  5. 1
      Assets/Scripts/Infrastructure/Messenger.cs
  6. 35
      Assets/Scripts/UI/InLobbyUserUI.cs
  7. 12
      Assets/Scripts/UI/LobbyUserVolumeUI.cs
  8. 23
      Assets/Scripts/UI/MuteUI.cs
  9. 2
      ProjectSettings/UnityConnectSettings.asset
  10. 23
      Assets/Scripts/Game/LocalUserVolume.cs
  11. 11
      Assets/Scripts/Game/LocalUserVolume.cs.meta

63
Assets/Prefabs/UI/UserCardPanel.prefab


m_StatusText: {fileID: 3667934756810823183}
m_EmoteText: {fileID: 7097926522474954833}
m_HostIcon: {fileID: 2063326445664711249}
m_MuteButton: {fileID: 0}
m_MuteUI: {fileID: 5371667691979465528}
m_lobbyUserVolumeUI: {fileID: 7750493951695561362}
--- !u!114 &788426075660952210
MonoBehaviour:
m_ObjectHideFlags: 0

- component: {fileID: 7240929418107909207}
- component: {fileID: 5467963549174563591}
- component: {fileID: 5371667691979465528}
- component: {fileID: 5564390157418853622}
m_Layer: 5
m_Name: MuteArea
m_TagString: Untagged

m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_voiceRings: {fileID: 1287953984161108202}
--- !u!225 &5564390157418853622
CanvasGroup:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3010031715874034773}
m_Enabled: 1
m_Alpha: 1
m_Interactable: 0
m_BlocksRaycasts: 0
m_IgnoreParentGroups: 0
--- !u!1 &3079367817526768243
GameObject:
m_ObjectHideFlags: 0

m_Group: {fileID: 0}
onValueChanged:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 5235189765028238254}
m_TargetAssemblyTypeName: LobbyRelaySample.UI.InLobbyUserUI, LobbyRelaySample
m_MethodName: OnMuteToggled
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_IsOn: 0
--- !u!222 &1712551819190407003
CanvasRenderer:

- component: {fileID: 478472562358024413}
- component: {fileID: 1918995816743806069}
- component: {fileID: 7750493951695561362}
- component: {fileID: 5190888420783209525}
m_Layer: 5
m_Name: VolumeArea
m_TagString: Untagged

m_Script: {fileID: 11500000, guid: a06ec4a4943ad514da7a222eacb66528, type: 3}
m_Name:
m_EditorClassIdentifier:
m_onVisibilityChange:
m_PersistentCalls:
m_Calls: []
--- !u!225 &5190888420783209525
CanvasGroup:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4809966060551735762}
m_Enabled: 1
m_Alpha: 1
m_Interactable: 1
m_BlocksRaycasts: 1
m_IgnoreParentGroups: 0
--- !u!1 &5448682293735175078
GameObject:
m_ObjectHideFlags: 0

m_Value: 0
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 5235189765028238254}
m_TargetAssemblyTypeName: LobbyRelaySample.UI.InLobbyUserUI, LobbyRelaySample
m_MethodName: OnVolumeSlide
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!1 &6130740818904467730
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 4467506543349070405}
- component: {fileID: 2063326445664711249}
m_Layer: 5
m_Name: Image
m_Name: HostIcon
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

10
Assets/Scenes/mainScene.unity


objectReference: {fileID: 0}
- target: {fileID: 2637199316291327119, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: -12.499985
value: -12.5
objectReference: {fileID: 0}
- target: {fileID: 2637199316850714325, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_BlocksRaycasts

objectReference: {fileID: 0}
- target: {fileID: 4822032080772604407, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.x
value: -0.000018075109
value: -0.000061035156
value: -0.14124535
value: -0.000061035156
objectReference: {fileID: 0}
- target: {fileID: 4824240073023402834, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y

- target: {fileID: 5674629351396617348, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_Alpha
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5763389493791200136, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5784287561701313075, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y

4
Assets/Scripts/Game/GameManager.cs


m_localLobby.CountDownTime = 0;
SetUserLobbyState();
}
else if (type == MessageType.SetPlayerSound)
{
var playerSound = (LobbyUserAudio)msg;
}
}
private void SetGameState(GameState state)

58
Assets/Scripts/Game/LobbyUser.cs


using System;
using UnityEngine;
namespace LobbyRelaySample
{

[Serializable]
public class LobbyUser : Observed<LobbyUser>
{
public LobbyUser(bool isHost = false, string displayName = null, string id = null, EmoteType emote = EmoteType.None, UserStatus userStatus = UserStatus.Menu, bool hasVoice = false, bool muted = false, float volume = 0)
public LobbyUser(bool isHost = false, string displayName = null, string id = null, EmoteType emote = EmoteType.None, UserStatus userStatus = UserStatus.Menu, bool hasVoice = false)
m_data = new UserData(isHost, displayName, id, emote, userStatus, hasVoice, muted, volume);
m_data = new UserData(isHost, displayName, id, emote, userStatus, hasVoice);
}
#region Local UserData

public EmoteType Emote { get; set; }
public UserStatus UserStatus { get; set; }
public bool HasVoice { get; set; }
public bool Muted { get; set; }
public float UserVolume { get; set; }
public UserData(bool isHost, string displayName, string id, EmoteType emote, UserStatus userStatus, bool hasVoice, bool muted, float userVolume)
public UserData(bool isHost, string displayName, string id, EmoteType emote, UserStatus userStatus, bool hasVoice)
{
IsHost = isHost;
DisplayName = displayName;

HasVoice = hasVoice;
Muted = muted;
UserVolume = userVolume;
}
}

{
m_data = new UserData(false, m_data.DisplayName, m_data.ID, EmoteType.None, UserStatus.Menu, false, false, 0); // ID and DisplayName should persist since this might be the local user.
m_data = new UserData(false, m_data.DisplayName, m_data.ID, EmoteType.None, UserStatus.Menu, false); // ID and DisplayName should persist since this might be the local user.
}
#endregion

Emote = 4,
ID = 8,
UserStatus = 16,
HasVoice = 32,
Muted = 64,
Volume = 128
HasVoice = 32
//TODO Add in lobbyUsers Voice Activity for animation?
}
private UserMembers m_lastChanged;

public bool HasVoice
{
get { return m_data.Muted; }
get { return m_data.HasVoice; }
if (m_data.Muted != value)
if (m_data.HasVoice != value)
m_data.Muted = value;
m_data.HasVoice = value;
m_lastChanged = UserMembers.HasVoice;
OnChanged(this);
}

public bool Muted
{
get { return m_data.Muted; }
set
{
if (m_data.Muted != value)
{
m_data.Muted = value;
m_lastChanged = UserMembers.Muted;
OnChanged(this);
}
}
}
public float Volume
{
get { return m_data.UserVolume; }
set
{
if (Math.Abs(m_data.UserVolume - value) > 0.05f)
{
m_data.UserVolume = value;
m_lastChanged = UserMembers.Volume;
OnChanged(this);
}
}
}
public override void CopyObserved(LobbyUser observed)
{
UserData data = observed.m_data;

(m_data.ID == data.ID ? 0 : (int)UserMembers.ID) |
(m_data.Emote == data.Emote ? 0 : (int)UserMembers.Emote) |
(m_data.UserStatus == data.UserStatus ? 0 : (int)UserMembers.UserStatus) |
(m_data.HasVoice == data.HasVoice ? 0 : (int)UserMembers.HasVoice) |
(m_data.Muted == data.Muted ? 0 : (int)UserMembers.Muted) |
(Math.Abs(m_data.UserVolume - data.UserVolume) < 0.05f ? 0 : (int)UserMembers.Volume);
(m_data.HasVoice == data.HasVoice ? 0 : (int)UserMembers.HasVoice);
if (lastChanged == 0) // Ensure something actually changed.
return;

1
Assets/Scripts/Infrastructure/Messenger.cs


StartCountdown = 9,
CancelCountdown = 10,
ConfirmInGameState = 11,
SetPlayerSound = 12
}
/// <summary>

35
Assets/Scripts/UI/InLobbyUserUI.cs


[SerializeField]
MuteUI m_MuteUI;
LobbyUserAudio m_userAudio = new LobbyUserAudio("None");
public bool IsAssigned => UserId != null;

m_observer = GetComponent<LobbyUserObserver>();
m_observer.BeginObserving(myLobbyUser);
UserId = myLobbyUser.ID;
m_userAudio = new LobbyUserAudio(UserId);
}
public void OnUserLeft()

m_observer.EndObserving();
}
m_userAudio.Muted = muted;
Locator.Get.Messenger.OnReceiveMessage(MessageType.SetPlayerSound, m_userAudio);
m_userAudio.UserVolume = volume;
Locator.Get.Messenger.OnReceiveMessage(MessageType.SetPlayerSound, m_userAudio);
}
public override void ObservedUpdated(LobbyUser observed)

m_EmoteText.SetText(observed.Emote.GetString());
// m_MuteUI.Show();
SetAudioState(observed.HasVoice);
/// <summary>
/// Disable or show the Volume Icons in sync with the package.
/// </summary>
void SetAudioState(bool hasVoice)
{
if (hasVoice)
{
m_MuteUI.EnableVoice();
m_lobbyUserVolumeUI.EnableVoice();
}
else
{
m_MuteUI.DisableVoice();
m_lobbyUserVolumeUI.DisableVoice();
}
}
string SetStatusFancy(UserStatus status)
{
switch (status)

12
Assets/Scripts/UI/LobbyUserVolumeUI.cs


namespace LobbyRelaySample.UI
{
public class LobbyUserVolumeUI : MonoBehaviour
public class LobbyUserVolumeUI : UIPanelBase
public void EnableVoice()
{
Show();
}
public void DisableVoice()
{
Hide();
}
}

23
Assets/Scripts/UI/MuteUI.cs


public void DisableVoice()
{
Hide(1);
Hide(0.4f);
/// <summary>
/// Controls the visibility of the volume rings to show activity levels of the voice channel on this user.
/// </summary>
/// <param name="normalizedVolume"></param>
public void OnSoundDetected(float normalizedVolume)
{
m_voiceRings.alpha = normalizedVolume;
}
/* TODO : If we can hook in the volume from a user, we can plug it in here.
/// <summary>
/// Controls the visibility of the volume rings to show activity levels of the voice channel on this user.
/// </summary>
/// <param name="normalizedVolume"></param>
public void OnSoundDetected(float normalizedVolume)
{
m_voiceRings.alpha = normalizedVolume;
}
*/
}
}

2
ProjectSettings/UnityConnectSettings.asset


m_Enabled: 0
m_TestMode: 0
UnityAnalyticsSettings:
m_Enabled: 0
m_Enabled: 1
m_TestMode: 0
m_InitializeOnStartup: 1
UnityAdsSettings:

23
Assets/Scripts/Game/LocalUserVolume.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LobbyRelaySample
{
[SerializeField]
public class LobbyUserAudio
{
public string ID { get; private set; }
public bool HasVoice;
public bool Muted;
public float UserVolume;
public LobbyUserAudio(string userID)
{
ID = userID;
HasVoice = false;
Muted = false;
UserVolume = 1;
}
}
}

11
Assets/Scripts/Game/LocalUserVolume.cs.meta


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