Initial commit: Client Doc docs Server Tools
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
|
||||
#if UNITY_WEBGL
|
||||
using WeChatWASM;
|
||||
#endif
|
||||
|
||||
public static class XData
|
||||
{
|
||||
//存储
|
||||
public static void DeleteAll()
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
WX.StorageDeleteAllSync();
|
||||
else
|
||||
PlayerPrefs.DeleteAll();
|
||||
#endif
|
||||
UnityEngine.PlayerPrefs.DeleteAll();
|
||||
}
|
||||
public static void DeleteKey(string key)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
WX.StorageDeleteKeySync(key);
|
||||
else
|
||||
PlayerPrefs.DeleteKey(key);
|
||||
#endif
|
||||
UnityEngine.PlayerPrefs.DeleteKey(key);
|
||||
}
|
||||
public static float GetFloat(string key, float defaultValue = 0)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
return WX.StorageGetFloatSync(key, defaultValue);
|
||||
else
|
||||
PlayerPrefs.GetFloat(key, defaultValue);
|
||||
#endif
|
||||
return UnityEngine.PlayerPrefs.GetFloat(key, defaultValue);
|
||||
}
|
||||
public static int GetInt(string key, int defaultValue = 0)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
return WX.StorageGetIntSync(key, defaultValue);
|
||||
else
|
||||
return PlayerPrefs.GetInt(key, defaultValue);
|
||||
#endif
|
||||
return UnityEngine.PlayerPrefs.GetInt(key, defaultValue);
|
||||
}
|
||||
public static string GetString(string key, string defaultValue = "")
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
return WX.StorageGetStringSync(key, defaultValue);
|
||||
else
|
||||
return PlayerPrefs.GetString(key, defaultValue);
|
||||
#endif
|
||||
return UnityEngine.PlayerPrefs.GetString(key, defaultValue);
|
||||
}
|
||||
public static bool HasKey(string key)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
return WX.StorageHasKeySync(key);
|
||||
else
|
||||
return PlayerPrefs.HasKey(key);
|
||||
#endif
|
||||
return UnityEngine.PlayerPrefs.HasKey(key);
|
||||
}
|
||||
public static void Save()
|
||||
{
|
||||
if (!GlobalData.bWX)
|
||||
UnityEngine.PlayerPrefs.Save();
|
||||
//微信不需要
|
||||
}
|
||||
public static void SetFloat(string key, float value)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
WX.StorageSetFloatSync(key,value);
|
||||
else
|
||||
PlayerPrefs.SetFloat(key, value);
|
||||
#endif
|
||||
UnityEngine.PlayerPrefs.SetFloat(key, value);
|
||||
}
|
||||
public static void SetInt(string key, int value)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
WX.StorageSetIntSync(key, value);
|
||||
else
|
||||
PlayerPrefs.SetInt(key, value);
|
||||
#endif
|
||||
UnityEngine.PlayerPrefs.SetInt(key, value);
|
||||
}
|
||||
public static void SetString(string key, string value)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (GlobalData.bWX)
|
||||
WX.StorageSetStringSync(key, value);
|
||||
else
|
||||
PlayerPrefs.SetString(key, value);
|
||||
#endif
|
||||
UnityEngine.PlayerPrefs.SetString(key, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user