You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.6 KiB
92 lines
2.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.Services.Lobbies;
|
|
using Unity.Services.Lobbies.Models;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class EventManager : MonoBehaviour
|
|
{
|
|
public static EventManager Instance { get; private set; }
|
|
private void Awake()
|
|
{
|
|
if (Instance == null) Instance = this;
|
|
}
|
|
|
|
[SerializeField] private EventButton eventButtonPrefab;
|
|
[SerializeField] private Transform content;
|
|
|
|
[SerializeField] private RS_InputField eventName;
|
|
[SerializeField] private TMP_Dropdown playersDropdown;
|
|
[SerializeField] private TMP_Dropdown durationDropdown;
|
|
[SerializeField] private TMP_Dropdown locationDropdown;
|
|
|
|
|
|
public void JoinEvent(Lobby lobby)
|
|
{
|
|
GameManager.Instance.Loading(true);
|
|
ConnectionManager.Instance.JoinRelay(lobby.Data["joinCode"].Value, () =>
|
|
{
|
|
GameManager.Instance.LoadScene(lobby.Data["location"].Value);
|
|
});
|
|
}
|
|
|
|
public void CreateEvent()
|
|
{
|
|
string location = locationDropdown.options[locationDropdown.value].text;
|
|
string playersText = playersDropdown.options[playersDropdown.value].text;
|
|
|
|
if (location == "My Room")
|
|
{
|
|
location = LocalPlayerData.RoomID;
|
|
}
|
|
|
|
if (!int.TryParse(playersText, out int players))
|
|
{
|
|
players = 10;
|
|
}
|
|
|
|
GameManager.Instance.Loading(true);
|
|
ConnectionManager.Instance.CreateLobbyAndRelay(eventName.Text, location, players, false, () =>
|
|
{
|
|
GameManager.Instance.LoadScene(location);
|
|
});
|
|
}
|
|
|
|
public void ClearPanel()
|
|
{
|
|
foreach (Transform transform in content)
|
|
{
|
|
Destroy(transform.gameObject);
|
|
}
|
|
}
|
|
|
|
public async void Render()
|
|
{
|
|
ClearPanel();
|
|
|
|
QueryLobbiesOptions options = new QueryLobbiesOptions()
|
|
{
|
|
Count = 25,
|
|
Filters = new List<QueryFilter>()
|
|
{
|
|
new QueryFilter(QueryFilter.FieldOptions.AvailableSlots, "0", QueryFilter.OpOptions.GT)
|
|
},
|
|
Order = new List<QueryOrder>()
|
|
{
|
|
new QueryOrder(false, QueryOrder.FieldOptions.Created)
|
|
}
|
|
};
|
|
|
|
QueryResponse lobbies = await Lobbies.Instance.QueryLobbiesAsync();
|
|
|
|
foreach (var lobby in lobbies.Results)
|
|
{
|
|
if (lobby.Data["ownerId"]?.Value == LocalPlayerData.ID.ToString() || lobby.Data["isLocation"]?.Value == "1") continue;
|
|
|
|
EventButton button = Instantiate(eventButtonPrefab, content);
|
|
button.Initialize(lobby);
|
|
}
|
|
}
|
|
}
|
|
|