[增加]1. 增加配置表组件
This commit is contained in:
parent
8eb85e4e97
commit
34759c7698
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 88c4847cef0f75344b4a19859b93ade6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "GameFrameX.Config.Editor",
|
||||
"references": [
|
||||
"GameFrameX.Config.Runtime",
|
||||
"GameFrameX.Editor",
|
||||
"GameFrameX.Runtime"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4e5167f03c4832146a00edd5bd303acd
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f305fe33bebd4a84f8ae0dcc6f3ba111
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,72 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX.Config.Runtime;
|
||||
using GameFrameX.Editor;
|
||||
using UnityEditor;
|
||||
|
||||
namespace GameFrameX.Config.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ConfigComponent))]
|
||||
internal sealed class ConfigComponentInspector : GameFrameworkInspector
|
||||
{
|
||||
private SerializedProperty m_EnableLoadConfigUpdateEvent = null;
|
||||
private SerializedProperty m_CachedBytesSize = null;
|
||||
|
||||
// private HelperInfo<ConfigHelperBase> m_ConfigHelperInfo = new HelperInfo<ConfigHelperBase>("Config");
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
ConfigComponent t = (ConfigComponent)target;
|
||||
|
||||
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_EnableLoadConfigUpdateEvent);
|
||||
// m_ConfigHelperInfo.Draw();
|
||||
EditorGUILayout.PropertyField(m_CachedBytesSize);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
|
||||
{
|
||||
EditorGUILayout.LabelField("Config Count", t.Count.ToString());
|
||||
// EditorGUILayout.LabelField("Cached Bytes Size", t.CachedBytesSize.ToString());
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
protected override void OnCompileComplete()
|
||||
{
|
||||
base.OnCompileComplete();
|
||||
|
||||
RefreshTypeNames();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_EnableLoadConfigUpdateEvent = serializedObject.FindProperty("m_EnableLoadConfigUpdateEvent");
|
||||
m_CachedBytesSize = serializedObject.FindProperty("m_CachedBytesSize");
|
||||
|
||||
// m_ConfigHelperInfo.Init(serializedObject);
|
||||
|
||||
RefreshTypeNames();
|
||||
}
|
||||
|
||||
private void RefreshTypeNames()
|
||||
{
|
||||
// m_ConfigHelperInfo.Refresh();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 05f027e0b86c40a3904227a034e9ccbe
|
||||
timeCreated: 1712727735
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [2023] [ALianBlank of copyright owner][alianblank@outlook.com][https://alianblank.com/]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f2f5365ee24f83444b9079212029dbd4
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
README.md
20
README.md
|
@ -1 +1,19 @@
|
|||
# com.alianblank.gameframex.unity.config
|
||||
## HOMEPAGE
|
||||
|
||||
GameFrameX 的 Config 配置表组件
|
||||
|
||||
**Config 配置表组件 (Config Component)** - 提供配置表相关的接口。
|
||||
|
||||
# 使用文档(文档编写于GPT4)
|
||||
|
||||
## 注意事项
|
||||
|
||||
# 使用方式(任选其一)
|
||||
|
||||
1. 直接在 `manifest.json` 的文件中的 `dependencies` 节点下添加以下内容
|
||||
```json
|
||||
{"com.alianblank.gameframex.config": "https://github.com/AlianBlank/com.alianblank.gameframex.unity.config.git"}
|
||||
```
|
||||
2. 在Unity 的`Packages Manager` 中使用`Git URL` 的方式添加库,地址为:https://github.com/AlianBlank/com.alianblank.gameframex.unity.config.git
|
||||
|
||||
3. 直接下载仓库放置到Unity 项目的`Packages` 目录下。会自动加载识别
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 793705c162520234a94c17360e1bee51
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67ca712478182f3458b1de6e04a40f0a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b573c9cdb6fa400aad98d8501011f5a3
|
||||
timeCreated: 1712727724
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 75f5ed0dabec4bc09dc0bc7a90d00596
|
||||
timeCreated: 1712727724
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
[Preserve]
|
||||
public abstract class BaseDataTable<T> : IDataTable<T>
|
||||
{
|
||||
protected readonly SortedDictionary<long, T> LongDataMaps = new SortedDictionary<long, T>();
|
||||
protected readonly SortedDictionary<string, T> StringDataMaps = new SortedDictionary<string, T>();
|
||||
|
||||
protected readonly List<T> DataList = new List<T>();
|
||||
public abstract Task LoadAsync();
|
||||
|
||||
public T Get(int id)
|
||||
{
|
||||
LongDataMaps.TryGetValue(id, out T value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public T Get(string id)
|
||||
{
|
||||
StringDataMaps.TryGetValue(id, out T value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public T this[int id] => Get(id);
|
||||
|
||||
public T this[string id] => Get(id);
|
||||
|
||||
public int Count => Math.Max(LongDataMaps.Count, StringDataMaps.Count);
|
||||
|
||||
public T FirstOrDefault => DataList.FirstOrDefault();
|
||||
|
||||
public T LastOrDefault => DataList.LastOrDefault();
|
||||
|
||||
public T[] All => DataList.ToArray();
|
||||
|
||||
public T[] ToArray()
|
||||
{
|
||||
return DataList.ToArray();
|
||||
}
|
||||
|
||||
public T Find(Func<T, bool> func)
|
||||
{
|
||||
return DataList.FirstOrDefault(func);
|
||||
}
|
||||
|
||||
public T[] FindList(Func<T, bool> func)
|
||||
{
|
||||
return DataList.Where(func).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5b36772731a46569fe32c2a7405e08f
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,63 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
public sealed partial class ConfigManager : GameFrameworkModule, IConfigManager
|
||||
{
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
private struct ConfigData
|
||||
{
|
||||
private readonly bool m_BoolValue;
|
||||
private readonly int m_IntValue;
|
||||
private readonly float m_FloatValue;
|
||||
private readonly string m_StringValue;
|
||||
|
||||
public ConfigData(bool boolValue, int intValue, float floatValue, string stringValue)
|
||||
{
|
||||
m_BoolValue = boolValue;
|
||||
m_IntValue = intValue;
|
||||
m_FloatValue = floatValue;
|
||||
m_StringValue = stringValue;
|
||||
}
|
||||
|
||||
public bool BoolValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BoolValue;
|
||||
}
|
||||
}
|
||||
|
||||
public int IntValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_IntValue;
|
||||
}
|
||||
}
|
||||
|
||||
public float FloatValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_FloatValue;
|
||||
}
|
||||
}
|
||||
|
||||
public string StringValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_StringValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 321448c68eec4288bc88512a4516eea5
|
||||
timeCreated: 1712727724
|
|
@ -0,0 +1,444 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameFrameX.Asset.Runtime;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局配置管理器。
|
||||
/// </summary>
|
||||
public sealed partial class ConfigManager : GameFrameworkModule, IConfigManager
|
||||
{
|
||||
private readonly Dictionary<string, ConfigData> m_ConfigDatas;
|
||||
private IConfigHelper m_ConfigHelper;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化全局配置管理器的新实例。
|
||||
/// </summary>
|
||||
public ConfigManager()
|
||||
{
|
||||
m_ConfigDatas = new Dictionary<string, ConfigData>(StringComparer.Ordinal);
|
||||
m_ConfigHelper = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局配置项数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return m_ConfigDatas.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓冲二进制流的大小。
|
||||
/// </summary>
|
||||
public int CachedBytesSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0; // DataProvider<IConfigManager>.CachedBytesSize; }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 读取全局配置成功事件。
|
||||
/// </summary>
|
||||
public event EventHandler<ReadDataSuccessEventArgs> ReadDataSuccess
|
||||
{
|
||||
add { m_DataProvider.ReadDataSuccess += value; }
|
||||
remove { m_DataProvider.ReadDataSuccess -= value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置失败事件。
|
||||
/// </summary>
|
||||
public event EventHandler<ReadDataFailureEventArgs> ReadDataFailure
|
||||
{
|
||||
add { m_DataProvider.ReadDataFailure += value; }
|
||||
remove { m_DataProvider.ReadDataFailure -= value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置更新事件。
|
||||
/// </summary>
|
||||
public event EventHandler<ReadDataUpdateEventArgs> ReadDataUpdate
|
||||
{
|
||||
add { m_DataProvider.ReadDataUpdate += value; }
|
||||
remove { m_DataProvider.ReadDataUpdate -= value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置时加载依赖资源事件。
|
||||
/// </summary>
|
||||
public event EventHandler<ReadDataDependencyAssetEventArgs> ReadDataDependencyAsset
|
||||
{
|
||||
add { m_DataProvider.ReadDataDependencyAsset += value; }
|
||||
remove { m_DataProvider.ReadDataDependencyAsset -= value; }
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 全局配置管理器轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
protected override void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理全局配置管理器。
|
||||
/// </summary>
|
||||
protected override void Shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置资源管理器。
|
||||
/// </summary>
|
||||
/// <param name="assetManager">资源管理器。</param>
|
||||
public void SetAssetManager(IAssetManager assetManager)
|
||||
{
|
||||
// m_DataProvider.SetAssetManager(assetManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置全局配置辅助器。
|
||||
/// </summary>
|
||||
/// <param name="configHelper">全局配置辅助器。</param>
|
||||
public void SetConfigHelper(IConfigHelper configHelper)
|
||||
{
|
||||
GameFrameworkGuard.NotNull(configHelper, nameof(configHelper));
|
||||
m_ConfigHelper = configHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确保二进制流缓存分配足够大小的内存并缓存。
|
||||
/// </summary>
|
||||
/// <param name="ensureSize">要确保二进制流缓存分配内存的大小。</param>
|
||||
public void EnsureCachedBytesSize(int ensureSize)
|
||||
{
|
||||
// DataProvider<IConfigManager>.EnsureCachedBytesSize(ensureSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放缓存的二进制流。
|
||||
/// </summary>
|
||||
public void FreeCachedBytes()
|
||||
{
|
||||
// DataProvider<IConfigManager>.FreeCachedBytes();
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
public void ReadData(string configAssetName)
|
||||
{
|
||||
m_DataProvider.ReadData(configAssetName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="priority">加载全局配置资源的优先级。</param>
|
||||
public void ReadData(string configAssetName, int priority)
|
||||
{
|
||||
m_DataProvider.ReadData(configAssetName, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void ReadData(string configAssetName, object userData)
|
||||
{
|
||||
m_DataProvider.ReadData(configAssetName, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="priority">加载全局配置资源的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void ReadData(string configAssetName, int priority, object userData)
|
||||
{
|
||||
m_DataProvider.ReadData(configAssetName, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configString">要解析的全局配置字符串。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(string configString)
|
||||
{
|
||||
return m_DataProvider.ParseData(configString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configString">要解析的全局配置字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(string configString, object userData)
|
||||
{
|
||||
return m_DataProvider.ParseData(configString, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes)
|
||||
{
|
||||
return m_DataProvider.ParseData(configBytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes, object userData)
|
||||
{
|
||||
return m_DataProvider.ParseData(configBytes, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="startIndex">全局配置二进制流的起始位置。</param>
|
||||
/// <param name="length">全局配置二进制流的长度。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes, int startIndex, int length)
|
||||
{
|
||||
return m_DataProvider.ParseData(configBytes, startIndex, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="startIndex">全局配置二进制流的起始位置。</param>
|
||||
/// <param name="length">全局配置二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
return m_DataProvider.ParseData(configBytes, startIndex, length, userData);
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要检查全局配置项的名称。</param>
|
||||
/// <returns>指定的全局配置项是否存在。</returns>
|
||||
public bool HasConfig(string configName)
|
||||
{
|
||||
return GetConfigData(configName).HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取布尔值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的布尔值。</returns>
|
||||
public bool GetBool(string configName)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
if (!configData.HasValue)
|
||||
{
|
||||
throw new GameFrameworkException(Utility.Text.Format("Config name '{0}' is not exist.", configName));
|
||||
}
|
||||
|
||||
return configData.Value.BoolValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取布尔值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的布尔值。</returns>
|
||||
public bool GetBool(string configName, bool defaultValue)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
return configData.HasValue ? configData.Value.BoolValue : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取整数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的整数值。</returns>
|
||||
public int GetInt(string configName)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
if (!configData.HasValue)
|
||||
{
|
||||
throw new GameFrameworkException(Utility.Text.Format("Config name '{0}' is not exist.", configName));
|
||||
}
|
||||
|
||||
return configData.Value.IntValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取整数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的整数值。</returns>
|
||||
public int GetInt(string configName, int defaultValue)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
return configData.HasValue ? configData.Value.IntValue : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取浮点数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的浮点数值。</returns>
|
||||
public float GetFloat(string configName)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
if (!configData.HasValue)
|
||||
{
|
||||
throw new GameFrameworkException(Utility.Text.Format("Config name '{0}' is not exist.", configName));
|
||||
}
|
||||
|
||||
return configData.Value.FloatValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取浮点数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的浮点数值。</returns>
|
||||
public float GetFloat(string configName, float defaultValue)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
return configData.HasValue ? configData.Value.FloatValue : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取字符串值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的字符串值。</returns>
|
||||
public string GetString(string configName)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
if (!configData.HasValue)
|
||||
{
|
||||
throw new GameFrameworkException(Utility.Text.Format("Config name '{0}' is not exist.", configName));
|
||||
}
|
||||
|
||||
return configData.Value.StringValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取字符串值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的字符串值。</returns>
|
||||
public string GetString(string configName, string defaultValue)
|
||||
{
|
||||
ConfigData? configData = GetConfigData(configName);
|
||||
return configData.HasValue ? configData.Value.StringValue : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要增加全局配置项的名称。</param>
|
||||
/// <param name="configValue">全局配置项的值。</param>
|
||||
/// <returns>是否增加全局配置项成功。</returns>
|
||||
public bool AddConfig(string configName, string configValue)
|
||||
{
|
||||
bool.TryParse(configValue, out var boolValue);
|
||||
|
||||
int.TryParse(configValue, out var intValue);
|
||||
|
||||
float.TryParse(configValue, out var floatValue);
|
||||
|
||||
return AddConfig(configName, boolValue, intValue, floatValue, configValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要增加全局配置项的名称。</param>
|
||||
/// <param name="boolValue">全局配置项布尔值。</param>
|
||||
/// <param name="intValue">全局配置项整数值。</param>
|
||||
/// <param name="floatValue">全局配置项浮点数值。</param>
|
||||
/// <param name="stringValue">全局配置项字符串值。</param>
|
||||
/// <returns>是否增加全局配置项成功。</returns>
|
||||
public bool AddConfig(string configName, bool boolValue, int intValue, float floatValue, string stringValue)
|
||||
{
|
||||
if (HasConfig(configName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ConfigDatas.Add(configName, new ConfigData(boolValue, intValue, floatValue, stringValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要移除全局配置项的名称。</param>
|
||||
public bool RemoveConfig(string configName)
|
||||
{
|
||||
if (!HasConfig(configName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_ConfigDatas.Remove(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有全局配置项。
|
||||
/// </summary>
|
||||
public void RemoveAllConfigs()
|
||||
{
|
||||
m_ConfigDatas.Clear();
|
||||
}
|
||||
|
||||
private ConfigData? GetConfigData(string configName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(configName))
|
||||
{
|
||||
throw new GameFrameworkException("Config name is invalid.");
|
||||
}
|
||||
|
||||
if (m_ConfigDatas.TryGetValue(configName, out var configData))
|
||||
{
|
||||
return configData;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 29bb7c2590d44f4ea0ee1099a69ea304
|
||||
timeCreated: 1712727724
|
|
@ -0,0 +1,6 @@
|
|||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
public interface IConfigData
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 635f5e85d23e49a8849e3274afa77b73
|
||||
timeCreated: 1712727724
|
|
@ -0,0 +1,16 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局配置辅助器接口。
|
||||
/// </summary>
|
||||
public interface IConfigHelper
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d5bc217200e84c65bca0fc3f4c84f0d6
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,148 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX.Asset.Runtime;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局配置管理器接口。
|
||||
/// </summary>
|
||||
public interface IConfigManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取全局配置项数量。
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓冲二进制流的大小。
|
||||
/// </summary>
|
||||
int CachedBytesSize { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置资源管理器。
|
||||
/// </summary>
|
||||
/// <param name="assetManager">资源管理器。</param>
|
||||
void SetAssetManager(IAssetManager assetManager);
|
||||
|
||||
/// <summary>
|
||||
/// 设置全局配置辅助器。
|
||||
/// </summary>
|
||||
/// <param name="configHelper">全局配置辅助器。</param>
|
||||
void SetConfigHelper(IConfigHelper configHelper);
|
||||
|
||||
/// <summary>
|
||||
/// 确保二进制流缓存分配足够大小的内存并缓存。
|
||||
/// </summary>
|
||||
/// <param name="ensureSize">要确保二进制流缓存分配内存的大小。</param>
|
||||
void EnsureCachedBytesSize(int ensureSize);
|
||||
|
||||
/// <summary>
|
||||
/// 释放缓存的二进制流。
|
||||
/// </summary>
|
||||
void FreeCachedBytes();
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要检查全局配置项的名称。</param>
|
||||
/// <returns>指定的全局配置项是否存在。</returns>
|
||||
bool HasConfig(string configName);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取布尔值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的布尔值。</returns>
|
||||
bool GetBool(string configName);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取布尔值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的布尔值。</returns>
|
||||
bool GetBool(string configName, bool defaultValue);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取整数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的整数值。</returns>
|
||||
int GetInt(string configName);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取整数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的整数值。</returns>
|
||||
int GetInt(string configName, int defaultValue);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取浮点数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的浮点数值。</returns>
|
||||
float GetFloat(string configName);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取浮点数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的浮点数值。</returns>
|
||||
float GetFloat(string configName, float defaultValue);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取字符串值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的字符串值。</returns>
|
||||
string GetString(string configName);
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取字符串值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的字符串值。</returns>
|
||||
string GetString(string configName, string defaultValue);
|
||||
|
||||
/// <summary>
|
||||
/// 增加指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要增加全局配置项的名称。</param>
|
||||
/// <param name="configValue">全局配置项的值。</param>
|
||||
/// <returns>是否增加全局配置项成功。</returns>
|
||||
bool AddConfig(string configName, string configValue);
|
||||
|
||||
/// <summary>
|
||||
/// 增加指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要增加全局配置项的名称。</param>
|
||||
/// <param name="boolValue">全局配置项布尔值。</param>
|
||||
/// <param name="intValue">全局配置项整数值。</param>
|
||||
/// <param name="floatValue">全局配置项浮点数值。</param>
|
||||
/// <param name="stringValue">全局配置项字符串值。</param>
|
||||
/// <returns>是否增加全局配置项成功。</returns>
|
||||
bool AddConfig(string configName, bool boolValue, int intValue, float floatValue, string stringValue);
|
||||
|
||||
/// <summary>
|
||||
/// 移除指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要移除全局配置项的名称。</param>
|
||||
/// <returns>是否移除全局配置项成功。</returns>
|
||||
bool RemoveConfig(string configName);
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有全局配置项。
|
||||
/// </summary>
|
||||
void RemoveAllConfigs();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9778ae1ff9ca4093bf6a7ed27e5beadb
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,94 @@
|
|||
using System.Threading.Tasks;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
public interface IDataTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步加载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task LoadAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表中对象的数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
int Count { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据表基础接口
|
||||
/// </summary>
|
||||
[Preserve]
|
||||
public interface IDataTable<out T> : IDataTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取对象
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
T Get(int id);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取对象
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
T Get(string id);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取对象
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
T this[int id] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取对象
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
T this[string id] { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表中第一个对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
T FirstOrDefault { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表中最后一个对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
T LastOrDefault { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表中所有对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
T[] All { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表中所有对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
T[] ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查找
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <returns></returns>
|
||||
T Find(System.Func<T, bool> func);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查找
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <returns></returns>
|
||||
T[] FindList(System.Func<T, bool> func);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f048a3a77e0348768c491e66f94a6bbd
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,336 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX.Event.Runtime;
|
||||
using GameFrameX.Runtime;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局配置组件。
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Game Framework/Config")]
|
||||
public sealed class ConfigComponent : GameFrameworkComponent
|
||||
{
|
||||
private IConfigManager m_ConfigManager = null;
|
||||
private EventComponent m_EventComponent = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局配置项数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return m_ConfigManager.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架组件初始化。
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
new ConfigManager();
|
||||
m_ConfigManager = GameFrameworkEntry.GetModule<IConfigManager>();
|
||||
if (m_ConfigManager == null)
|
||||
{
|
||||
Log.Fatal("Config manager is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
BaseComponent baseComponent = GameEntry.GetComponent<BaseComponent>();
|
||||
if (baseComponent == null)
|
||||
{
|
||||
Log.Fatal("Base component is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_EventComponent = GameEntry.GetComponent<EventComponent>();
|
||||
if (m_EventComponent == null)
|
||||
{
|
||||
Log.Fatal("Event component is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private System.Collections.Generic.Dictionary<string, IDataTable> m_Tables = new System.Collections.Generic.Dictionary<string, IDataTable>();
|
||||
|
||||
public System.Collections.Generic.IEnumerable<IDataTable> DataTables => m_Tables.Values;
|
||||
|
||||
public BaseDataTable<T> GetDataTable<T>(string tableName)
|
||||
{
|
||||
bool isExist = m_Tables.TryGetValue(tableName, out var value) ;
|
||||
if (isExist)
|
||||
{
|
||||
return (BaseDataTable<T>)value;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
/*
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
public void ReadData(string configAssetName)
|
||||
{
|
||||
m_ConfigManager.ReadData(configAssetName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="priority">加载全局配置资源的优先级。</param>
|
||||
public void ReadData(string configAssetName, int priority)
|
||||
{
|
||||
m_ConfigManager.ReadData(configAssetName, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void ReadData(string configAssetName, object userData)
|
||||
{
|
||||
m_ConfigManager.ReadData(configAssetName, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="priority">加载全局配置资源的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void ReadData(string configAssetName, int priority, object userData)
|
||||
{
|
||||
m_ConfigManager.ReadData(configAssetName, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configString">要解析的全局配置字符串。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(string configString)
|
||||
{
|
||||
return m_ConfigManager.ParseData(configString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configString">要解析的全局配置字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(string configString, object userData)
|
||||
{
|
||||
return m_ConfigManager.ParseData(configString, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes)
|
||||
{
|
||||
return m_ConfigManager.ParseData(configBytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes, object userData)
|
||||
{
|
||||
return m_ConfigManager.ParseData(configBytes, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="startIndex">全局配置二进制流的起始位置。</param>
|
||||
/// <param name="length">全局配置二进制流的长度。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes, int startIndex, int length)
|
||||
{
|
||||
return m_ConfigManager.ParseData(configBytes, startIndex, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="startIndex">全局配置二进制流的起始位置。</param>
|
||||
/// <param name="length">全局配置二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public bool ParseData(byte[] configBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
return m_ConfigManager.ParseData(configBytes, startIndex, length, userData);
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要检查全局配置项的名称。</param>
|
||||
/// <returns>指定的全局配置项是否存在。</returns>
|
||||
public bool HasConfig(string configName)
|
||||
{
|
||||
return m_ConfigManager.HasConfig(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取布尔值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的布尔值。</returns>
|
||||
public bool GetBool(string configName)
|
||||
{
|
||||
return m_ConfigManager.GetBool(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取布尔值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的布尔值。</returns>
|
||||
public bool GetBool(string configName, bool defaultValue)
|
||||
{
|
||||
return m_ConfigManager.GetBool(configName, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取整数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的整数值。</returns>
|
||||
public int GetInt(string configName)
|
||||
{
|
||||
return m_ConfigManager.GetInt(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取整数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的整数值。</returns>
|
||||
public int GetInt(string configName, int defaultValue)
|
||||
{
|
||||
return m_ConfigManager.GetInt(configName, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取浮点数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的浮点数值。</returns>
|
||||
public float GetFloat(string configName)
|
||||
{
|
||||
return m_ConfigManager.GetFloat(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取浮点数值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的浮点数值。</returns>
|
||||
public float GetFloat(string configName, float defaultValue)
|
||||
{
|
||||
return m_ConfigManager.GetFloat(configName, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取字符串值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <returns>读取的字符串值。</returns>
|
||||
public string GetString(string configName)
|
||||
{
|
||||
return m_ConfigManager.GetString(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定全局配置项中读取字符串值。
|
||||
/// </summary>
|
||||
/// <param name="configName">要获取全局配置项的名称。</param>
|
||||
/// <param name="defaultValue">当指定的全局配置项不存在时,返回此默认值。</param>
|
||||
/// <returns>读取的字符串值。</returns>
|
||||
public string GetString(string configName, string defaultValue)
|
||||
{
|
||||
return m_ConfigManager.GetString(configName, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要增加全局配置项的名称。</param>
|
||||
/// <param name="boolValue">全局配置项布尔值。</param>
|
||||
/// <param name="intValue">全局配置项整数值。</param>
|
||||
/// <param name="floatValue">全局配置项浮点数值。</param>
|
||||
/// <param name="stringValue">全局配置项字符串值。</param>
|
||||
/// <returns>是否增加全局配置项成功。</returns>
|
||||
public bool AddConfig(string configName, bool boolValue, int intValue, float floatValue, string stringValue)
|
||||
{
|
||||
return m_ConfigManager.AddConfig(configName, boolValue, intValue, floatValue, stringValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除指定全局配置项。
|
||||
/// </summary>
|
||||
/// <param name="configName">要移除全局配置项的名称。</param>
|
||||
/// <returns>是否移除全局配置项成功。</returns>
|
||||
public bool RemoveConfig(string configName)
|
||||
{
|
||||
return m_ConfigManager.RemoveConfig(configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有全局配置项。
|
||||
/// </summary>
|
||||
public void RemoveAllConfigs()
|
||||
{
|
||||
m_ConfigManager.RemoveAllConfigs();
|
||||
}
|
||||
|
||||
/*
|
||||
private void OnReadDataSuccess(object sender, ReadDataSuccessEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, LoadConfigSuccessEventArgs.Create(e.DataAssetName, e.Duration, e.UserData));
|
||||
}
|
||||
|
||||
private void OnReadDataFailure(object sender, ReadDataFailureEventArgs e)
|
||||
{
|
||||
Log.Warning("Load config failure, asset name '{0}', error message '{1}'.", e.DataAssetName, e.ErrorMessage);
|
||||
m_EventComponent.Fire(this, LoadConfigFailureEventArgs.Create(e.DataAssetName, e.ErrorMessage, e.UserData));
|
||||
}
|
||||
|
||||
private void OnReadDataUpdate(object sender, ReadDataUpdateEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, LoadConfigUpdateEventArgs.Create(e.DataAssetName, e.Progress, e.UserData));
|
||||
}*/
|
||||
public void Add(string tbBlackboardName, IDataTable dataTable)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: be92abf1b6aa472c9ff7ebd49bbab9bf
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX;
|
||||
using GameFrameX.Config;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameFrameX.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认全局配置辅助器。
|
||||
/// </summary>
|
||||
public class DefaultConfigHelper : ConfigHelperBase
|
||||
{
|
||||
private static readonly string[] ColumnSplitSeparator = new string[] { "\t" };
|
||||
private static readonly string BytesAssetExtension = ".bytes";
|
||||
private const int ColumnCount = 4;
|
||||
|
||||
private AssetComponent m_ResourceComponent = null;
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configManager">全局配置管理器。</param>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="configAsset">全局配置资源。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否读取全局配置成功。</returns>
|
||||
public override bool ReadData(IConfigManager configManager, string configAssetName, object configAsset, object userData)
|
||||
{
|
||||
TextAsset configTextAsset = configAsset as TextAsset;
|
||||
if (configTextAsset != null)
|
||||
{
|
||||
if (configAssetName.EndsWith(BytesAssetExtension, StringComparison.Ordinal))
|
||||
{
|
||||
return configManager.ParseData(configTextAsset.bytes, userData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return configManager.ParseData(configTextAsset.text, userData);
|
||||
}
|
||||
}
|
||||
|
||||
Log.Warning("Config asset '{0}' is invalid.", configAssetName);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configManager">全局配置管理器。</param>
|
||||
/// <param name="configAssetName">全局配置资源名称。</param>
|
||||
/// <param name="configBytes">全局配置二进制流。</param>
|
||||
/// <param name="startIndex">全局配置二进制流的起始位置。</param>
|
||||
/// <param name="length">全局配置二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否读取全局配置成功。</returns>
|
||||
public override bool ReadData(IConfigManager configManager, string configAssetName, byte[] configBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
if (configAssetName.EndsWith(BytesAssetExtension, StringComparison.Ordinal))
|
||||
{
|
||||
return configManager.ParseData(configBytes, startIndex, length, userData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return configManager.ParseData(Utility.Converter.GetString(configBytes, startIndex, length), userData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configManager">全局配置管理器。</param>
|
||||
/// <param name="configString">要解析的全局配置字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public override bool ParseData(IConfigManager configManager, string configString, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
int position = 0;
|
||||
string configLineString = null;
|
||||
while ((configLineString = configString.ReadLine(ref position)) != null)
|
||||
{
|
||||
if (configLineString[0] == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] splitedLine = configLineString.Split(ColumnSplitSeparator, StringSplitOptions.None);
|
||||
if (splitedLine.Length != ColumnCount)
|
||||
{
|
||||
Log.Warning("Can not parse config line string '{0}' which column count is invalid.", configLineString);
|
||||
return false;
|
||||
}
|
||||
|
||||
string configName = splitedLine[1];
|
||||
string configValue = splitedLine[3];
|
||||
if (!configManager.AddConfig(configName, configValue))
|
||||
{
|
||||
Log.Warning("Can not add config with config name '{0}' which may be invalid or duplicate.", configName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Warning("Can not parse config string with exception '{0}'.", exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析全局配置。
|
||||
/// </summary>
|
||||
/// <param name="configManager">全局配置管理器。</param>
|
||||
/// <param name="configBytes">要解析的全局配置二进制流。</param>
|
||||
/// <param name="startIndex">全局配置二进制流的起始位置。</param>
|
||||
/// <param name="length">全局配置二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析全局配置成功。</returns>
|
||||
public override bool ParseData(IConfigManager configManager, byte[] configBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(configBytes, startIndex, length, false))
|
||||
{
|
||||
using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
|
||||
{
|
||||
while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
|
||||
{
|
||||
string configName = binaryReader.ReadString();
|
||||
string configValue = binaryReader.ReadString();
|
||||
if (!configManager.AddConfig(configName, configValue))
|
||||
{
|
||||
Log.Warning("Can not add config with config name '{0}' which may be invalid or duplicate.", configName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Warning("Can not parse config bytes with exception '{0}'.", exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放全局配置资源。
|
||||
/// </summary>
|
||||
/// <param name="configManager">全局配置管理器。</param>
|
||||
/// <param name="configAsset">要释放的全局配置资源。</param>
|
||||
public override void ReleaseDataAsset(IConfigManager configManager, object configAsset)
|
||||
{
|
||||
m_ResourceComponent.UnloadAsset(configAsset);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_ResourceComponent = GameEntry.GetComponent<ResourceComponent>();
|
||||
if (m_ResourceComponent == null)
|
||||
{
|
||||
Log.Fatal("Resource component is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cc9c1f7807594e88b15360cdac1e2b89
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f1c8c93ff08b403c8e0b8cc7f05d24f3
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,81 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX.Event.Runtime;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载全局配置失败事件。
|
||||
/// </summary>
|
||||
public sealed class LoadConfigFailureEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载全局配置失败事件编号。
|
||||
/// </summary>
|
||||
public static readonly string EventId = typeof(LoadConfigFailureEventArgs).FullName;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载全局配置失败事件的新实例。
|
||||
/// </summary>
|
||||
public LoadConfigFailureEventArgs()
|
||||
{
|
||||
ConfigAssetName = null;
|
||||
ErrorMessage = null;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载全局配置失败事件编号。
|
||||
/// </summary>
|
||||
public override string Id
|
||||
{
|
||||
get { return EventId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局配置资源名称。
|
||||
/// </summary>
|
||||
public string ConfigAssetName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取错误信息。
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载全局配置失败事件。
|
||||
/// </summary>
|
||||
/// <param name="dataAssetName"></param>
|
||||
/// <param name="errorMessage"></param>
|
||||
/// <param name="userData"></param>
|
||||
/// <returns>创建的加载全局配置失败事件。</returns>
|
||||
public static LoadConfigFailureEventArgs Create(string dataAssetName, string errorMessage, object userData)
|
||||
{
|
||||
LoadConfigFailureEventArgs loadConfigFailureEventArgs = ReferencePool.Acquire<LoadConfigFailureEventArgs>();
|
||||
loadConfigFailureEventArgs.ConfigAssetName = dataAssetName;
|
||||
loadConfigFailureEventArgs.ErrorMessage = errorMessage;
|
||||
loadConfigFailureEventArgs.UserData = userData;
|
||||
return loadConfigFailureEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载全局配置失败事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
ConfigAssetName = null;
|
||||
ErrorMessage = null;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ae4025af07d84460858838f0d53694d4
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,81 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX.Event.Runtime;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载全局配置成功事件。
|
||||
/// </summary>
|
||||
public sealed class LoadConfigSuccessEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载全局配置成功事件编号。
|
||||
/// </summary>
|
||||
public static readonly string EventId = typeof(LoadConfigSuccessEventArgs).FullName;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载全局配置成功事件编号的新实例。
|
||||
/// </summary>
|
||||
public LoadConfigSuccessEventArgs()
|
||||
{
|
||||
ConfigAssetName = null;
|
||||
Duration = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载全局配置成功事件编号。
|
||||
/// </summary>
|
||||
public override string Id
|
||||
{
|
||||
get { return EventId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局配置资源名称。
|
||||
/// </summary>
|
||||
public string ConfigAssetName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载持续时间。
|
||||
/// </summary>
|
||||
public float Duration { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载全局配置成功事件。
|
||||
/// </summary>
|
||||
/// <param name="dataAssetName"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <param name="userData"></param>
|
||||
/// <returns>创建的加载全局配置成功事件。</returns>
|
||||
public static LoadConfigSuccessEventArgs Create(string dataAssetName, float duration, object userData)
|
||||
{
|
||||
LoadConfigSuccessEventArgs loadConfigSuccessEventArgs = ReferencePool.Acquire<LoadConfigSuccessEventArgs>();
|
||||
loadConfigSuccessEventArgs.ConfigAssetName = dataAssetName;
|
||||
loadConfigSuccessEventArgs.Duration = duration;
|
||||
loadConfigSuccessEventArgs.UserData = userData;
|
||||
return loadConfigSuccessEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载全局配置成功事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
ConfigAssetName = null;
|
||||
Duration = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 927588170db145caaf8810ca6d80ecc2
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,81 @@
|
|||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFrameX.Event.Runtime;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载全局配置更新事件。
|
||||
/// </summary>
|
||||
public sealed class LoadConfigUpdateEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载全局配置失败事件编号。
|
||||
/// </summary>
|
||||
public static readonly string EventId = typeof(LoadConfigUpdateEventArgs).FullName;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载全局配置更新事件的新实例。
|
||||
/// </summary>
|
||||
public LoadConfigUpdateEventArgs()
|
||||
{
|
||||
ConfigAssetName = null;
|
||||
Progress = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载全局配置失败事件编号。
|
||||
/// </summary>
|
||||
public override string Id
|
||||
{
|
||||
get { return EventId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局配置资源名称。
|
||||
/// </summary>
|
||||
public string ConfigAssetName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载全局配置进度。
|
||||
/// </summary>
|
||||
public float Progress { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载全局配置更新事件。
|
||||
/// </summary>
|
||||
/// <param name="dataAssetName"></param>
|
||||
/// <param name="progress"></param>
|
||||
/// <param name="userData"></param>
|
||||
/// <returns>创建的加载全局配置更新事件。</returns>
|
||||
public static LoadConfigUpdateEventArgs Create(string dataAssetName, float progress, object userData)
|
||||
{
|
||||
LoadConfigUpdateEventArgs loadConfigUpdateEventArgs = ReferencePool.Acquire<LoadConfigUpdateEventArgs>();
|
||||
loadConfigUpdateEventArgs.ConfigAssetName = dataAssetName;
|
||||
loadConfigUpdateEventArgs.Progress = progress;
|
||||
loadConfigUpdateEventArgs.UserData = userData;
|
||||
return loadConfigUpdateEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载全局配置更新事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
ConfigAssetName = null;
|
||||
Progress = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1ce0b7f1a934430b3f36521833d9e24
|
||||
timeCreated: 1712727725
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "GameFrameX.Config.Runtime",
|
||||
"references": [
|
||||
"GameFrameX.Runtime",
|
||||
"GameFrameX.Event.Runtime",
|
||||
"GameFrameX.Asset.Runtime"
|
||||
],
|
||||
"rootNamespace": "GameFrameX.Config.Runtime",
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c999e23336e1c6a459b7a3ab2d192daf
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace GameFrameX.Config.Runtime
|
||||
{
|
||||
public class GameFrameXConfigCroppingHelper : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
_ = typeof(ConfigManager);
|
||||
_ = typeof(IConfigData);
|
||||
_ = typeof(IConfigHelper);
|
||||
_ = typeof(IConfigManager);
|
||||
_ = typeof(LoadConfigFailureEventArgs);
|
||||
_ = typeof(LoadConfigSuccessEventArgs);
|
||||
_ = typeof(LoadConfigUpdateEventArgs);
|
||||
_ = typeof(IDataTable<>);
|
||||
_ = typeof(BaseDataTable<>);
|
||||
_ = typeof(ConfigComponent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 412b80a447a75c942b5d430c87670939
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 27074b333c578c247a558a7a1e310658
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "GameFrameX.Config.Tests",
|
||||
"references": [
|
||||
"GameFrameX.Config.Runtime"
|
||||
],
|
||||
"rootNamespace": "GameFrameX.Config.Tests",
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e414e7b89d9261040b2f23fda6bf9b0b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GameFrameX.Config.Tests
|
||||
{
|
||||
internal class UnitTests
|
||||
{
|
||||
private DateTime dateTime, dateTime1;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
dateTime = DateTime.Now;
|
||||
dateTime1 = DateTime.Now.AddHours(1);
|
||||
}
|
||||
|
||||
// Here is an example of a unit test for the IsUnixSameDay method
|
||||
[Test]
|
||||
public void TestIsUnixSameDay()
|
||||
{
|
||||
// Arrange
|
||||
// long timestamp1 = 1617842400; // April 7, 2021 12:00:00 AM UTC
|
||||
// long timestamp2 = 1617896400; // April 7, 2021 12:00:00 PM UTC
|
||||
|
||||
// Act
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
Assert.That(dateTime1.Year, Is.EqualTo(dateTime.Year));
|
||||
Assert.That(dateTime1.Month, Is.EqualTo(dateTime.Month));
|
||||
Assert.That(dateTime1.Day, Is.EqualTo(dateTime.Day));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bc4ef0e769040a54e88c54b53a463d9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "com.alianblank.gameframex.config",
|
||||
"displayName": "Game Frame X Config",
|
||||
"category": "Game Framework X",
|
||||
"description": "Game Frame X Config Component",
|
||||
"version": "1.0.0",
|
||||
"unity": "2017.1",
|
||||
"keywords": [
|
||||
"Game Framework X"
|
||||
],
|
||||
"repository": {
|
||||
"name": "com.alianblank.gameframex.config",
|
||||
"url": "https://github.com/AlianBlank/com.alianblank.gameframex.unity.config.git",
|
||||
"type": "git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Blank",
|
||||
"email": "alianblank@outlook.com",
|
||||
"url": "https://alianblank.com/"
|
||||
},
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a6fb72627accb0d47948959f565d2ea0
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue