Files
unity-application/Assets/Common/Scripts/UserButton.cs
2023-05-12 11:53:17 +00:00

61 lines
1.5 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Handles actions when a user presses the account button (upper right corner)
/// </summary>
public class UserButton : MonoBehaviour
{
/// <summary>
/// UI reference to the avatar object
/// </summary>
public Image avatar;
/// <summary>
/// UI reference to the username object
/// </summary>
public TMP_Text username;
/// <summary>
/// UI reference to the dropdown box with all options
/// </summary>
public GameObject dropdownBox;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
PersistentDataController.GetInstance().Load();
User user = UserList.GetCurrentUser();
avatar.sprite = user.GetAvatar();
username.text = user.GetUsername();
dropdownBox.SetActive(false);
}
/// <summary>
/// Change to the UserProgressScreen scene
/// </summary>
public void OpenProgressCallback()
{
SystemController.GetInstance().LoadNextScene("Accounts/Scenes/UserProgressScreen");
}
/// <summary>
/// Change to the ChangeUserScreen scene
/// </summary>
public void ChangeUserCallback()
{
SystemController.GetInstance().LoadNextScene("Accounts/Scenes/ChangeUserScreen");
}
/// <summary>
/// Toggle the dropdown box
/// </summary>
public void ToggleDropdown()
{
dropdownBox.SetActive(!dropdownBox.activeSelf);
}
}