67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using FishNet.Connection;
|
|
using FishNet.Object;
|
|
using Managers;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class Room
|
|
{
|
|
#region Field
|
|
public Room() { }
|
|
public Room(string name, string password, bool lockOnStart, int playerCount)
|
|
{
|
|
this.name = name;
|
|
this.maxPlayers = playerCount;
|
|
this.lockOnStart = lockOnStart;
|
|
this.hasPassword = !string.IsNullOrEmpty(password);
|
|
}
|
|
|
|
public string name;
|
|
public int maxPlayers;
|
|
public bool hasPassword;
|
|
public bool lockOnStart;
|
|
public bool isStarted;
|
|
|
|
public List<NetworkConnection> Members = new();
|
|
public List<NetworkObject> MemberIds = new();
|
|
public List<NetworkObject> StartedMembers = new();
|
|
|
|
[System.NonSerialized] public GameManager gameManager;
|
|
[System.NonSerialized] public string PasswordAuthenticator = string.Empty;
|
|
[System.NonSerialized] public HashSet<Scene> Scenes = new HashSet<Scene>();
|
|
#endregion
|
|
|
|
#region Members
|
|
public void AddMember(NetworkObject clientId)
|
|
{
|
|
if (!MemberIds.Contains(clientId))
|
|
{
|
|
MemberIds.Add(clientId);
|
|
Members.Add(clientId.Owner);
|
|
}
|
|
}
|
|
public void AddStartedMember(NetworkObject clientId)
|
|
{
|
|
if (!StartedMembers.Contains(clientId))
|
|
StartedMembers.Add(clientId);
|
|
}
|
|
public bool RemoveMember(NetworkObject clientId)
|
|
{
|
|
int index = MemberIds.IndexOf(clientId);
|
|
if (index != -1)
|
|
{
|
|
MemberIds.RemoveAt(index);
|
|
Members.Remove(clientId.Owner);
|
|
if (StartedMembers.Contains(clientId))
|
|
{
|
|
StartedMembers.Remove(clientId);
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
} |