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

This commit is contained in:
2026-04-18 12:27:04 +08:00
parent 1b59e72d2c
commit 5737c35897
2 changed files with 153 additions and 35 deletions

View File

@@ -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
{
@@ -26,9 +25,17 @@ namespace Stary.Evo
/// <param name="value">值</param>
public static void SetString(string key, string value)
{
LoadData();
_dataCache[key] = value;
SaveData();
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
PlayerPrefs.SetString(key, value);
PlayerPrefs.Save();
}
else
{
LoadData();
_dataCache[key] = value;
SaveData();
}
}
/// <summary>
@@ -39,9 +46,16 @@ namespace Stary.Evo
/// <returns>值</returns>
public static string GetString(string key, string defaultValue = "")
{
LoadData();
_dataCache.TryGetValue(key, out var value);
return value is string ? (string)value : 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>
@@ -51,9 +65,17 @@ namespace Stary.Evo
/// <param name="value">值</param>
public static void SetInt(string key, int value)
{
LoadData();
_dataCache[key] = value;
SaveData();
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
PlayerPrefs.SetInt(key, value);
PlayerPrefs.Save();
}
else
{
LoadData();
_dataCache[key] = value;
SaveData();
}
}
/// <summary>
@@ -64,8 +86,15 @@ namespace Stary.Evo
/// <returns>值</returns>
public static int GetInt(string key, int defaultValue = 0)
{
LoadData();
return _dataCache.TryGetValue(key, out var value) ? (int)value : defaultValue;
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
return PlayerPrefs.GetInt(key, defaultValue);
}
else
{
LoadData();
return _dataCache.TryGetValue(key, out var value) ? (int)value : defaultValue;
}
}
/// <summary>
@@ -75,9 +104,17 @@ namespace Stary.Evo
/// <param name="value">值</param>
public static void SetFloat(string key, float value)
{
LoadData();
_dataCache[key] = value;
SaveData();
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
PlayerPrefs.SetFloat(key, value);
PlayerPrefs.Save();
}
else
{
LoadData();
_dataCache[key] = value;
SaveData();
}
}
/// <summary>
@@ -88,8 +125,15 @@ namespace Stary.Evo
/// <returns>值</returns>
public static float GetFloat(string key, float defaultValue = 0.0f)
{
LoadData();
return _dataCache.TryGetValue(key, out var value) ? (float)value : defaultValue;
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
return PlayerPrefs.GetFloat(key, defaultValue);
}
else
{
LoadData();
return _dataCache.TryGetValue(key, out var value) ? (float)value : defaultValue;
}
}
/// <summary>
@@ -99,9 +143,17 @@ namespace Stary.Evo
/// <param name="value">值</param>
public static void SetBool(string key, bool value)
{
LoadData();
_dataCache[key] = value;
SaveData();
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
PlayerPrefs.SetInt(key, value ? 1 : 0);
PlayerPrefs.Save();
}
else
{
LoadData();
_dataCache[key] = value;
SaveData();
}
}
/// <summary>
@@ -112,8 +164,15 @@ namespace Stary.Evo
/// <returns>值</returns>
public static bool GetBool(string key, bool defaultValue = false)
{
LoadData();
return _dataCache.TryGetValue(key, out var value) ? (bool)value : defaultValue;
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>
@@ -123,8 +182,15 @@ namespace Stary.Evo
/// <returns>是否存在</returns>
public static bool HasKey(string key)
{
LoadData();
return _dataCache.ContainsKey(key);
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
return PlayerPrefs.HasKey(key);
}
else
{
LoadData();
return _dataCache.ContainsKey(key);
}
}
/// <summary>
@@ -133,10 +199,18 @@ namespace Stary.Evo
/// <param name="key">键</param>
public static void DeleteKey(string key)
{
LoadData();
if (_dataCache.Remove(key))
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
SaveData();
PlayerPrefs.DeleteKey(key);
PlayerPrefs.Save();
}
else
{
LoadData();
if (_dataCache.Remove(key))
{
SaveData();
}
}
}
@@ -145,8 +219,16 @@ namespace Stary.Evo
/// </summary>
public static void DeleteAll()
{
_dataCache.Clear();
SaveData();
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
PlayerPrefs.DeleteAll();
PlayerPrefs.Save();
}
else
{
_dataCache.Clear();
SaveData();
}
}
/// <summary>
@@ -155,8 +237,17 @@ namespace Stary.Evo
/// <returns>键列表</returns>
public static string[] GetAllKeys()
{
LoadData();
return _dataCache.Keys.ToArray();
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
// WebGL平台无法直接获取所有键这里返回空数组
// 注意:实际项目中可能需要维护一个键的列表
return new string[0];
}
else
{
LoadData();
return _dataCache.Keys.ToArray();
}
}
/// <summary>
@@ -165,8 +256,17 @@ namespace Stary.Evo
/// <returns>键值对字典</returns>
public static Dictionary<string, object> GetAll()
{
LoadData();
return new Dictionary<string, object>(_dataCache);
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
// WebGL平台无法直接获取所有键值对这里返回空字典
// 注意:实际项目中可能需要维护一个键值对的字典
return new Dictionary<string, object>();
}
else
{
LoadData();
return new Dictionary<string, object>(_dataCache);
}
}
/// <summary>
@@ -174,6 +274,12 @@ namespace Stary.Evo
/// </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();
}

View File

@@ -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",