Documentation for the Unity C# Library
Loading...
Searching...
No Matches
LoginScreen.cs
Go to the documentation of this file.
1using System;
2using TMPro;
3using UnityEngine;
4using UnityEngine.UI;
5
6namespace PixoVR.Login
7{
8 public enum Mode
9 {
10 Unknown,
11 Offline,
12 Online
13 }
14
15 public class LoginScreen : MonoBehaviour
16 {
17 [SerializeField] private TMP_InputField _loginInputField;
18 [SerializeField] private TMP_InputField _passwordInputField;
19 [SerializeField] private Toggle _rememberMeToggle;
20 [SerializeField] private GameObject _errorMessageGameObject;
21 [SerializeField] private GameObject _OfflineModeMessageGameObject;
22 [SerializeField] private TMP_Text _errorMessageText;
23 [SerializeField] private Button _loginButton;
25 public event Action<string, string> LoginButtonClicked;
26 public event Action<bool> RememberMeToggleValueChanged;
27
28 private void OnEnable()
29 {
30 _rememberMeToggle.onValueChanged.AddListener(OnRememberMeToggleValueChanged);
31 _loginButton.onClick.AddListener(OnLoginButtonClicked);
32 }
33
34 private void OnDisable()
35 {
36 _rememberMeToggle.onValueChanged.RemoveListener(OnRememberMeToggleValueChanged);
37 _loginButton.onClick.RemoveListener(OnLoginButtonClicked);
38 }
39
40 private void Start()
41 {
42 _errorMessageGameObject.gameObject.SetActive(false);
43 }
45 private void OnRememberMeToggleValueChanged(bool isToggleOn)
46 {
47 RememberMeToggleValueChanged?.Invoke(isToggleOn);
48 }
50 private void OnLoginButtonClicked()
51 {
52 if (string.IsNullOrEmpty(_loginInputField.text) || string.IsNullOrEmpty(_passwordInputField.text))
53 return;
54
56 }
57
58 public void ShowRememberedCredentials(string login, string password)
59 {
60 _loginInputField.text = login;
61 _passwordInputField.text = password;
62 }
63
64 public void SetRememberMe(bool isOn)
65 {
66 _rememberMeToggle.SetIsOnWithoutNotify(isOn);
67 }
68
69 public void ShowErrorMessage(string message)
70 {
71 _errorMessageGameObject.SetActive(true);
72 _errorMessageText.text = message;
73 }
74
75 public void SetOnlineMode(Mode mode)
76 {
77 _loginInputField.interactable = mode == Mode.Online;
78 _passwordInputField.interactable = mode == Mode.Online;
79 _rememberMeToggle.interactable = mode == Mode.Online;
80 _OfflineModeMessageGameObject.SetActive(mode == Mode.Offline);
81 _loginButton.interactable = mode == Mode.Online;
82 }
83 }
84}
TMP_Text _errorMessageText
[SerializeField]
GameObject _errorMessageGameObject
[SerializeField]
Toggle _rememberMeToggle
[SerializeField]
void ShowRememberedCredentials(string login, string password)
void SetOnlineMode(Mode mode)
Action< bool > RememberMeToggleValueChanged
void ShowErrorMessage(string message)
void OnRememberMeToggleValueChanged(bool isToggleOn)
TMP_InputField _loginInputField
[SerializeField]
Button _loginButton
[SerializeField]
GameObject _OfflineModeMessageGameObject
[SerializeField]
void SetRememberMe(bool isOn)
TMP_InputField _passwordInputField
[SerializeField]
Action< string, string > LoginButtonClicked