Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e1cebb2

Browse files
Datacontroller initialized
1 parent 87ce6dd commit e1cebb2

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

‎Data/DataController.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,65 @@ namespace Data {
77

88
public class DataController : MonoBehaviour
99
{
10-
10+
public static readonly string DATA_SCORE = "score";
11+
public static readonly string DATA_HIGHSCORE = "highscore";
12+
13+
private static readonly int DEFAULT_INT = 0;
14+
private static readonly float DEFAULT_FLOAT = 0.0F;
15+
private static readonly string DEFAULT_STRING = "";
16+
17+
public bool debug;
18+
19+
#region Public Functions
20+
public T GetData<T>(string _data, bool _createIfNull=true) {
21+
if (!DataExists(_data)) {
22+
string _warning = "Data ["+_data+"] does not exist.";
23+
if (_createIfNull) {
24+
_warning += "Creating..";
25+
LogWarning(_warning);
26+
} else {
27+
_warning += "Returning default..";
28+
LogWarning(_warning);
29+
return default(T);
30+
}
31+
}
32+
33+
if (typeof(T) == typeof(int)) {
34+
return PlayerPrefs.GetInt(_data, DEFAULT_INT);
35+
} else if (typeof(T) == typeof(float)) {
36+
return PlayerPrefs.GetFloat(_data, DEFAULT_FLOAT);
37+
} else if (typeof(T) == typeof(string)) {
38+
return PlayerPrefs.GetString(_data, DEFAULT_STRING);
39+
}
40+
41+
return default(T);
42+
}
43+
44+
public void SaveData<T>(string _data, T _val) {
45+
if (typeof(T) == typeof(int)) {
46+
return PlayerPrefs.SetInt(_data, _val);
47+
} else if (typeof(T) == typeof(float)) {
48+
return PlayerPrefs.SetFloat(_data, _val);
49+
} else if (typeof(T) == typeof(string)) {
50+
return PlayerPrefs.SetString(_data, _val);
51+
}
52+
}
53+
#endif
54+
55+
#region Private Functions
56+
private bool DataExists(string _data) {
57+
return PlayerPrefs.HasKey(_data);
58+
}
59+
60+
private void LogWarning(string _msg) {
61+
if (!debug) return;
62+
Debug.LogWarning("[DataController]: "+_msg);
63+
}
64+
#endif
65+
66+
#region Tests
67+
68+
#endregion
1169
}
1270
}
1371
}

‎Menu/PageController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ private void LogWarning(string _msg) {
131131
if (!debug) return;
132132
Debug.LogWarning("[Page Controller]: "+_msg);
133133
}
134+
#endregion
135+
136+
#region Tests
137+
134138
#endregion
135139
}
136140
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /