48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Ashwild.Network;
|
|
|
|
namespace Ashwild.UI
|
|
{
|
|
public class SavePanel : UIPanel
|
|
{
|
|
[Header("Save Slots")]
|
|
[SerializeField] private Button slot1Button;
|
|
[SerializeField] private Button slot2Button;
|
|
[SerializeField] private Button slot3Button;
|
|
|
|
[Header("Navigation")]
|
|
[SerializeField] private Button backButton;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
slot1Button.onClick.AddListener(() => LoadGame(0));
|
|
slot2Button.onClick.AddListener(() => LoadGame(1));
|
|
slot3Button.onClick.AddListener(() => LoadGame(2));
|
|
backButton.onClick.AddListener(() => UIManager.Instance.Back());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Records the chosen slot and launches a hosted multiplayer session. The game scene
|
|
/// to load is owned by NetworkSessionManager (single source of truth), so it is not
|
|
/// duplicated here.
|
|
/// </summary>
|
|
private void LoadGame(int slotIndex)
|
|
{
|
|
// Future: SaveManager.Instance.Load(slotIndex) before launching.
|
|
GameSession.SelectedSlot = slotIndex;
|
|
GameSession.Mode = GameSession.LaunchMode.Host;
|
|
|
|
if (NetworkSessionManager.Instance == null)
|
|
{
|
|
Debug.LogError("[SavePanel] NetworkSessionManager introuvable — la MenuScene doit contenir le NetworkManager.", this);
|
|
return;
|
|
}
|
|
|
|
// Hosting brings the server up, then loads the game scene over the network.
|
|
NetworkSessionManager.Instance.HostSession();
|
|
}
|
|
}
|
|
}
|