feat(NetworkManager): Clear Spawnable Prefabs button (#3619) (#3915)

* feat(NetworkManager): Clear Spawnable Prefabs button (#3619)

* Update Assets/Mirror/Editor/NetworkManagerEditor.cs

Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>

---------

Co-authored-by: mischa <info@noobtuts.com>
Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>
This commit is contained in:
mischa 2024-10-08 18:27:52 +02:00 committed by GitHub
parent 2d3c1e8ba1
commit dec47b7b7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,6 +50,15 @@ public override void OnInspectorGUI()
{
ScanForNetworkIdentities();
}
// clicking the Populate button in a large project can add hundreds of entries.
// have a clear button in case that wasn't intended.
GUI.enabled = networkManager.spawnPrefabs.Count > 0;
if (GUILayout.Button("Clear Spawnable Prefabs"))
{
ClearNetworkIdentities();
}
GUI.enabled = true;
}
void ScanForNetworkIdentities()
@ -117,6 +126,19 @@ void ScanForNetworkIdentities()
}
}
void ClearNetworkIdentities()
{
// RecordObject is needed for "*" to show up in Scene.
// however, this only saves List.Count without the entries.
Undo.RecordObject(networkManager, "NetworkManager: cleared prefabs");
// add the entries
networkManager.spawnPrefabs.Clear();
// SetDirty is required to save the individual entries properly.
EditorUtility.SetDirty(target);
}
static void DrawHeader(Rect headerRect)
{
GUI.Label(headerRect, "Registered Spawnable Prefabs:");