using System; using UnityEngine; namespace LobbyRelaySample.UI { /// /// Current user statea /// Set as a flag to allow for the unity inspector to select multiples for various UI features. /// [Flags] public enum UserPermission { Client = 1, Host = 2 } /// /// Shows the UI when the lobbyuser is set to the matching conditions. /// [RequireComponent(typeof(LobbyUserObserver))] public class UserStateVisibilityUI : ObserverPanel { public UserStatus ShowThisWhen; public UserPermission Permissions; public override void ObservedUpdated(LobbyUser observed) { var hasStatusFlags = ShowThisWhen.HasFlag(observed.UserStatus); var hasPermissions = false; if (Permissions.HasFlag(UserPermission.Host) && observed.IsHost) { hasPermissions = true; } else if (Permissions.HasFlag(UserPermission.Client) && !observed.IsHost) { hasPermissions = true; } if (hasStatusFlags && hasPermissions) Show(); else Hide(); } } }