diff --git a/Editor/Batching.cs b/Editor/BatchingScope.cs
similarity index 80%
rename from Editor/Batching.cs
rename to Editor/BatchingScope.cs
index 8632f71..9b75147 100644
--- a/Editor/Batching.cs
+++ b/Editor/BatchingScope.cs
@@ -3,11 +3,11 @@
namespace GBG.EditorUserSettings.Editor
{
- public struct Batching : IDisposable
+ public struct BatchingScope : IDisposable
{
private IEditorUserSettingsStorage _storage;
- internal Batching(IEditorUserSettingsStorage storage)
+ internal BatchingScope(IEditorUserSettingsStorage storage)
{
_storage = storage;
Assert.IsTrue(_storage.BatchingCounter > 0);
diff --git a/Editor/Batching.cs.meta b/Editor/BatchingScope.cs.meta
similarity index 100%
rename from Editor/Batching.cs.meta
rename to Editor/BatchingScope.cs.meta
diff --git a/Editor/CustomEditorUserSettings.cs b/Editor/CustomEditorUserSettings.cs
index a99cb28..0d0051b 100644
--- a/Editor/CustomEditorUserSettings.cs
+++ b/Editor/CustomEditorUserSettings.cs
@@ -45,7 +45,7 @@ private static IEditorUserSettingsStorage GetStorage(bool isSharedAcrossProjects
private static void TryDestroy(this IEditorUserSettingsStorage storage, bool isSharedAcrossProjects)
{
- if (isSharedAcrossProjects && storage.BatchingCounter == 0)
+ if (isSharedAcrossProjects && storage != null && storage.BatchingCounter == 0)
{
storage.Destroy();
}
@@ -165,5 +165,32 @@ public static void Clear(bool isSharedAcrossProjects = false)
storage.Clear();
storage.TryDestroy(isSharedAcrossProjects);
}
+
+
+ ///
+ /// 开始批量编辑模式。
+ /// 批量编辑模式下,修改配置时不会立即将配置写入文件,而是等到批量编辑模式结束时才写入。
+ ///
+ /// 配置是否在项目间共享。若为true,则在/UserSettings文件夹中查找;否则在项目/../UserSettings文件夹下查找。
+ /// 批处理区域对象。可配合using语句块使用。
+ public static BatchingScope StartBatching(bool isSharedAcrossProjects = false)
+ {
+ IEditorUserSettingsStorage storage = GetStorage(isSharedAcrossProjects);
+ BatchingScope scope = storage.StartBatching();
+ storage.TryDestroy(isSharedAcrossProjects);
+
+ return scope;
+ }
+
+ ///
+ /// 结束批量编辑模式。
+ ///
+ /// 配置是否在项目间共享。若为true,则在/UserSettings文件夹中查找;否则在项目/../UserSettings文件夹下查找。
+ public static void EndBatching(bool isSharedAcrossProjects = false)
+ {
+ IEditorUserSettingsStorage storage = GetStorage(isSharedAcrossProjects);
+ storage.EndBatching();
+ storage.TryDestroy(isSharedAcrossProjects);
+ }
}
}
diff --git a/Editor/EditorUserSettingsStorage.cs b/Editor/EditorUserSettingsStorage.cs
index de55b58..397cc70 100644
--- a/Editor/EditorUserSettingsStorage.cs
+++ b/Editor/EditorUserSettingsStorage.cs
@@ -121,10 +121,10 @@ public void Clear()
}
- public Batching StartBatching()
+ public BatchingScope StartBatching()
{
BatchingCounter++;
- return new Batching(this);
+ return new BatchingScope(this);
}
public void EndBatching()
diff --git a/Editor/IEditorUserSettingsStorage.cs b/Editor/IEditorUserSettingsStorage.cs
index bc04d4e..5a96a09 100644
--- a/Editor/IEditorUserSettingsStorage.cs
+++ b/Editor/IEditorUserSettingsStorage.cs
@@ -4,7 +4,7 @@ internal interface IEditorUserSettingsStorage
{
uint BatchingCounter { get; }
- Batching StartBatching();
+ BatchingScope StartBatching();
void EndBatching();
diff --git a/README.md b/README.md
index 401cdb9..5223733 100644
--- a/README.md
+++ b/README.md
@@ -1,25 +1,55 @@
# EditorUserSettings
-TODO
+存储用于Unity Editor环境的自定义配置数据,可以控制是否在项目间共享这些配置数据。
Store custom settings data for Unity Editor environment, and control whether to share these settings data between projects.
-## Features
+## 支持的Unity版本
Supported Unity Versions
-TODO
+Unity 2019.4及更新版本。
Unity 2019.4 or higher.
-## Supported Unity Versions
+## 安装方式
Installation
-Unity 2021.3 or higher.
+[![openupm](https://img.shields.io/npm/v/com.greenbamboogames.editorusersettings?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.greenbamboogames.editorusersettings/)
+使用 [OpenUPM](https://openupm.com/packages/com.greenbamboogames.editorusersettings) 安装此包,或者直接克隆此仓库到项目中。
Install this package via [OpenUPM](https://openupm.com/packages/com.greenbamboogames.editorusersettings), or clone this repository directly into the Packages folder of your project.
-## Installation
-[![openupm](https://img.shields.io/npm/v/com.greenbamboogames.editorusersettings?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.greenbamboogames.editorusersettings/)
+## 如何使用
How to Use
+
+### API
+
+```csharp
+static class CustomEditorUserSettings
+{
+ bool Has(string key, bool isSharedAcrossProjects = false);
+
+ T Get(string key, T defaultValue, bool isSharedAcrossProjects = false);
+ bool TryGet(string key, out T value);
+
+ void Set(string key, T value, bool isSharedAcrossProjects = false);
+
+ bool Remove(string key, bool isSharedAcrossProjects = false);
+ bool RemoveAll(bool isSharedAcrossProjects = false);
+
+ void Clear(bool isSharedAcrossProjects = false);
+
+ BatchingScope StartBatching(bool isSharedAcrossProjects = false);
+ void EndBatching(bool isSharedAcrossProjects = false);
+}
+```
+
+
+### 菜单项
Menu Items
-Install this package via [OpenUPM](https://openupm.com/packages/com.greenbamboogames.editorusersettings), or clone this repository directly into the Packages folder of your project.
+- Tools/Bamboo/Editor User Settings
+ - 检视项目配置存储对象:Inspect Storage Object for Project
+ - 在文件夹中显示项目配置存储对象:Show Storage Object for Project in Folder
+ - 检视跨项目配置存储对象:Inspect Storage Object Shared Across Projects
+ - 在文件夹中显示跨项目配置存储对象:Show Storage Object Shared Across Projects in Folder
-## How to Use
+## 已知问题
Known Issues
-TODO
\ No newline at end of file
+1. 读写跨项目配置数据时,没有添加文件锁机制,同时读写时,可能会导致数据丢失。
When reading and writing data across projects, there is no file lock mechanism added, and data may be lost when reading and writing at the same time.
+2. 读写跨项目配置数据时,低版本Unity可能无法读取某些高版本Unity存储的数据。
When reading and writing data across projects, lower versions of Unity may not be able to read some data stored by higher versions of Unity.
\ No newline at end of file
diff --git a/package.json b/package.json
index 4785a90..5b182c8 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,9 @@
{
"name": "com.greenbamboogames.editorusersettings",
- "version": "1.0.0-preview",
+ "version": "1.0.0",
"displayName": "Editor User Settings!",
"description": "Store user settings in Unity Editor.",
- "unity": "2022.3",
+ "unity": "2019.4",
"documentationUrl": "https://github.com/SolarianZ/EditorUserSettings",
"changelogUrl": "https://github.com/SolarianZ/EditorUserSettings/releases",
"licensesUrl": "https://github.com/SolarianZ/EditorUserSettings/blob/main/LICENSE",