提交示例代码
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed partial class ContainerConfigData
|
||||
{
|
||||
private readonly Dictionary<int, ContainerConfig> _configsByType = new Dictionary<int, ContainerConfig>();
|
||||
|
||||
public override void EndInit()
|
||||
{
|
||||
foreach (var containerConfig in List)
|
||||
{
|
||||
_configsByType.Add(containerConfig.Type, containerConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public ContainerConfig GetConfig(ContainerType containerType)
|
||||
{
|
||||
if (!_configsByType.TryGetValue((int)containerType, out var config))
|
||||
{
|
||||
Log.Error($"containerType {containerType} not found!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public bool TryGetConfig(ContainerType containerType, out ContainerConfig containerConfig)
|
||||
{
|
||||
if (!_configsByType.TryGetValue((int)containerType, out containerConfig))
|
||||
{
|
||||
Log.Error($"containerType {containerType} not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user