Skip to content

Commit

Permalink
feat(NetworkManager): Clear Spawnable Prefabs button (#3619)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischa committed Oct 8, 2024
1 parent 6f4cc8e commit ebcb4c4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Assets/Mirror/Editor/NetworkManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ 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.
if (GUILayout.Button("Clear Spawnable Prefabs"))
{
ClearNetworkIdentities();
}
}

void ScanForNetworkIdentities()
Expand Down Expand Up @@ -117,6 +124,20 @@ 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 ebcb4c4

Please sign in to comment.