Filtering results by user preference

Many game lobbies allow players to filter the results by various criteria. For example, you might hide all private rooms, or only show rooms on a certain map.

Filtering arrays

We can filter out our room list array based on the user's preference, this way the user can more easily search for a suitable game to join:

using UnityEngine; using System.Collections; using System.Linq; using System.Collections.Generic; public class Example_FilterRooms { public static RoomInfo[] FilterRooms( RoomInfo[] src, bool includeFull, Hashtable properties ) { // use a Where expression to filter out rooms that do not match the given criteria // then convert that to an array return src.Where( room => ( filterRoom( room, includeFull, ...

Get Unity Multiplayer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.