You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Fusion;
|
|
|
|
public class SessionListUIHandler : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI statusText;
|
|
public GameObject sessionItemListPrefab;
|
|
public VerticalLayoutGroup verticalLayoutGroup;
|
|
|
|
private List<(SessionInfoUIListItem item, Action<SessionInfo> handler)> activeItems = new();
|
|
|
|
public void ClearList()
|
|
{
|
|
foreach (var (item, handler) in activeItems)
|
|
{
|
|
item.OnJoinSession -= handler; // ✅ Correct way to unsubscribe
|
|
Destroy(item.gameObject);
|
|
}
|
|
|
|
activeItems.Clear();
|
|
statusText.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void AddToList(SessionInfo sessionInfo, Action<SessionInfo> onJoinCallback)
|
|
{
|
|
var item = Instantiate(sessionItemListPrefab, verticalLayoutGroup.transform)
|
|
.GetComponent<SessionInfoUIListItem>();
|
|
|
|
item.SetSessionInfo(sessionInfo);
|
|
item.OnJoinSession += onJoinCallback;
|
|
|
|
activeItems.Add((item, onJoinCallback)); // store pair for clean removal
|
|
}
|
|
|
|
public void ShowNoSessionsMessage(string message = "No Game Sessions Found")
|
|
{
|
|
statusText.text = message;
|
|
statusText.gameObject.SetActive(true);
|
|
}
|
|
}
|