Microphones now work locally, which doesn't seem to work. Experimenting.

This commit is contained in:
Jamie Greunbaum 2026-05-02 20:12:58 -04:00
parent 1555eb8c9f
commit eabb7f95e4
14 changed files with 349 additions and 376 deletions

File diff suppressed because one or more lines are too long

View File

@ -131,6 +131,7 @@ public class GameManagerBase : UdonSharpBehaviour
_AllowInteractionFromHostCard = true;
EnablePlayerMicrophone(true);
EnableAudienceSilencer(false);
_HostPositionMarker.SetPlayer(_CaseManager.GetHostOwner().displayName);
string[] WinningPlayers = _CaseManager.GetCurrentWinningPlayers();
@ -154,6 +155,7 @@ public class GameManagerBase : UdonSharpBehaviour
public virtual void DeinitialiseGameMode()
{
EnablePlayerMicrophone(false);
EnableAudienceSilencer(true);
_HostPositionMarker.ClearPlayer();
for (int i = 0; i < _PlayerPositionMarkers.Length; i++)

View File

@ -107,8 +107,6 @@ public class GameManagerRound1 : GameManagerBase
Display.Activate(false);
}
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(EnableAudienceSilencer), true);
_AudioManager.SendCustomNetworkEvent(NetworkEventTarget.All, "PlayMusic", MusicEventType.WhereInTheWorld);
SendCustomEventDelayedSeconds(nameof(PlaySecondPartOfThemeMusic), 3.6666666666f);

View File

@ -79,8 +79,6 @@ public class GameManagerRound2 : GameManagerBase
Display.Activate(true);
}
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(EnableAudienceSilencer), true);
_CameraControllerRound2.InitialiseCameras();
_CameraControllerRound2.DisableAllSwitchers();
_CameraControllerRound2.SwitchToModemCamera();

View File

@ -123,8 +123,6 @@ public class GameManagerRound3 : GameManagerBase
Overlay.EnableOverlayElements(false);
}
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(EnableAudienceSilencer), false);
_CameraControllerRound3.InitialiseCameras();
_CameraControllerRound3.PlayIFeelGood(true);
DeinitialiseGameplayCameraFollowers();

View File

@ -290,19 +290,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _EnteredPlayers
Data: _LocalOverlapCounter
- Name: $v
Entry: 7
Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _EnteredPlayers
Data: _LocalOverlapCounter
- Name: <UserType>k__BackingField
Entry: 7
Data: 19|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDKBase.VRCPlayerApi[], VRCSDKBase
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:

View File

@ -2,6 +2,7 @@
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon.Common;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
@ -14,31 +15,25 @@ public class Microphone : UdonSharpBehaviour
[UdonSynced] private bool _MicrophoneEnabled = false;
private VRCPlayerApi[] _EnteredPlayers = new VRCPlayerApi[MAX_PLAYERS];
private int _LocalOverlapCounter = 0;
private const float DEFAULT_VOICE_DISTANCE_NEAR = 0.0f;
private const float DEFAULT_VOICE_DISTANCE_FAR = 25.0f;
private const int MAX_PLAYERS = 100;
public override void OnDeserialization(DeserializationResult Result)
{
_EnableMicrophone_Synced();
base.OnDeserialization(Result);
}
public override void OnPlayerTriggerEnter(VRCPlayerApi Player)
{
for (int i = 0; i < _EnteredPlayers.Length; i++)
if (Player == Networking.LocalPlayer)
{
if (_EnteredPlayers[i] == null)
{
_EnteredPlayers[i] = Player;
break;
}
}
if (_MicrophoneEnabled && _LocalPlayerIsAllowedToSetMicrophone())
{
Debug.Log("[Microphone] Microphone " + gameObject.name + " is now changing volume settings for player " + Player.displayName);
Player.SetVoiceDistanceNear(_MikedVoiceDistanceNear);
Player.SetVoiceDistanceFar(_MikedVoiceDistanceFar);
_LocalOverlapCounter++;
_UpdateMicrophoneEffect();
}
base.OnPlayerTriggerEnter(Player);
@ -46,24 +41,10 @@ public class Microphone : UdonSharpBehaviour
public override void OnPlayerTriggerExit(VRCPlayerApi Player)
{
if (Player != null && Player.IsValid())
if (Player == Networking.LocalPlayer)
{
for (int i = 0; i < _EnteredPlayers.Length; i++)
{
if (_EnteredPlayers[i] == Player)
{
_EnteredPlayers[i] = null;
break;
}
}
if (_MicrophoneEnabled && _LocalPlayerIsAllowedToSetMicrophone())
{
Debug.Log("[Microphone] Microphone " + gameObject.name + " is now changing volume settings for player " + Player.displayName);
Player.SetVoiceDistanceNear(DEFAULT_VOICE_DISTANCE_NEAR);
Player.SetVoiceDistanceFar(DEFAULT_VOICE_DISTANCE_FAR);
}
_LocalOverlapCounter--;
_UpdateMicrophoneEffect();
}
base.OnPlayerTriggerExit(Player);
@ -71,21 +52,21 @@ public class Microphone : UdonSharpBehaviour
public override void OnPlayerJoined(VRCPlayerApi Player)
{
Player.SetVoiceDistanceNear(DEFAULT_VOICE_DISTANCE_NEAR);
Player.SetVoiceDistanceFar(DEFAULT_VOICE_DISTANCE_FAR);
if (Player == Networking.LocalPlayer)
{
Networking.LocalPlayer.SetVoiceDistanceNear(DEFAULT_VOICE_DISTANCE_NEAR);
Networking.LocalPlayer.SetVoiceDistanceFar(DEFAULT_VOICE_DISTANCE_FAR);
}
base.OnPlayerJoined(Player);
}
public override void OnPlayerLeft(VRCPlayerApi Player)
{
for (int i = 0; i < _EnteredPlayers.Length; i++)
if (Player == Networking.LocalPlayer)
{
if (_EnteredPlayers[i] == Player)
{
_EnteredPlayers[i] = null;
break;
}
Networking.LocalPlayer.SetVoiceDistanceNear(DEFAULT_VOICE_DISTANCE_NEAR);
Networking.LocalPlayer.SetVoiceDistanceFar(DEFAULT_VOICE_DISTANCE_FAR);
}
base.OnPlayerLeft(Player);
@ -94,30 +75,22 @@ public class Microphone : UdonSharpBehaviour
public void EnableMicrophone(bool Enable)
{
_MicrophoneEnabled = Enable;
Debug.Log("[Microphone] Microphone is now " + (Enable ? "en" : "dis") + "abled");
if (_LocalPlayerIsAllowedToSetMicrophone())
if (Networking.IsOwner(gameObject))
{
for (int i = 0; i < _EnteredPlayers.Length; i++)
{
if (_EnteredPlayers[i] != null && _EnteredPlayers[i].IsValid())
{
Debug.Log("[Microphone] Microphone " + gameObject.name + " is now " + (_MicrophoneEnabled ? "en" : "dis") + "abled; changing volume settings for player " + _EnteredPlayers[i].displayName);
_EnteredPlayers[i].SetVoiceDistanceNear(_MicrophoneEnabled ? _MikedVoiceDistanceNear : DEFAULT_VOICE_DISTANCE_NEAR);
_EnteredPlayers[i].SetVoiceDistanceFar(_MicrophoneEnabled ? _MikedVoiceDistanceFar : DEFAULT_VOICE_DISTANCE_FAR);
}
}
_MicrophoneEnabled = Enable;
_EnableMicrophone_Synced();
RequestSerialization();
}
RequestSerialization();
}
private void _EnableMicrophone_Synced()
{
_UpdateMicrophoneEffect();
}
private bool _LocalPlayerIsAllowedToSetMicrophone()
private void _UpdateMicrophoneEffect()
{
return _PermissionsPanel.IsPlayerHost(Networking.LocalPlayer) && Networking.IsOwner(gameObject);
Networking.LocalPlayer.SetVoiceDistanceNear((_MicrophoneEnabled && _LocalOverlapCounter > 0) ? _MikedVoiceDistanceNear : DEFAULT_VOICE_DISTANCE_NEAR);
Networking.LocalPlayer.SetVoiceDistanceFar((_MicrophoneEnabled && _LocalOverlapCounter > 0) ? _MikedVoiceDistanceFar : DEFAULT_VOICE_DISTANCE_FAR);
}
}

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: BoneFollower
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: ccbda9bf23e2f714c9226283c77a92e5,
serializedUdonProgramAsset: {fileID: 11400000, guid: 52ecc8a73071e8e40928c3609699fcf4,
type: 2}
udonAssembly:
assemblyError:

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: InteractToggle
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 405e38d3dfb2f514daeed0e28fbb4864,
serializedUdonProgramAsset: {fileID: 11400000, guid: 873dfce61b1514e429c92e0d2fded7de,
type: 2}
udonAssembly:
assemblyError:

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: PlayerModSetter
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: f938e6c4ff027a74da405a1f9353fd2b,
serializedUdonProgramAsset: {fileID: 11400000, guid: e81558796a212ab4d88e305e2010f24b,
type: 2}
udonAssembly:
assemblyError:

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: GlobalToggleObject
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: c49c9265a3ef24642a6a4465d0a78872,
serializedUdonProgramAsset: {fileID: 11400000, guid: 2fe8ced6184000f49bca526cd2c5891c,
type: 2}
udonAssembly:
assemblyError:

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: MasterToggleObject
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 04024a76ab1924042ba521e11cb76d91,
serializedUdonProgramAsset: {fileID: 11400000, guid: a2d01d9f36ac6df49831be249e48ecc4,
type: 2}
udonAssembly:
assemblyError:

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: TrackingDataFollower
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 17f8fbbe6cc186d4f8dbb057b01a4ec2,
serializedUdonProgramAsset: {fileID: 11400000, guid: 1b89d4552983c0448a7389decec3b555,
type: 2}
udonAssembly:
assemblyError:

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: WorldAudioSettings
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 128d924a3066b7546b2d1c73e61006ab,
serializedUdonProgramAsset: {fileID: 11400000, guid: 994b559b0f158b4499f8937980ed8694,
type: 2}
udonAssembly:
assemblyError: