Game Development Reference
In-Depth Information
MemoryStream(Convert.FromBase64String(data));
_users = binary.Deserialize(memory) as
List<UserData>;
} else {
for (int i = 0 ; i < RANDOM_NAMES.Length; ++i) {
UserData user = new UserData();
user.name = RANDOM_NAMES[i];
user.score =
Mathf.FloorToInt(UnityEngine.Random.value * 1000);
_users.Add(user);
}
}
this.SortByScore();
}
We just created the function to load the string data using Player-
Prefs.GetString (key,"") from the key. We also checked that it was not
an empty string. Then, we deserialized the data by first converting it from string
to the byte array using MemoryStream , and then we used BinaryFormat-
ter to deserialize the data to List<UserData> .
4. Next, we will go to the UIHiscore script to add the script to initialize the local
hi-score table, as shown in the following highlighted code:
// Unity JavaScript user:
private var _user : UserData;
private var _localHiscore : LocalHiscore;
private var _scrollLocal : Vector2 = Vector2.zero;
function Awake () {
_localHiscore = GetComponent.<LocalHiscore>();
if (_localHiscore == null) {
_localHiscore =
gameObject.AddComponent.<LocalHiscore>();
}
}
function Start () {
_localHiscore.Initialize(maxUser);
Search WWH ::




Custom Search