64 lines
1.9 KiB
C#
Raw Normal View History

2025-09-19 14:56:58 +05:00
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace BulletHellTemplate
{
/// <summary>
/// Manages the frame selection and application process in the UI.
/// </summary>
public class FramesEntry : MonoBehaviour
{
[Header("UI Components")]
[Tooltip("Displays the frame image.")]
public Image icon;
[Tooltip("Highlights the selected frame.")]
public Image selected;
[Tooltip("Displays the name of the frame.")]
public TextMeshProUGUI frameName;
private string frameId;
/// <summary>
/// Sets the frame information for this entry.
/// </summary>
/// <param name="_frameId">The ID of the frame to set.</param>
public void SetFrameInfo(string _frameId)
{
frameId = _frameId;
}
/// <summary>
/// Applies the frame locally when clicked. This method does not synchronize with the server.
/// </summary>
public void OnClickChangeFrame()
{
PlayerSave.SetPlayerFrame(frameId);
UIProfileMenu.Singleton.LoadProfile();
UIMainMenu.Singleton.LoadPlayerInfo();
UIProfileMenu.Singleton.OnChangeFrame.Invoke();
}
/// <summary>
/// Applies the frame locally and synchronizes the change with the server when clicked.
/// </summary>
public async void OnClickChangeFrameOnline()
{
// Set the frame locally
PlayerSave.SetPlayerFrame(frameId);
// Update UI elements
UIProfileMenu.Singleton.LoadProfile();
UIMainMenu.Singleton.LoadPlayerInfo();
// Update the frame in the Firestore database
await BackendManager.Singleton.UpdatePlayerFrame(frameId);
// Invoke event for successful frame change
UIProfileMenu.Singleton.OnChangeFrame.Invoke();
}
}
}