Wes xx build fix
This commit is contained in:
committed by
Louis Adriaens
parent
601cf38c61
commit
2fa54620ef
8
Assets/Accounts/Prefabs.meta
Normal file
8
Assets/Accounts/Prefabs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32d13c7982bb5b1449abb4c889b61826
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
212
Assets/Accounts/Prefabs/Avatar.prefab
Normal file
212
Assets/Accounts/Prefabs/Avatar.prefab
Normal file
@@ -0,0 +1,212 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &6263784958278830195
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6263784958278830196}
|
||||
- component: {fileID: 6263784958278830198}
|
||||
- component: {fileID: 6263784958278830197}
|
||||
m_Layer: 5
|
||||
m_Name: Image
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &6263784958278830196
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784958278830195}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 6263784960026409965}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 100, y: 100}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &6263784958278830198
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784958278830195}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &6263784958278830197
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784958278830195}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!1 &6263784960026409964
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6263784960026409965}
|
||||
- component: {fileID: 6263784960026409952}
|
||||
- component: {fileID: 6263784960026409967}
|
||||
- component: {fileID: 6263784960026409966}
|
||||
m_Layer: 5
|
||||
m_Name: Avatar
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &6263784960026409965
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784960026409964}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 6263784958278830196}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &6263784960026409952
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784960026409964}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &6263784960026409967
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784960026409964}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!114 &6263784960026409966
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6263784960026409964}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Navigation:
|
||||
m_Mode: 3
|
||||
m_WrapAround: 0
|
||||
m_SelectOnUp: {fileID: 0}
|
||||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||
m_ColorMultiplier: 1
|
||||
m_FadeDuration: 0.1
|
||||
m_SpriteState:
|
||||
m_HighlightedSprite: {fileID: 0}
|
||||
m_PressedSprite: {fileID: 0}
|
||||
m_SelectedSprite: {fileID: 0}
|
||||
m_DisabledSprite: {fileID: 0}
|
||||
m_AnimationTriggers:
|
||||
m_NormalTrigger: Normal
|
||||
m_HighlightedTrigger: Highlighted
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 6263784960026409967}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 0}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName:
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName:
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
7
Assets/Accounts/Prefabs/Avatar.prefab.meta
Normal file
7
Assets/Accounts/Prefabs/Avatar.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c09ef5423059da444ad7743174e9f077
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Accounts/Scenes.meta
Normal file
8
Assets/Accounts/Scenes.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eecb682f6c673164e96e4f8965d6b1c4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1486
Assets/Accounts/Scenes/UserCreationScreen.unity
Normal file
1486
Assets/Accounts/Scenes/UserCreationScreen.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Accounts/Scenes/UserCreationScreen.unity.meta
Normal file
7
Assets/Accounts/Scenes/UserCreationScreen.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 401cfc17c01f88847b434260a6a93933
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Accounts/ScriptableObjects.meta
Normal file
8
Assets/Accounts/ScriptableObjects.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1138319cd1864546a021b76adee333c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Accounts/ScriptableObjects/UserList.asset
Normal file
32
Assets/Accounts/ScriptableObjects/UserList.asset
Normal file
@@ -0,0 +1,32 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 0
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3f3d6d68c3c3db64e91cf5ec9537ccda, type: 3}
|
||||
m_Name: UserList
|
||||
m_EditorClassIdentifier:
|
||||
storedUserList:
|
||||
currentUserIndex: 0
|
||||
storedUsers:
|
||||
- username: dvschuyl
|
||||
avatar: {fileID: 21300000, guid: f2344cd67769733ceb363a41e1d88a65, type: 3}
|
||||
playtime: 0
|
||||
courses:
|
||||
- entries:
|
||||
- key: courseIndex
|
||||
bytes: 0001000000ffffffff01000000000000000c0200000046417373656d626c792d4353686172702c2056657273696f6e3d302e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d6e756c6c05010000000b436f75727365496e646578010000000776616c75655f5f000802000000000000000b
|
||||
- key: courseProgress
|
||||
bytes: 0001000000ffffffff010000000000000004010000000d53797374656d2e53696e676c6501000000076d5f76616c7565000b0000403f0b
|
||||
minigames:
|
||||
- entries:
|
||||
- key: minigameIndex
|
||||
bytes: 0001000000ffffffff01000000000000000c0200000046417373656d626c792d4353686172702c2056657273696f6e3d302e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d6e756c6c05010000000d4d696e6967616d65496e646578010000000776616c75655f5f000802000000000000000b
|
||||
- key: highscore
|
||||
bytes: 0001000000ffffffff010000000000000004010000000c53797374656d2e496e74333201000000076d5f76616c75650008000000000b
|
||||
8
Assets/Accounts/ScriptableObjects/UserList.asset.meta
Normal file
8
Assets/Accounts/ScriptableObjects/UserList.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 072bec636a40f7e4e93b0ac624a3bda2
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Accounts/Scripts.meta
Normal file
8
Assets/Accounts/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 221fac2e860d54348be4de169ea910d9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
Assets/Accounts/Scripts/Progress.cs
Normal file
79
Assets/Accounts/Scripts/Progress.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
// Can not be created from Editor
|
||||
public class Progress
|
||||
{
|
||||
[Serializable]
|
||||
// Helper class to serialize into byte[]
|
||||
protected class DataEntry
|
||||
{
|
||||
public string key;
|
||||
public List<byte> bytes = new List<byte>();
|
||||
|
||||
public DataEntry(string key, byte[] data)
|
||||
{
|
||||
this.key = key;
|
||||
this.bytes = new List<byte>(data);
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Course or Minigame")]
|
||||
[SerializeField]
|
||||
// values belonging to a certain key, in List (which can be serialized)
|
||||
private List<DataEntry> entries = new List<DataEntry>();
|
||||
|
||||
|
||||
// Add new `key` := `value`, returns `true` if successful
|
||||
public bool AddOrUpdate<T>(string key, T data)
|
||||
{
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
DataEntry entry = entries.Find(x => x.key == key);
|
||||
|
||||
// Hacky serialization stuff
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
bf.Serialize(ms, data);
|
||||
if (entry != null)
|
||||
{
|
||||
entry.bytes.Clear();
|
||||
entry.bytes.AddRange(ms.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
entries.Add(new DataEntry(key, ms.ToArray()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the value of type `T` belonging to `key`
|
||||
public T Get<T>(string key)
|
||||
{
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
// Find the correct key
|
||||
foreach (DataEntry entry in entries)
|
||||
{
|
||||
if (entry.key == key)
|
||||
{
|
||||
// Hacky serialization stuff
|
||||
byte[] data = entry.bytes.ToArray();
|
||||
ms.Write(data, 0, data.Length);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return (T)bf.Deserialize(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Raise an exception when key is not found
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Scripts/Progress.cs.meta
Normal file
11
Assets/Accounts/Scripts/Progress.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d887bc641cc7a8f4abf9d4eb34d26923
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
Assets/Accounts/Scripts/User.cs
Normal file
62
Assets/Accounts/Scripts/User.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class User
|
||||
{
|
||||
[Header("Personal data")]
|
||||
// User nickname
|
||||
public string username;
|
||||
// User avatar
|
||||
public Sprite avatar;
|
||||
|
||||
[Header("Personal settings")]
|
||||
// TODO: set personal settings and preferences
|
||||
|
||||
[Header("Progress")]
|
||||
// Total playtime
|
||||
public double playtime;
|
||||
[SerializeField]
|
||||
// List of courses a user started/completed
|
||||
public List<Progress> courses = new List<Progress>();
|
||||
[SerializeField]
|
||||
// List of minigames a user played
|
||||
public List<Progress> minigames = new List<Progress>();
|
||||
|
||||
// Get a list of all recently started courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
|
||||
public List<Tuple<CourseIndex, float>> GetRecentCourses()
|
||||
{
|
||||
// TODO: return better results (for now only return all courses)
|
||||
List<Tuple<CourseIndex, float>> recentCourses = new List<Tuple<CourseIndex, float>>();
|
||||
foreach (Progress courseProgress in courses)
|
||||
{
|
||||
CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
|
||||
float progress = courseProgress.Get<float>("courseProgress");
|
||||
recentCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
|
||||
}
|
||||
return recentCourses;
|
||||
}
|
||||
|
||||
// Get a list of all recommended courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
|
||||
public List<Tuple<CourseIndex, float>> GetRecommendedCourses()
|
||||
{
|
||||
List<Tuple<CourseIndex, float>> recommenedCourses = new List<Tuple<CourseIndex, float>>();
|
||||
if (courses.Count == 0)
|
||||
{
|
||||
recommenedCourses.Add(Tuple.Create<CourseIndex, float>(CourseIndex.FINGERSPELLING, 0.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: return better results (for now only return all courses)
|
||||
foreach (Progress courseProgress in courses)
|
||||
{
|
||||
CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
|
||||
float progress = courseProgress.Get<float>("courseProgress");
|
||||
recommenedCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
|
||||
}
|
||||
}
|
||||
|
||||
return recommenedCourses;
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Scripts/User.cs.meta
Normal file
11
Assets/Accounts/Scripts/User.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae6d59a84b340534f8bbfc7101ce4a2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
Assets/Accounts/Scripts/UserCreationScreen.cs
Normal file
98
Assets/Accounts/Scripts/UserCreationScreen.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UserCreationScreen : MonoBehaviour
|
||||
{
|
||||
// Max length of a username
|
||||
private const int MAX_USERNAME_LENGTH = 12;
|
||||
|
||||
[Header("UI References")]
|
||||
// Reference to the input text field for username
|
||||
public TMP_InputField inputName;
|
||||
// Reference to the avatar-list container
|
||||
public Transform avatarsContainer;
|
||||
|
||||
[Header("Prefab")]
|
||||
// Avatar prefab
|
||||
public GameObject avatarPrefab;
|
||||
// List of all sprites that are supported as avatars
|
||||
public List<Sprite> sprites = new List<Sprite>();
|
||||
|
||||
[Header("Users List")]
|
||||
// Reference to the UserList ScriptableObject
|
||||
public UserList users;
|
||||
|
||||
[SerializeField]
|
||||
// Current selected avatar
|
||||
private int selectedAvatar = 0;
|
||||
// List of references to avatar background sprites (so we can color them nicely)
|
||||
private List<Image> avatars = new List<Image>();
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
for (int i = 0; i < sprites.Count; i++)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(avatarPrefab, avatarsContainer);
|
||||
|
||||
// Store value of i so we can use it the callback (else it would get the value of sprites.Count)
|
||||
int x = i;
|
||||
// Add onClick callback
|
||||
instance.GetComponent<Button>().onClick.AddListener(() => UpdateAvatar(x));
|
||||
|
||||
// Store reference to image for fancy coloring
|
||||
Image background = instance.GetComponent<Image>();
|
||||
avatars.Add(background);
|
||||
// Set background color
|
||||
background.color = selectedAvatar == i ? Color.blue : Color.gray;
|
||||
// Find correct component for setting the sprite
|
||||
foreach (Image img in background.GetComponentsInChildren<Image>())
|
||||
if (img != background)
|
||||
{
|
||||
img.sprite = sprites[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current selected avatar
|
||||
private void UpdateAvatar(int newAvatar)
|
||||
{
|
||||
avatars[selectedAvatar].color = Color.gray;
|
||||
selectedAvatar = newAvatar;
|
||||
avatars[selectedAvatar].color = Color.blue;
|
||||
}
|
||||
|
||||
// Check if a given string is a correct username (using Regex)
|
||||
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)
|
||||
public void CreateUser()
|
||||
{
|
||||
string username = inputName.text;
|
||||
if (IsValidUsername(username))
|
||||
{
|
||||
if (users.GetUserByUsername(username) == null)
|
||||
{
|
||||
// Create a new entry in the UserList ScriptableObject
|
||||
users.CreateAndAddNewUser(username, sprites[selectedAvatar]);
|
||||
// TODO: change scene, for now just change to StartScreen
|
||||
SceneManager.LoadScene("Common/Scenes/StartScreen");
|
||||
}
|
||||
// TODO: give more feedback to user
|
||||
// Warn user that username already exists
|
||||
else Debug.LogWarning($"Username '{username}' already exists!");
|
||||
}
|
||||
// TODO: give more feedback to user
|
||||
// Warn user that username is invalid
|
||||
else Debug.LogWarning($"Invalid username '{username}'!");
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Scripts/UserCreationScreen.cs.meta
Normal file
11
Assets/Accounts/Scripts/UserCreationScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc3902e35c042b14f83b24498d31d587
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Accounts/Scripts/UserList.cs
Normal file
89
Assets/Accounts/Scripts/UserList.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/UserList")]
|
||||
public class UserList : ScriptableObject
|
||||
{
|
||||
// Serializable UserList content
|
||||
[Serializable]
|
||||
public class StoredUserList
|
||||
{
|
||||
public int currentUserIndex;
|
||||
public List<User> storedUsers = new List<User>();
|
||||
}
|
||||
[Header("Users")]
|
||||
[SerializeField]
|
||||
// Reference to serializable version of UserList
|
||||
private StoredUserList storedUserList = new StoredUserList();
|
||||
|
||||
// Path to .json file
|
||||
public static string PATH = null;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
PATH = $"{Application.dataPath}/users.json";
|
||||
Load();
|
||||
}
|
||||
|
||||
// Create a new User
|
||||
public User CreateNewUser(string name, Sprite avatar)
|
||||
{
|
||||
User user = new User();
|
||||
user.username = name;
|
||||
user.avatar = avatar;
|
||||
return user;
|
||||
}
|
||||
|
||||
// Create a new User and add to list
|
||||
public User CreateAndAddNewUser(string name, Sprite avatar)
|
||||
{
|
||||
User user = CreateNewUser(name, avatar);
|
||||
storedUserList.storedUsers.Add(user);
|
||||
Save();
|
||||
return user;
|
||||
}
|
||||
|
||||
// Get user by username, returns `null` if no user can be found with such name
|
||||
public User GetUserByUsername(string username)
|
||||
{
|
||||
foreach (User user in storedUserList.storedUsers)
|
||||
if (user.username == username) return user;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get a list of all users
|
||||
public List<User> GetUsers()
|
||||
{
|
||||
return storedUserList.storedUsers;
|
||||
}
|
||||
|
||||
// Get the current active user
|
||||
public User GetCurrentUser()
|
||||
{
|
||||
return storedUserList.storedUsers[storedUserList.currentUserIndex];
|
||||
}
|
||||
|
||||
// Save the userList
|
||||
public void Save()
|
||||
{
|
||||
string json = JsonUtility.ToJson(storedUserList);
|
||||
File.CreateText(PATH).Close();
|
||||
File.WriteAllText(PATH, json);
|
||||
}
|
||||
|
||||
// Load the userList into this object
|
||||
public void Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
storedUserList.storedUsers.Clear();
|
||||
|
||||
string text = File.ReadAllText(PATH);
|
||||
storedUserList = JsonUtility.FromJson<StoredUserList>(text);
|
||||
}
|
||||
catch (FileNotFoundException) { Debug.Log($"Path '{PATH}' not found"); }
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Scripts/UserList.cs.meta
Normal file
11
Assets/Accounts/Scripts/UserList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f3d6d68c3c3db64e91cf5ec9537ccda
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Accounts/Tests.meta
Normal file
8
Assets/Accounts/Tests.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8156c3a6e88d0bb4ebabdf7c26979081
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
175
Assets/Accounts/Tests/TestProgress.cs
Normal file
175
Assets/Accounts/Tests/TestProgress.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
public class TestProgress : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
// Dummy struct
|
||||
private struct SerializableStruct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
private struct NonSerializableStruct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
|
||||
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
|
||||
private bool AddNonSerializableStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
NonSerializableStruct nss = new NonSerializableStruct();
|
||||
try { progress.AddOrUpdate<NonSerializableStruct>("key", nss); }
|
||||
catch (SerializationException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
|
||||
private bool AccessInvalidKey()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
try { progress.Get<int>("non-existing key"); }
|
||||
catch (KeyNotFoundException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper method, returns true if `Progress.Get(...)` throws a `InvalidCastException`
|
||||
private bool AccessInvalidType()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key", 123456789);
|
||||
try { progress.Get<double>("key"); }
|
||||
catch (InvalidCastException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
TestNewProgress();
|
||||
TestProgressAddInvalidData();
|
||||
TestProgressAddDuplicateKey();
|
||||
TestProgressAddInt();
|
||||
TestProgressAddDouble();
|
||||
TestProgressAddString();
|
||||
TestProgressAddSerializableStruct();
|
||||
TestProgressAddNonSerializableStruct();
|
||||
TestProgressGetInvalidKey();
|
||||
TestProgressGetInvalidType();
|
||||
TestProgressUpdate();
|
||||
TestProgressGetInt();
|
||||
TestProgressGetDouble();
|
||||
TestProgressGetString();
|
||||
TestProgressGetStruct();
|
||||
}
|
||||
|
||||
public void TestNewProgress()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress != null);
|
||||
}
|
||||
|
||||
public void TestProgressAddInvalidData()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(!progress.AddOrUpdate<GameObject>("key", null));
|
||||
}
|
||||
|
||||
public void TestProgressAddDuplicateKey()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key 1", 0);
|
||||
Debug.Assert(progress.AddOrUpdate<int>("key 1", 1));
|
||||
}
|
||||
|
||||
public void TestProgressAddInt()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<int>("key", 1));
|
||||
}
|
||||
|
||||
public void TestProgressAddDouble()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<double>("key", 1.0));
|
||||
}
|
||||
|
||||
public void TestProgressAddString()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<string>("key", "Hello World!"));
|
||||
}
|
||||
|
||||
public void TestProgressAddSerializableStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
|
||||
}
|
||||
|
||||
public void TestProgressAddNonSerializableStruct()
|
||||
{
|
||||
Debug.Assert(AddNonSerializableStruct());
|
||||
}
|
||||
|
||||
public void TestProgressGetInvalidKey()
|
||||
{
|
||||
Debug.Assert(AccessInvalidKey());
|
||||
}
|
||||
|
||||
public void TestProgressGetInvalidType()
|
||||
{
|
||||
Debug.Assert(AccessInvalidType());
|
||||
}
|
||||
|
||||
public void TestProgressUpdate()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Debug.Assert(progress.Get<int>("key") == 1);
|
||||
progress.AddOrUpdate<int>("key", 2);
|
||||
Debug.Assert(progress.Get<int>("key") == 2);
|
||||
}
|
||||
|
||||
public void TestProgressGetInt()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Debug.Assert(progress.Get<int>("key") == 1);
|
||||
}
|
||||
|
||||
public void TestProgressGetDouble()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<double>("key", 1.0);
|
||||
Debug.Assert(progress.Get<double>("key") == 1.0);
|
||||
}
|
||||
|
||||
public void TestProgressGetString()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<string>("key", "Hello World!");
|
||||
Debug.Assert(progress.Get<string>("key") == "Hello World!");
|
||||
}
|
||||
|
||||
public void TestProgressGetStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
|
||||
int R = 1, G = 10, B = 100;
|
||||
float X = 0.1f, Y = 0.01f, Z = 0.001f;
|
||||
SerializableStruct data = new SerializableStruct { r = R, g = G, b = B, x = X, y = Y, z = Z };
|
||||
progress.AddOrUpdate<SerializableStruct>("key", data);
|
||||
SerializableStruct result = progress.Get<SerializableStruct>("key");
|
||||
Debug.Assert(result.r == R);
|
||||
Debug.Assert(result.g == G);
|
||||
Debug.Assert(result.b == B);
|
||||
Debug.Assert(result.x == X);
|
||||
Debug.Assert(result.y == Y);
|
||||
Debug.Assert(result.z == Z);
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Tests/TestProgress.cs.meta
Normal file
11
Assets/Accounts/Tests/TestProgress.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49445c42f43d1bb488f588623826a39e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/Accounts/Tests/TestUserCreationScreen.cs
Normal file
27
Assets/Accounts/Tests/TestUserCreationScreen.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TestUserCreationScreen : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
TestIsValidUsernameTrue();
|
||||
TestIsValidUsernameFalse();
|
||||
}
|
||||
|
||||
public void TestIsValidUsernameTrue()
|
||||
{
|
||||
foreach (char c in "abcdefghijklmnopqrstuvwxyz")
|
||||
Debug.Assert(UserCreationScreen.IsValidUsername(c.ToString()));
|
||||
|
||||
Debug.Assert(UserCreationScreen.IsValidUsername("abcdefghijkl"));
|
||||
}
|
||||
|
||||
public void TestIsValidUsernameFalse()
|
||||
{
|
||||
Debug.Assert(!UserCreationScreen.IsValidUsername(string.Empty));
|
||||
foreach (char c in " \n\t0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-*/%_(){}[]\\")
|
||||
Debug.Assert(!UserCreationScreen.IsValidUsername(c.ToString()));
|
||||
|
||||
Debug.Assert(!UserCreationScreen.IsValidUsername("abcdefghijklmnopqrstuvwxyz"));
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Tests/TestUserCreationScreen.cs.meta
Normal file
11
Assets/Accounts/Tests/TestUserCreationScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6dabaf99e10900459274641f4cc9010
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user