@@ -24,7 +24,7 @@ public static string LoadString<T>(in T key, in string field)
24
24
{
25
25
var fullName = key . GetType ( ) . FullName ;
26
26
if ( string . IsNullOrEmpty ( fullName ) ) return string . Empty ;
27
- return PlayerPrefs . GetString ( string . Concat ( fullName . GetHashCode ( ) , field . GetHashCode ( ) ) ) ;
27
+ return PlayerPrefs . GetString ( string . Concat ( fullName . GetHashCode ( ) , field . GetHashCode ( ) , "_String" ) ) ;
28
28
}
29
29
30
30
/// <summary>
@@ -38,7 +38,7 @@ public static int LoadInt<T>(in T key, in string field)
38
38
{
39
39
var fullName = key . GetType ( ) . FullName ;
40
40
if ( string . IsNullOrEmpty ( fullName ) ) return 0 ;
41
- return PlayerPrefs . GetInt ( string . Concat ( fullName . GetHashCode ( ) , field . GetHashCode ( ) ) ) ;
41
+ return PlayerPrefs . GetInt ( string . Concat ( fullName . GetHashCode ( ) , field . GetHashCode ( ) , "_Int" ) ) ;
42
42
}
43
43
44
44
/// <summary>
@@ -52,7 +52,7 @@ public static bool LoadBool<T>(in T key, in string field)
52
52
{
53
53
var fullName = key . GetType ( ) . FullName ;
54
54
if ( string . IsNullOrEmpty ( fullName ) ) return false ;
55
- return PlayerPrefs . GetInt ( string . Concat ( fullName . GetHashCode ( ) , field . GetHashCode ( ) ) ) == 1 ;
55
+ return PlayerPrefs . GetInt ( string . Concat ( fullName . GetHashCode ( ) , field . GetHashCode ( ) , "_Boolean" ) ) == 1 ;
56
56
}
57
57
58
58
/// <summary>
@@ -63,8 +63,8 @@ public static bool LoadBool<T>(in T key, in string field)
63
63
/// <returns>返回值</returns>
64
64
public static string LoadString ( in string key , in string def = null )
65
65
{
66
- if ( PlayerPrefs . HasKey ( string . Concat ( key , "_String" ) ) ) return def ;
67
- return PlayerPrefs . GetString ( key ) ;
66
+ var address = string . Concat ( key , "_String" ) ;
67
+ return PlayerPrefs . HasKey ( address ) ? def : PlayerPrefs . GetString ( address ) ;
68
68
}
69
69
70
70
/// <summary>
@@ -75,8 +75,8 @@ public static string LoadString(in string key, in string def = null)
75
75
/// <returns>返回值</returns>
76
76
public static int LoadInt ( in string key , in int def = 0 )
77
77
{
78
- if ( PlayerPrefs . HasKey ( string . Concat ( key , "_Int" ) ) ) return def ;
79
- return PlayerPrefs . GetInt ( key ) ;
78
+ var address = string . Concat ( key , "_Int" ) ;
79
+ return PlayerPrefs . HasKey ( address ) ? def : PlayerPrefs . GetInt ( address ) ;
80
80
}
81
81
82
82
/// <summary>
@@ -89,8 +89,9 @@ public static int LoadInt(in string key, in int def = 0)
89
89
public static T LoadEnum < T > ( in string key , in T def = default )
90
90
where T : Enum
91
91
{
92
- if ( PlayerPrefs . HasKey ( string . Concat ( key , "_Enum" ) ) ) return def ;
93
- return ( T ) Enum . Parse ( typeof ( T ) , PlayerPrefs . GetInt ( key ) . ToString ( ) ) ;
92
+ var address = string . Concat ( key , "_Enum" ) ;
93
+ if ( PlayerPrefs . HasKey ( address ) ) return def ;
94
+ return ( T ) Enum . Parse ( typeof ( T ) , PlayerPrefs . GetInt ( address ) . ToString ( ) ) ;
94
95
}
95
96
96
97
/// <summary>
@@ -104,8 +105,9 @@ public static T LoadEnum<T>(in T def = default)
104
105
{
105
106
var fullName = typeof ( T ) . FullName ;
106
107
if ( string . IsNullOrEmpty ( fullName ) ) return def ;
107
- if ( PlayerPrefs . HasKey ( string . Concat ( fullName , "_Enum" ) ) ) return def ;
108
- return ( T ) Enum . Parse ( typeof ( T ) , PlayerPrefs . GetInt ( fullName ) . ToString ( ) ) ;
108
+ var address = string . Concat ( fullName , "_Enum" ) ;
109
+ if ( PlayerPrefs . HasKey ( address ) ) return def ;
110
+ return ( T ) Enum . Parse ( typeof ( T ) , PlayerPrefs . GetInt ( address ) . ToString ( ) ) ;
109
111
}
110
112
111
113
/// <summary>
@@ -117,8 +119,8 @@ public static T LoadEnum<T>(in T def = default)
117
119
/// <returns>返回值</returns>
118
120
public static T LoadJsonData < T > ( in string key , in T def = default )
119
121
{
120
- if ( PlayerPrefs . HasKey ( string . Concat ( key , "_Json" ) ) ) return def ;
121
- return AHelper . Json . Deserialize < T > ( PlayerPrefs . GetString ( key ) ) ;
122
+ var address = string . Concat ( key , "_Json" ) ;
123
+ return PlayerPrefs . HasKey ( address ) ? def : AHelper . Json . Deserialize < T > ( PlayerPrefs . GetString ( address ) ) ;
122
124
}
123
125
124
126
/// <summary>
@@ -129,8 +131,8 @@ public static T LoadJsonData<T>(in string key, in T def = default)
129
131
/// <returns>返回值</returns>
130
132
public static float LoadFloat ( in string key , in float def = 0 )
131
133
{
132
- if ( PlayerPrefs . HasKey ( string . Concat ( key , "_Float" ) ) ) return def ;
133
- return PlayerPrefs . GetFloat ( key ) ;
134
+ var address = string . Concat ( key , "_Float" ) ;
135
+ return PlayerPrefs . HasKey ( address ) ? def : PlayerPrefs . GetFloat ( address ) ;
134
136
}
135
137
}
136
138
0 commit comments