O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required