Add formatting rules
This commit is contained in:
@@ -5,34 +5,56 @@ using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// UserCreationScreen scene manager
|
||||
/// </summary>
|
||||
public class UserCreationScreen : MonoBehaviour
|
||||
{
|
||||
// Max length of a username
|
||||
/// <summary>
|
||||
/// Maximum lenght of a username
|
||||
/// </summary>
|
||||
private const int MAX_USERNAME_LENGTH = 12;
|
||||
|
||||
[Header("UI References")]
|
||||
// Reference to the input text field for username
|
||||
/// <summary>
|
||||
/// Reference to the input text field for username
|
||||
/// </summary>
|
||||
public TMP_InputField inputName;
|
||||
// Reference to the avatar-list container
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the avatar-list container
|
||||
/// </summary>
|
||||
public Transform avatarsContainer;
|
||||
|
||||
[Header("Prefab")]
|
||||
// Avatar prefab
|
||||
/// <summary>
|
||||
/// Avatar prefab
|
||||
/// </summary>
|
||||
public GameObject avatarPrefab;
|
||||
// List of all sprites that are supported as avatars
|
||||
|
||||
/// <summary>
|
||||
/// List of all sprites that are supported as avatars
|
||||
/// </summary>
|
||||
public List<Sprite> sprites = new List<Sprite>();
|
||||
|
||||
[Header("Users List")]
|
||||
// Reference to the UserList ScriptableObject
|
||||
/// <summary>
|
||||
/// Reference to the UserList ScriptableObject
|
||||
/// </summary>
|
||||
public UserList users;
|
||||
|
||||
/// <summary>
|
||||
/// Current selected avatar
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
// Current selected avatar
|
||||
private int selectedAvatar = 0;
|
||||
// List of references to avatar background sprites (so we can color them nicely)
|
||||
|
||||
/// <summary>
|
||||
/// List of references to avatar background sprites (so we can color them nicely)
|
||||
/// </summary>
|
||||
private List<Image> avatars = new List<Image>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
for (int i = 0; i < sprites.Count; i++)
|
||||
@@ -60,7 +82,10 @@ public class UserCreationScreen : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current selected avatar
|
||||
/// <summary>
|
||||
/// Update the current selected avatar
|
||||
/// </summary>
|
||||
/// <param name="newAvatar">Index to the new avatar in the <c>this.avatars</c> list</param>
|
||||
private void UpdateAvatar(int newAvatar)
|
||||
{
|
||||
avatars[selectedAvatar].color = Color.gray;
|
||||
@@ -68,13 +93,20 @@ public class UserCreationScreen : MonoBehaviour
|
||||
avatars[selectedAvatar].color = Color.blue;
|
||||
}
|
||||
|
||||
// Check if a given string is a correct username (using Regex)
|
||||
/// <summary>
|
||||
/// Check if a given string is a correct username (using Regex)
|
||||
/// </summary>
|
||||
/// <param name="username">The username to be checked</param>
|
||||
/// <returns><c>true</c> if the username was valid, <c>false</c> otherwise</returns>
|
||||
static public bool IsValidUsername(string username)
|
||||
{
|
||||
return new Regex($@"^[abcdefghijklmnopqrstuvwxyz]{{1,{MAX_USERNAME_LENGTH}}}$").IsMatch(username);
|
||||
}
|
||||
|
||||
// Create a new user (will be called by button)
|
||||
/// <summary>
|
||||
/// Create a new user
|
||||
/// (this method will be called by a button callback)
|
||||
/// </summary>
|
||||
public void CreateUser()
|
||||
{
|
||||
string username = inputName.text;
|
||||
|
||||
Reference in New Issue
Block a user