4
4
using OpenBrush . Multiplayer ;
5
5
using System . Threading . Tasks ;
6
6
using System . ComponentModel . Composition ;
7
+ using System . Collections . Generic ;
7
8
8
9
#if UNITY_EDITOR
9
10
[ CustomEditor ( typeof ( MultiplayerManager ) ) ]
@@ -16,6 +17,8 @@ public class MultiplayerManagerInspector : Editor
16
17
private bool isPrivate = false ;
17
18
private int maxPlayers = 4 ;
18
19
private bool voiceDisabled = false ;
20
+ private Dictionary < int , bool > muteStates = new Dictionary < int , bool > ( ) ;
21
+ private Dictionary < int , bool > viewOnlyStates = new Dictionary < int , bool > ( ) ;
19
22
20
23
public override void OnInspectorGUI ( )
21
24
{
@@ -107,27 +110,61 @@ public override void OnInspectorGUI()
107
110
EditorGUILayout . LabelField ( $ "{ ownership } ") ;
108
111
EditorGUILayout . EndHorizontal ( ) ;
109
112
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 )
113
120
{
114
- remoteUsersRegistered = "UserIds:[ " ;
121
+ // Then when iterating:
115
122
foreach ( var remotePlayer in multiplayerManager . m_RemotePlayers . List )
116
123
{
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 ( ) ;
118
162
}
119
- remoteUsersRegistered += "]" ;
120
163
}
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
+ }
131
168
132
169
Repaint ( ) ;
133
170
0 commit comments