Skip to content

Commit b9249a2

Browse files
committed
Added registered scenes as a ordered list
1 parent b4bfd9d commit b9249a2

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

MLAPI-Editor/NetworkingManagerEditor.cs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ private void OnEnable()
9191

9292

9393
int firstLabelWidth = 50;
94-
int secondLabelWidth = 90;
95-
float secondFieldWidth = 10;
96-
int reduceFirstWidth = 45;
94+
int secondLabelWidth = networkingManager.NetworkConfig.AllowPassthroughMessages ? 90 : 0;
95+
float secondFieldWidth = networkingManager.NetworkConfig.AllowPassthroughMessages ? 10 : 0;
96+
int reduceFirstWidth = networkingManager.NetworkConfig.AllowPassthroughMessages ? 45 : 20;
9797

9898
EditorGUI.LabelField(new Rect(rect.x, rect.y, firstLabelWidth, EditorGUIUtility.singleLineHeight), "Name");
9999
EditorGUI.PropertyField(new Rect(rect.x + firstLabelWidth, rect.y, rect.width - firstLabelWidth - secondLabelWidth - secondFieldWidth - reduceFirstWidth,
100100
EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("Name"), GUIContent.none);
101101

102-
EditorGUI.LabelField(new Rect(rect.width - secondLabelWidth - secondFieldWidth, rect.y, secondLabelWidth, EditorGUIUtility.singleLineHeight), "Passthrough");
103-
EditorGUI.PropertyField(new Rect(rect.width - secondFieldWidth, rect.y, secondFieldWidth,
104-
EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("Passthrough"), GUIContent.none);
102+
if (networkingManager.NetworkConfig.AllowPassthroughMessages)
103+
{
104+
EditorGUI.LabelField(new Rect(rect.width - secondLabelWidth - secondFieldWidth, rect.y, secondLabelWidth, EditorGUIUtility.singleLineHeight), "Passthrough");
105+
EditorGUI.PropertyField(new Rect(rect.width - secondFieldWidth, rect.y, secondFieldWidth,
106+
EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("Passthrough"), GUIContent.none);
107+
}
105108
};
106109

107110
messageTypesList.drawHeaderCallback = (Rect rect) => {
@@ -118,10 +121,10 @@ private void OnEnable()
118121
int firstLabelWidth = 50;
119122
int secondLabelWidth = 40;
120123
int secondFieldWidth = 150;
121-
int thirdLabelWidth = 70;
122-
int thirdFieldWidth = 10;
124+
int thirdLabelWidth = networkingManager.NetworkConfig.EnableEncryption ? 70 : 0;
125+
int thirdFieldWidth = networkingManager.NetworkConfig.EnableEncryption ? 10 : 0;
123126
int reduceFirstWidth = 45;
124-
int reduceSecondWidth = 10;
127+
int reduceSecondWidth = networkingManager.NetworkConfig.EnableEncryption ? 10 : 0;
125128

126129
EditorGUI.LabelField(new Rect(rect.x, rect.y, firstLabelWidth, EditorGUIUtility.singleLineHeight), "Name");
127130
EditorGUI.PropertyField(new Rect(rect.x + firstLabelWidth, rect.y, rect.width - firstLabelWidth - secondLabelWidth - secondFieldWidth - thirdFieldWidth - thirdLabelWidth - reduceFirstWidth,
@@ -132,14 +135,35 @@ private void OnEnable()
132135
EditorGUI.PropertyField(new Rect(rect.width - secondFieldWidth - thirdLabelWidth - thirdFieldWidth, rect.y, secondFieldWidth - reduceSecondWidth,
133136
EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("Type"), GUIContent.none);
134137

135-
EditorGUI.LabelField(new Rect(rect.width - thirdFieldWidth - thirdLabelWidth, rect.y, thirdLabelWidth, EditorGUIUtility.singleLineHeight), "Encrypted");
136-
EditorGUI.PropertyField(new Rect(rect.width - thirdFieldWidth, rect.y, secondFieldWidth,
137-
EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("Encrypted"), GUIContent.none);
138+
if (networkingManager.NetworkConfig.EnableEncryption)
139+
{
140+
EditorGUI.LabelField(new Rect(rect.width - thirdFieldWidth - thirdLabelWidth, rect.y, thirdLabelWidth, EditorGUIUtility.singleLineHeight), "Encrypted");
141+
EditorGUI.PropertyField(new Rect(rect.width - thirdFieldWidth, rect.y, secondFieldWidth,
142+
EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("Encrypted"), GUIContent.none);
143+
}
138144
};
139145

140146
channelsList.drawHeaderCallback = (Rect rect) => {
141147
EditorGUI.LabelField(rect, "Channels (Auto Sorted)");
142148
};
149+
150+
151+
registeredScenesList = new ReorderableList(serializedObject, serializedObject.FindProperty("NetworkConfig").FindPropertyRelative("RegisteredScenes"), true, true, true, true);
152+
registeredScenesList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
153+
{
154+
SerializedProperty element = registeredScenesList.serializedProperty.GetArrayElementAtIndex(index);
155+
int firstLabelWidth = 50;
156+
int padding = 20;
157+
158+
EditorGUI.LabelField(new Rect(rect.x, rect.y, firstLabelWidth, EditorGUIUtility.singleLineHeight), "Name");
159+
EditorGUI.PropertyField(new Rect(rect.x + firstLabelWidth, rect.y, rect.width - firstLabelWidth - padding,
160+
EditorGUIUtility.singleLineHeight), element, GUIContent.none);
161+
162+
};
163+
164+
registeredScenesList.drawHeaderCallback = (Rect rect) => {
165+
EditorGUI.LabelField(rect, "Registered Scene Names (Auto Sorted)");
166+
};
143167
}
144168

145169
public override void OnInspectorGUI()
@@ -153,13 +177,21 @@ public override void OnInspectorGUI()
153177
EditorGUILayout.PropertyField(RunInBackgroundProperty);
154178
EditorGUILayout.PropertyField(LogLevelProperty);
155179

156-
EditorGUILayout.Space();
157-
networkPrefabsList.DoLayoutList();
180+
if (networkingManager.NetworkConfig.HandleObjectSpawning)
181+
{
182+
EditorGUILayout.Space();
183+
networkPrefabsList.DoLayoutList();
184+
}
158185
EditorGUILayout.Space();
159186
messageTypesList.DoLayoutList();
160187
EditorGUILayout.Space();
161188
channelsList.DoLayoutList();
162189
EditorGUILayout.Space();
190+
if (networkingManager.NetworkConfig.EnableSceneSwitching)
191+
{
192+
registeredScenesList.DoLayoutList();
193+
EditorGUILayout.Space();
194+
}
163195

164196
serializedObject.ApplyModifiedProperties();
165197
base.OnInspectorGUI();

MLAPI/Data/NetworkConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class NetworkConfig
5555
/// <summary>
5656
/// A list of SceneNames that can be used during networked games.
5757
/// </summary>
58+
[HideInInspector]
5859
public List<string> RegisteredScenes = new List<string>();
5960
/// <summary>
6061
/// A list of spawnable prefabs

0 commit comments

Comments
 (0)