64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BulletHellTemplate
|
|
{
|
|
/// <summary>
|
|
/// Manages the icon selection and application process in the UI.
|
|
/// </summary>
|
|
public class IconsEntry : MonoBehaviour
|
|
{
|
|
[Header("UI Components")]
|
|
[Tooltip("Displays the icon image.")]
|
|
public Image icon;
|
|
|
|
[Tooltip("Highlights the selected icon.")]
|
|
public Image selected;
|
|
|
|
[Tooltip("Displays the name of the icon.")]
|
|
public TextMeshProUGUI iconName;
|
|
|
|
private string iconId;
|
|
|
|
/// <summary>
|
|
/// Sets the icon information for this entry.
|
|
/// </summary>
|
|
/// <param name="_iconId">The ID of the icon to set.</param>
|
|
public void SetIconInfo(string _iconId)
|
|
{
|
|
iconId = _iconId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applies the icon locally when clicked. This method does not synchronize with the server.
|
|
/// </summary>
|
|
public void OnClickChangeIcon()
|
|
{
|
|
PlayerSave.SetPlayerIcon(iconId);
|
|
UIProfileMenu.Singleton.LoadProfile();
|
|
UIMainMenu.Singleton.LoadPlayerInfo();
|
|
UIProfileMenu.Singleton.OnChangeIcon.Invoke();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applies the icon locally and synchronizes the change with the server when clicked.
|
|
/// </summary>
|
|
public async void OnClickChangeIconOnline()
|
|
{
|
|
// Set the icon locally
|
|
PlayerSave.SetPlayerIcon(iconId);
|
|
|
|
// Update UI elements
|
|
UIProfileMenu.Singleton.LoadProfile();
|
|
UIMainMenu.Singleton.LoadPlayerInfo();
|
|
|
|
// Update the icon in the Firestore database
|
|
await BackendManager.Singleton.UpdatePlayerIcon(iconId);
|
|
|
|
// Invoke event for successful icon change
|
|
UIProfileMenu.Singleton.OnChangeIcon.Invoke();
|
|
}
|
|
}
|
|
}
|