11
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 2s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 6s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 4s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 4s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 32s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 3s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 16s
Plugin Library CI / publish (07.RKTools) (push) Successful in 2s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 2s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 6s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 4s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 4s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 32s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 3s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 16s
Plugin Library CI / publish (07.RKTools) (push) Successful in 2s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
This commit is contained in:
@@ -2,13 +2,12 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Stary.Evo
|
namespace Stary.Evo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义EditorPrefs实现,数据存储在项目根目录的EditorPrefs.ini文件中
|
/// 自定义PlayerPrefs实现,数据存储在项目根目录的PlayerPrefs.ini文件中
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class CustomPlayerPrefs
|
public static class CustomPlayerPrefs
|
||||||
{
|
{
|
||||||
@@ -26,9 +25,17 @@ namespace Stary.Evo
|
|||||||
/// <param name="value">值</param>
|
/// <param name="value">值</param>
|
||||||
public static void SetString(string key, string value)
|
public static void SetString(string key, string value)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
_dataCache[key] = value;
|
{
|
||||||
SaveData();
|
PlayerPrefs.SetString(key, value);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
_dataCache[key] = value;
|
||||||
|
SaveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,9 +46,16 @@ namespace Stary.Evo
|
|||||||
/// <returns>值</returns>
|
/// <returns>值</returns>
|
||||||
public static string GetString(string key, string defaultValue = "")
|
public static string GetString(string key, string defaultValue = "")
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
_dataCache.TryGetValue(key, out var value);
|
{
|
||||||
return value is string ? (string)value : defaultValue;
|
return PlayerPrefs.GetString(key, defaultValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
_dataCache.TryGetValue(key, out var value);
|
||||||
|
return value is string ? (string)value : defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -51,9 +65,17 @@ namespace Stary.Evo
|
|||||||
/// <param name="value">值</param>
|
/// <param name="value">值</param>
|
||||||
public static void SetInt(string key, int value)
|
public static void SetInt(string key, int value)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
_dataCache[key] = value;
|
{
|
||||||
SaveData();
|
PlayerPrefs.SetInt(key, value);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
_dataCache[key] = value;
|
||||||
|
SaveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,8 +86,15 @@ namespace Stary.Evo
|
|||||||
/// <returns>值</returns>
|
/// <returns>值</returns>
|
||||||
public static int GetInt(string key, int defaultValue = 0)
|
public static int GetInt(string key, int defaultValue = 0)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
return _dataCache.TryGetValue(key, out var value) ? (int)value : defaultValue;
|
{
|
||||||
|
return PlayerPrefs.GetInt(key, defaultValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
return _dataCache.TryGetValue(key, out var value) ? (int)value : defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -75,9 +104,17 @@ namespace Stary.Evo
|
|||||||
/// <param name="value">值</param>
|
/// <param name="value">值</param>
|
||||||
public static void SetFloat(string key, float value)
|
public static void SetFloat(string key, float value)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
_dataCache[key] = value;
|
{
|
||||||
SaveData();
|
PlayerPrefs.SetFloat(key, value);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
_dataCache[key] = value;
|
||||||
|
SaveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -88,8 +125,15 @@ namespace Stary.Evo
|
|||||||
/// <returns>值</returns>
|
/// <returns>值</returns>
|
||||||
public static float GetFloat(string key, float defaultValue = 0.0f)
|
public static float GetFloat(string key, float defaultValue = 0.0f)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
return _dataCache.TryGetValue(key, out var value) ? (float)value : defaultValue;
|
{
|
||||||
|
return PlayerPrefs.GetFloat(key, defaultValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
return _dataCache.TryGetValue(key, out var value) ? (float)value : defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -99,9 +143,17 @@ namespace Stary.Evo
|
|||||||
/// <param name="value">值</param>
|
/// <param name="value">值</param>
|
||||||
public static void SetBool(string key, bool value)
|
public static void SetBool(string key, bool value)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
_dataCache[key] = value;
|
{
|
||||||
SaveData();
|
PlayerPrefs.SetInt(key, value ? 1 : 0);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
_dataCache[key] = value;
|
||||||
|
SaveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -112,8 +164,15 @@ namespace Stary.Evo
|
|||||||
/// <returns>值</returns>
|
/// <returns>值</returns>
|
||||||
public static bool GetBool(string key, bool defaultValue = false)
|
public static bool GetBool(string key, bool defaultValue = false)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
return _dataCache.TryGetValue(key, out var value) ? (bool)value : defaultValue;
|
{
|
||||||
|
return PlayerPrefs.GetInt(key, defaultValue ? 1 : 0) == 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
return _dataCache.TryGetValue(key, out var value) ? (bool)value : defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -123,8 +182,15 @@ namespace Stary.Evo
|
|||||||
/// <returns>是否存在</returns>
|
/// <returns>是否存在</returns>
|
||||||
public static bool HasKey(string key)
|
public static bool HasKey(string key)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
return _dataCache.ContainsKey(key);
|
{
|
||||||
|
return PlayerPrefs.HasKey(key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
return _dataCache.ContainsKey(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -133,10 +199,18 @@ namespace Stary.Evo
|
|||||||
/// <param name="key">键</param>
|
/// <param name="key">键</param>
|
||||||
public static void DeleteKey(string key)
|
public static void DeleteKey(string key)
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
if (_dataCache.Remove(key))
|
|
||||||
{
|
{
|
||||||
SaveData();
|
PlayerPrefs.DeleteKey(key);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
if (_dataCache.Remove(key))
|
||||||
|
{
|
||||||
|
SaveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,8 +219,16 @@ namespace Stary.Evo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void DeleteAll()
|
public static void DeleteAll()
|
||||||
{
|
{
|
||||||
_dataCache.Clear();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
SaveData();
|
{
|
||||||
|
PlayerPrefs.DeleteAll();
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dataCache.Clear();
|
||||||
|
SaveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -155,8 +237,17 @@ namespace Stary.Evo
|
|||||||
/// <returns>键列表</returns>
|
/// <returns>键列表</returns>
|
||||||
public static string[] GetAllKeys()
|
public static string[] GetAllKeys()
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
return _dataCache.Keys.ToArray();
|
{
|
||||||
|
// WebGL平台无法直接获取所有键,这里返回空数组
|
||||||
|
// 注意:实际项目中可能需要维护一个键的列表
|
||||||
|
return new string[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
return _dataCache.Keys.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -165,8 +256,17 @@ namespace Stary.Evo
|
|||||||
/// <returns>键值对字典</returns>
|
/// <returns>键值对字典</returns>
|
||||||
public static Dictionary<string, object> GetAll()
|
public static Dictionary<string, object> GetAll()
|
||||||
{
|
{
|
||||||
LoadData();
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
return new Dictionary<string, object>(_dataCache);
|
{
|
||||||
|
// WebGL平台无法直接获取所有键值对,这里返回空字典
|
||||||
|
// 注意:实际项目中可能需要维护一个键值对的字典
|
||||||
|
return new Dictionary<string, object>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
return new Dictionary<string, object>(_dataCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -174,6 +274,12 @@ namespace Stary.Evo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static void LoadData()
|
private static void LoadData()
|
||||||
{
|
{
|
||||||
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
|
{
|
||||||
|
// WebGL平台使用PlayerPrefs,不需要从文件加载
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_isDataLoaded && _dataCache != null)
|
if (_isDataLoaded && _dataCache != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -234,6 +340,12 @@ namespace Stary.Evo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static void SaveData()
|
private static void SaveData()
|
||||||
{
|
{
|
||||||
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
|
{
|
||||||
|
// WebGL平台使用PlayerPrefs,不需要保存到文件
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_dataCache == null)
|
if (_dataCache == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -272,6 +384,12 @@ namespace Stary.Evo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Refresh()
|
public static void Refresh()
|
||||||
{
|
{
|
||||||
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||||
|
{
|
||||||
|
// WebGL平台使用PlayerPrefs,不需要刷新
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_isDataLoaded = false;
|
_isDataLoaded = false;
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.staryevo.main",
|
"name": "com.staryevo.main",
|
||||||
"version": "2.1.13",
|
"version": "2.1.14",
|
||||||
"displayName": "00.StaryEvo",
|
"displayName": "00.StaryEvo",
|
||||||
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
||||||
"unity": "2021.3",
|
"unity": "2021.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user