Skip to content

Commit 7fd3b5d

Browse files
committed
Update multiplayer editor script to test mute/unmute for all and edit/view mode for all
1 parent 2390667 commit 7fd3b5d

File tree

1 file changed

+53
-16
lines changed

1 file changed

+53
-16
lines changed

Diff for: Assets/Editor/MultiplayerManagerEditor.cs

+53-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using OpenBrush.Multiplayer;
55
using System.Threading.Tasks;
66
using System.ComponentModel.Composition;
7+
using System.Collections.Generic;
78

89
#if UNITY_EDITOR
910
[CustomEditor(typeof(MultiplayerManager))]
@@ -16,6 +17,8 @@ public class MultiplayerManagerInspector : Editor
1617
private bool isPrivate = false;
1718
private int maxPlayers = 4;
1819
private bool voiceDisabled = false;
20+
private Dictionary<int, bool> muteStates = new Dictionary<int, bool>();
21+
private Dictionary<int, bool> viewOnlyStates = new Dictionary<int, bool>();
1922

2023
public override void OnInspectorGUI()
2124
{
@@ -107,27 +110,61 @@ public override void OnInspectorGUI()
107110
EditorGUILayout.LabelField($"{ownership}");
108111
EditorGUILayout.EndHorizontal();
109112

110-
//Remote Users
111-
string remoteUsersRegistered = "";
112-
if (multiplayerManager.m_RemotePlayers != null && multiplayerManager.m_RemotePlayers.List.Count > 0)
113+
// Show the remote players
114+
GUILayout.Space(10);
115+
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
116+
117+
EditorGUILayout.LabelField("Remote Players", EditorStyles.boldLabel);
118+
if (multiplayerManager.m_RemotePlayers != null &&
119+
multiplayerManager.m_RemotePlayers.List.Count > 0)
113120
{
114-
remoteUsersRegistered = "UserIds:[ ";
121+
// Then when iterating:
115122
foreach (var remotePlayer in multiplayerManager.m_RemotePlayers.List)
116123
{
117-
remoteUsersRegistered += remotePlayer.PlayerId.ToString() + ",";
124+
int playerId = remotePlayer.PlayerId; // now an int
125+
126+
// Ensure our dictionaries have entries for this playerId
127+
if (!muteStates.ContainsKey(playerId))
128+
{
129+
muteStates[playerId] = false;
130+
}
131+
if (!viewOnlyStates.ContainsKey(playerId))
132+
{
133+
viewOnlyStates[playerId] = false;
134+
}
135+
136+
EditorGUILayout.BeginHorizontal();
137+
EditorGUILayout.LabelField($"Player: {playerId}");
138+
139+
//mute/unmute
140+
bool currentMuteState = muteStates[playerId];
141+
string muteButtonLabel = currentMuteState ? "Unmute" : "Mute";
142+
if (GUILayout.Button(muteButtonLabel))
143+
{
144+
bool newMuteState = !currentMuteState;
145+
MultiplayerManager.m_Instance.MutePlayerForAll(newMuteState, playerId);
146+
muteStates[playerId] = newMuteState;
147+
EditorUtility.SetDirty(target);
148+
}
149+
150+
//viewOnly/edit
151+
bool currentViewState = viewOnlyStates[playerId];
152+
string viewButtonLabel = currentViewState ? "Disable ViewOnly" : "Enable ViewOnly";
153+
if (GUILayout.Button(viewButtonLabel))
154+
{
155+
bool newViewState = !currentViewState;
156+
MultiplayerManager.m_Instance.ToggleUserViewOnlyMode(newViewState, playerId);
157+
viewOnlyStates[playerId] = newViewState;
158+
EditorUtility.SetDirty(target);
159+
}
160+
161+
EditorGUILayout.EndHorizontal();
118162
}
119-
remoteUsersRegistered += "]";
120163
}
121-
else remoteUsersRegistered = "Not Assigned";
122-
123-
//Registered remote players
124-
125-
EditorGUILayout.BeginHorizontal();
126-
GUILayout.Label("Registered Remote Players IDs:", EditorStyles.boldLabel);
127-
EditorGUILayout.LabelField($"{remoteUsersRegistered}");
128-
EditorGUILayout.EndHorizontal();
129-
130-
164+
else
165+
{
166+
EditorGUILayout.LabelField("No remote players found.");
167+
}
131168

132169
Repaint();
133170

0 commit comments

Comments
 (0)