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.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义EditorPrefs实现,数据存储在项目根目录的EditorPrefs.ini文件中
|
||||
/// 自定义PlayerPrefs实现,数据存储在项目根目录的PlayerPrefs.ini文件中
|
||||
/// </summary>
|
||||
public static class CustomPlayerPrefs
|
||||
{
|
||||
@@ -25,11 +24,19 @@ namespace Stary.Evo
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
public static void SetString(string key, string value)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
PlayerPrefs.SetString(key, value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
_dataCache[key] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字符串值
|
||||
@@ -38,11 +45,18 @@ namespace Stary.Evo
|
||||
/// <param name="defaultValue">默认值</param>
|
||||
/// <returns>值</returns>
|
||||
public static string GetString(string key, string defaultValue = "")
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
return PlayerPrefs.GetString(key, defaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
_dataCache.TryGetValue(key, out var value);
|
||||
return value is string ? (string)value : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置整数值
|
||||
@@ -50,11 +64,19 @@ namespace Stary.Evo
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
public static void SetInt(string key, int value)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
PlayerPrefs.SetInt(key, value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
_dataCache[key] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取整数值
|
||||
@@ -63,10 +85,17 @@ namespace Stary.Evo
|
||||
/// <param name="defaultValue">默认值</param>
|
||||
/// <returns>值</returns>
|
||||
public static int GetInt(string key, int defaultValue = 0)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
return PlayerPrefs.GetInt(key, defaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
return _dataCache.TryGetValue(key, out var value) ? (int)value : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置浮点数值
|
||||
@@ -74,11 +103,19 @@ namespace Stary.Evo
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
public static void SetFloat(string key, float value)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
PlayerPrefs.SetFloat(key, value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
_dataCache[key] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取浮点数值
|
||||
@@ -87,10 +124,17 @@ namespace Stary.Evo
|
||||
/// <param name="defaultValue">默认值</param>
|
||||
/// <returns>值</returns>
|
||||
public static float GetFloat(string key, float defaultValue = 0.0f)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
return PlayerPrefs.GetFloat(key, defaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
return _dataCache.TryGetValue(key, out var value) ? (float)value : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置布尔值
|
||||
@@ -98,11 +142,19 @@ namespace Stary.Evo
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
public static void SetBool(string key, bool value)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
PlayerPrefs.SetInt(key, value ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
_dataCache[key] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取布尔值
|
||||
@@ -111,10 +163,17 @@ namespace Stary.Evo
|
||||
/// <param name="defaultValue">默认值</param>
|
||||
/// <returns>值</returns>
|
||||
public static bool GetBool(string key, bool defaultValue = false)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
return PlayerPrefs.GetInt(key, defaultValue ? 1 : 0) == 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
return _dataCache.TryGetValue(key, out var value) ? (bool)value : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在指定的键
|
||||
@@ -122,16 +181,30 @@ namespace Stary.Evo
|
||||
/// <param name="key">键</param>
|
||||
/// <returns>是否存在</returns>
|
||||
public static bool HasKey(string key)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
return PlayerPrefs.HasKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
return _dataCache.ContainsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定的键
|
||||
/// </summary>
|
||||
/// <param name="key">键</param>
|
||||
public static void DeleteKey(string key)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
PlayerPrefs.DeleteKey(key);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
if (_dataCache.Remove(key))
|
||||
@@ -139,41 +212,74 @@ namespace Stary.Evo
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有数据
|
||||
/// </summary>
|
||||
public static void DeleteAll()
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
PlayerPrefs.DeleteAll();
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
_dataCache.Clear();
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有键
|
||||
/// </summary>
|
||||
/// <returns>键列表</returns>
|
||||
public static string[] GetAllKeys()
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
// WebGL平台无法直接获取所有键,这里返回空数组
|
||||
// 注意:实际项目中可能需要维护一个键的列表
|
||||
return new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
return _dataCache.Keys.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有键值对
|
||||
/// </summary>
|
||||
/// <returns>键值对字典</returns>
|
||||
public static Dictionary<string, object> GetAll()
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
// WebGL平台无法直接获取所有键值对,这里返回空字典
|
||||
// 注意:实际项目中可能需要维护一个键值对的字典
|
||||
return new Dictionary<string, object>();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData();
|
||||
return new Dictionary<string, object>(_dataCache);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从文件加载数据
|
||||
/// </summary>
|
||||
private static void LoadData()
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
// WebGL平台使用PlayerPrefs,不需要从文件加载
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isDataLoaded && _dataCache != null)
|
||||
return;
|
||||
|
||||
@@ -234,6 +340,12 @@ namespace Stary.Evo
|
||||
/// </summary>
|
||||
private static void SaveData()
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
// WebGL平台使用PlayerPrefs,不需要保存到文件
|
||||
return;
|
||||
}
|
||||
|
||||
if (_dataCache == null)
|
||||
return;
|
||||
|
||||
@@ -272,6 +384,12 @@ namespace Stary.Evo
|
||||
/// </summary>
|
||||
public static void Refresh()
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
{
|
||||
// WebGL平台使用PlayerPrefs,不需要刷新
|
||||
return;
|
||||
}
|
||||
|
||||
_isDataLoaded = false;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.main",
|
||||
"version": "2.1.13",
|
||||
"version": "2.1.14",
|
||||
"displayName": "00.StaryEvo",
|
||||
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
||||
"unity": "2021.3",
|
||||
|
||||
Reference in New Issue
Block a user