56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Ashwild.Network;
|
|
|
|
namespace Ashwild.UI
|
|
{
|
|
/// <summary>
|
|
/// Drop-in button for the in-game pause menu: opens the Steam overlay friends list so the
|
|
/// player can invite a friend to the current session. Resolves the SteamInviteService lazily
|
|
/// at click time so it works regardless of scene/singleton initialization order.
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
[RequireComponent(typeof(Button))]
|
|
public class InviteFriendButton : MonoBehaviour
|
|
{
|
|
#region Serialized Fields
|
|
|
|
[Header("References")]
|
|
[Tooltip("The button that opens the Steam invite overlay. Auto-found if left empty.")]
|
|
[SerializeField] private Button button;
|
|
|
|
#endregion
|
|
|
|
#region Unity Lifecycle
|
|
|
|
/// <summary>
|
|
/// Wires the click handler.
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
if (button == null) button = GetComponent<Button>();
|
|
if (button != null) button.onClick.AddListener(OpenInviteOverlay);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Internal Helpers
|
|
|
|
/// <summary>
|
|
/// Forwards to the Steam invite service, logging if it is unavailable.
|
|
/// </summary>
|
|
private void OpenInviteOverlay()
|
|
{
|
|
if (SteamInviteService.Instance == null)
|
|
{
|
|
Debug.LogError("[InviteFriendButton] SteamInviteService introuvable — ajoute-le sur le NetworkManager.", this);
|
|
return;
|
|
}
|
|
|
|
SteamInviteService.Instance.OpenInviteOverlay();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|