This commit is contained in:
Jelle De Geest
2023-04-26 19:04:34 +02:00
parent 172938cec8
commit 47f8b96122
1004 changed files with 60756 additions and 117444 deletions

View File

@@ -34,20 +34,9 @@ public class UserCreationScreen : MonoBehaviour
/// </summary>
public GameObject avatarPrefab;
/// <summary>
/// List of all sprites that are supported as avatars
/// </summary>
public List<Sprite> sprites = new List<Sprite>();
/// <summary>
/// Reference to the UserList ScriptableObject
/// </summary>
public UserList users;
/// <summary>
/// Current selected avatar
/// </summary>
[SerializeField]
private int selectedAvatar = 0;
/// <summary>
@@ -55,6 +44,16 @@ public class UserCreationScreen : MonoBehaviour
/// </summary>
private List<Image> avatars = new List<Image>();
/// <summary>
/// Reference to the back button, so we can deactivate it when the user cannot go back (when no user is found at startup)
/// </summary>
public GameObject backButton;
/// <summary>
/// Boolean used to check whether the user can go back to the previous scene
/// </summary>
public static bool canGoBack = true;
/// <summary>
/// Start is called before the first frame update
@@ -62,8 +61,12 @@ public class UserCreationScreen : MonoBehaviour
void Start()
{
errorMessage.SetActive(false);
backButton.SetActive(canGoBack);
for (int i = 0; i < sprites.Count; i++)
// Reset to default value
UserCreationScreen.canGoBack = true;
for (int i = 0; i < UserList.AVATARS.Count; i++)
{
// Create instance of prefab
GameObject instance = GameObject.Instantiate(avatarPrefab, avatarsContainer);
@@ -79,7 +82,7 @@ public class UserCreationScreen : MonoBehaviour
// Set background color
background.color = selectedAvatar == i ? Color.blue : Color.gray;
// Find correct component for setting the sprite
instance.transform.Find("Image").GetComponent<Image>().sprite = sprites[i];
instance.transform.Find("Image").GetComponent<Image>().sprite = UserList.AVATARS[i];
}
}
@@ -113,10 +116,10 @@ public class UserCreationScreen : MonoBehaviour
string username = inputName.text;
if (IsValidUsername(username))
{
if (users.GetUserByUsername(username) == null)
if (UserList.GetUserByUsername(username) == null)
{
// Create a new entry in the UserList ScriptableObject
users.ChangeCurrentUser(users.CreateAndAddNewUser(username, sprites[selectedAvatar]));
UserList.AddUser(username, UserList.AVATARS[selectedAvatar]);
SystemController.GetInstance().BackToPreviousScene();
}
// Warn user that username already exists