导表工具修改
This commit is contained in:
114
Assets/Scripts/Generate/Test/RodConfig.cs
Normal file
114
Assets/Scripts/Generate/Test/RodConfig.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using ProtoBuf;
|
||||
using Fantasy;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
#if FANTASY_NET
|
||||
using Fantasy.ConfigTable;
|
||||
using Fantasy.Serialize;
|
||||
#else
|
||||
using NBC;
|
||||
using NBC.Serialize;
|
||||
#endif
|
||||
// ReSharper disable CollectionNeverUpdated.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
#pragma warning disable CS0169
|
||||
#pragma warning disable CS8618
|
||||
#pragma warning disable CS8625
|
||||
#pragma warning disable CS8603
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
[ProtoContract]
|
||||
public sealed partial class RodConfigData : ASerialize, IConfigTable, IProto
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public List<RodConfig> List { get; set; } = new List<RodConfig>();
|
||||
#if FANTASY_NET
|
||||
[ProtoIgnore]
|
||||
private readonly ConcurrentDictionary<uint, RodConfig> _configs = new ConcurrentDictionary<uint, RodConfig>();
|
||||
#else
|
||||
[ProtoIgnore]
|
||||
private readonly Dictionary<uint, RodConfig> _configs = new Dictionary<uint, RodConfig>();
|
||||
#endif
|
||||
private static RodConfigData _instance = null;
|
||||
|
||||
public static RodConfigData Instance
|
||||
{
|
||||
get { return _instance ??= ConfigTableHelper.Load<RodConfigData>(); }
|
||||
private set => _instance = value;
|
||||
}
|
||||
|
||||
public RodConfig Get(uint id, bool check = true)
|
||||
{
|
||||
if (_configs.ContainsKey(id))
|
||||
{
|
||||
return _configs[id];
|
||||
}
|
||||
|
||||
if (check)
|
||||
{
|
||||
throw new Exception($"RodConfig not find {id} Id");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public bool TryGet(uint id, out RodConfig config)
|
||||
{
|
||||
config = null;
|
||||
|
||||
if (!_configs.ContainsKey(id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
config = _configs[id];
|
||||
return true;
|
||||
}
|
||||
public override void AfterDeserialization()
|
||||
{
|
||||
foreach (var config in List)
|
||||
{
|
||||
#if FANTASY_NET
|
||||
_configs.TryAdd(config.Id, config);
|
||||
#else
|
||||
_configs.Add(config.Id, config);
|
||||
#endif
|
||||
config.AfterDeserialization();
|
||||
}
|
||||
|
||||
EndInit();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public sealed partial class RodConfig : ASerialize, IProto
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public uint Id { get; set; } // Id
|
||||
[ProtoMember(2)]
|
||||
public string Model { get; set; } // 模型
|
||||
[ProtoMember(3)]
|
||||
public uint Type { get; set; } // 类型
|
||||
[ProtoMember(4)]
|
||||
public uint Ring { get; set; } // 导线圈
|
||||
[ProtoMember(5)]
|
||||
public uint Length { get; set; } // 长度(毫米)
|
||||
[ProtoMember(6)]
|
||||
public uint Weight { get; set; } // 重量(克)
|
||||
[ProtoMember(7)]
|
||||
public uint Strength { get; set; } // 强度
|
||||
[ProtoMember(8)]
|
||||
public uint MaxRange { get; set; } // 最大范围
|
||||
[ProtoMember(9)]
|
||||
public uint ConstructionType { get; set; } // 结构类型
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user