饭太稀
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Fantasy.ConfigTable",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:0b7224b83ba514121aa026f3857f820a"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4d36c5a80dc44c6e822eba8db9ed704
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfbf88374cb6b49f2947ab95a9bc08ba
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Fantasy.Serialize;
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
// ReSharper disable SuspiciousTypeConversion.Global
|
||||
|
||||
namespace Fantasy.ConfigTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置表帮助类
|
||||
/// </summary>
|
||||
public static class ConfigTableHelper
|
||||
{
|
||||
private static string _assetBundleDirectoryPath;
|
||||
private static IConfigTableAssetBundle _configTableAssetBundle;
|
||||
private static readonly object Lock = new object();
|
||||
// 配置表数据缓存字典
|
||||
private static readonly Dictionary<string, ASerialize> ConfigDic = new ();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化ConfigTableHelper
|
||||
/// </summary>
|
||||
/// <param name="assetBundleDirectoryPath"></param>
|
||||
/// <param name="configTableAssetBundle"></param>
|
||||
public static void Initialize(string assetBundleDirectoryPath, IConfigTableAssetBundle configTableAssetBundle)
|
||||
{
|
||||
_assetBundleDirectoryPath = assetBundleDirectoryPath;
|
||||
_configTableAssetBundle = configTableAssetBundle;
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载配置表数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T">配置表类型</typeparam>
|
||||
/// <returns>配置表数据</returns>
|
||||
public static T Load<T>() where T : ASerialize
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataConfig = typeof(T).Name;
|
||||
|
||||
if (ConfigDic.TryGetValue(dataConfig, out var aProto))
|
||||
{
|
||||
return (T)aProto;
|
||||
}
|
||||
|
||||
var dataConfigPath = _configTableAssetBundle.Combine(_assetBundleDirectoryPath, dataConfig);
|
||||
var bytes = _configTableAssetBundle.LoadConfigTable(dataConfigPath);
|
||||
var data = SerializerManager.GetSerializer(FantasySerializerType.ProtoBuf).Deserialize<T>(bytes);
|
||||
ConfigDic[dataConfig] = data;
|
||||
return data;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"ConfigTableManage:{typeof(T).Name} 数据表加载之后反序列化时出错:{ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重新加载配置表数据
|
||||
/// </summary>
|
||||
public static void ReLoadConfigTable()
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
foreach (var (_, aProto) in ConfigDic)
|
||||
{
|
||||
((IDisposable) aProto).Dispose();
|
||||
}
|
||||
|
||||
ConfigDic.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e3ca7a021b1c445a9f58c1e4645fe17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e10a07ad20ee4d7298ee808a3ea8b73
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using ProtoBuf;
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
// ReSharper disable CheckNamespace
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
namespace Fantasy.ConfigTable
|
||||
{
|
||||
[ProtoContract]
|
||||
public partial class IntDictionaryConfig
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public Dictionary<int, int> Dic;
|
||||
public int this[int key] => GetValue(key);
|
||||
public bool TryGetValue(int key, out int value)
|
||||
{
|
||||
value = default;
|
||||
|
||||
if (!Dic.ContainsKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = Dic[key];
|
||||
return true;
|
||||
}
|
||||
private int GetValue(int key)
|
||||
{
|
||||
return Dic.TryGetValue(key, out var value) ? value : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 294753d61a7ac401f9f1b75e43d7536e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using ProtoBuf;
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
// ReSharper disable CheckNamespace
|
||||
// ReSharper disable CollectionNeverUpdated.Global
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
namespace Fantasy.ConfigTable
|
||||
{
|
||||
[ProtoContract]
|
||||
public sealed partial class StringDictionaryConfig
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public Dictionary<int, string> Dic;
|
||||
public string this[int key] => GetValue(key);
|
||||
public bool TryGetValue(int key, out string value)
|
||||
{
|
||||
value = default;
|
||||
|
||||
if (!Dic.ContainsKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = Dic[key];
|
||||
return true;
|
||||
}
|
||||
private string GetValue(int key)
|
||||
{
|
||||
return Dic.TryGetValue(key, out var value) ? value : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 295679520921148c685abac87ba609fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e229cd1e867af419193a32fefaf271df
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Fantasy.ConfigTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示是一个配置文件
|
||||
/// </summary>
|
||||
public interface IConfigTable { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba91b698a7df846c185a3d9e384f71b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Fantasy.ConfigTable
|
||||
{
|
||||
public interface IConfigTableAssetBundle
|
||||
{
|
||||
/// <summary>
|
||||
/// 不同的资源管理器有各自独特的包加载方式。
|
||||
/// 为了满足不同的需求,我们提供了这个接口,允许用户自定义拼装包路径。
|
||||
/// 通过这个接口,用户可以根据自己的特定格式和要求,灵活地加载包,从而提高资源管理的灵活性和效率。
|
||||
/// </summary>
|
||||
/// <param name="assetBundleDirectoryPath"></param>
|
||||
/// <param name="dataConfig"></param>
|
||||
/// <returns></returns>
|
||||
public string Combine(string assetBundleDirectoryPath, string dataConfig);
|
||||
public byte[] LoadConfigTable(string assetBundlePath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a819f57dfada43d9955a9b402772cf6d
|
||||
timeCreated: 1728549292
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "com.fantasy.configtable",
|
||||
"version": "2024.2.24",
|
||||
"displayName": "Fantasy.ConfigTable",
|
||||
"description": "Fantasy is a cross platform distributed server framework.",
|
||||
"category": "Network Framework",
|
||||
"documentationUrl": "https://www.code-fantasy.com/",
|
||||
"changelogUrl": "https://www.code-fantasy.com/",
|
||||
"licensesUrl": "https://www.code-fantasy.com/",
|
||||
"keywords": [
|
||||
"Fantasy",
|
||||
"Framework",
|
||||
"hotfix",
|
||||
"Server",
|
||||
"Network"
|
||||
],
|
||||
"author": {
|
||||
"name": "Fantasy",
|
||||
"email": "362946@qq.com",
|
||||
"url": "https://www.code-fantasy.com/"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db12b302eec284d61984b0798590173a
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user