Skip to content

Commit

Permalink
feat(NetworkManager): Clear Spawnable Prefabs button (#3619) (#3915)
Browse files Browse the repository at this point in the history
* feat(NetworkManager): Clear Spawnable Prefabs button (#3619)

* Update Assets/Mirror/Editor/NetworkManagerEditor.cs

Co-authored-by: MrGadget <[email protected]>

---------

Co-authored-by: mischa <[email protected]>
Co-authored-by: MrGadget <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent 2d3c1e8 commit dec47b7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Assets/Mirror/Editor/NetworkManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:");
Expand Down

0 comments on commit dec47b7

Please sign in to comment.