From 27fc477a1ae54f5f17d74f2faa60f8e2ff5fb2da Mon Sep 17 00:00:00 2001 From: andong777 Date: Tue, 2 Sep 2014 15:37:49 +0800 Subject: [PATCH] rebuild done. --- Assets/Scripts/SaveLoad.cs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/SaveLoad.cs b/Assets/Scripts/SaveLoad.cs index eefcbdc..9e13fdf 100644 --- a/Assets/Scripts/SaveLoad.cs +++ b/Assets/Scripts/SaveLoad.cs @@ -12,7 +12,7 @@ public class SaveLoad { int cursor; // cursor to read records private SaveLoad() { - cursor = start; + ResetCursor(); } public static SaveLoad Instance @@ -33,7 +33,7 @@ public static SaveLoad Instance public void ResetCursor() { - cursor = start; + cursor = start - recordsPerPage; } public void Save(Data data) @@ -79,16 +79,16 @@ public Data[] Prev() { int i = 0; var page = new Data[recordsPerPage]; + if (cursor - recordsPerPage >= start) + cursor -= recordsPerPage; Debug.Log("---Prev---"+cursor); - cursor = cursor - recordsPerPage >= start ? cursor - recordsPerPage : start; while (i < recordsPerPage && PlayerPrefs.HasKey(cursor + "Name")) { - string name = PlayerPrefs.GetString(cursor + "Name"); - int score = PlayerPrefs.GetInt(cursor + "Score"); - page[i++] = new Data(cursor, name, score); - - cursor ++; - } + int idx = cursor + i; + string name = PlayerPrefs.GetString(idx + "Name"); + int score = PlayerPrefs.GetInt(idx + "Score"); + page[i++] = new Data(idx, name, score); + } return page; } @@ -96,14 +96,15 @@ public Data[] Next() { int i=0; var page = new Data[recordsPerPage]; + if (PlayerPrefs.HasKey((cursor + recordsPerPage) + "Name")) + cursor += recordsPerPage; Debug.Log("---Next---"+cursor); while (i < recordsPerPage && PlayerPrefs.HasKey(cursor + "Name")) { - string name = PlayerPrefs.GetString(cursor + "Name"); - int score = PlayerPrefs.GetInt(cursor + "Score"); - page[i++] = new Data(cursor, name, score); - - cursor ++; + int idx = cursor + i; + string name = PlayerPrefs.GetString(idx + "Name"); + int score = PlayerPrefs.GetInt(idx + "Score"); + page[i++] = new Data(idx, name, score); } return page; }