mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
78 lines
2.1 KiB
Plaintext
78 lines
2.1 KiB
Plaintext
using System;
|
|
using ProtoBuf;
|
|
using TEngine.Core;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
// ReSharper disable CollectionNeverUpdated.Global
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
|
#pragma warning disable CS0169
|
|
#pragma warning disable CS8618
|
|
#pragma warning disable CS8625
|
|
#pragma warning disable CS8603
|
|
|
|
namespace (namespace)
|
|
{
|
|
[ProtoContract]
|
|
public sealed partial class (ConfigName)Data : AProto, IConfigTable, IDisposable
|
|
{
|
|
[ProtoMember(1)]
|
|
public List<(ConfigName)> List { get; set; } = new List<(ConfigName)>();
|
|
[ProtoIgnore]
|
|
private readonly Dictionary<uint, (ConfigName)> _configs = new Dictionary<uint, (ConfigName)>();
|
|
private static (ConfigName)Data _instance;
|
|
|
|
public static (ConfigName)Data Instance
|
|
{
|
|
get { return _instance ??= ConfigTableManage.Load<(ConfigName)Data>(); }
|
|
private set => _instance = value;
|
|
}
|
|
|
|
public (ConfigName) Get(uint id, bool check = true)
|
|
{
|
|
if (_configs.ContainsKey(id))
|
|
{
|
|
return _configs[id];
|
|
}
|
|
|
|
if (check)
|
|
{
|
|
throw new Exception($"(ConfigName) not find {id} Id");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
public bool TryGet(uint id, out (ConfigName) config)
|
|
{
|
|
config = null;
|
|
|
|
if (!_configs.ContainsKey(id))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
config = _configs[id];
|
|
return true;
|
|
}
|
|
public override void AfterDeserialization()
|
|
{
|
|
for (var i = 0; i < List.Count; i++)
|
|
{
|
|
(ConfigName) config = List[i];
|
|
_configs.Add(config.Id, config);
|
|
config.AfterDeserialization();
|
|
}
|
|
|
|
base.AfterDeserialization();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Instance = null;
|
|
}
|
|
}
|
|
|
|
[ProtoContract]
|
|
public sealed partial class (ConfigName) : AProto
|
|
{(Fields)
|
|
}
|
|
} |