AIConfig.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using ProtoBuf;
  5. namespace ET
  6. {
  7. [ProtoContract]
  8. [Config]
  9. public partial class AIConfigCategory : ProtoObject
  10. {
  11. public static AIConfigCategory Instance;
  12. [ProtoIgnore]
  13. [BsonIgnore]
  14. private Dictionary<int, AIConfig> dict = new Dictionary<int, AIConfig>();
  15. [BsonElement]
  16. [ProtoMember(1)]
  17. private List<AIConfig> list = new List<AIConfig>();
  18. public AIConfigCategory()
  19. {
  20. Instance = this;
  21. }
  22. public override void EndInit()
  23. {
  24. foreach (AIConfig config in list)
  25. {
  26. config.EndInit();
  27. this.dict.Add(config.Id, config);
  28. }
  29. this.AfterEndInit();
  30. }
  31. public AIConfig Get(int id)
  32. {
  33. this.dict.TryGetValue(id, out AIConfig item);
  34. if (item == null)
  35. {
  36. throw new Exception($"配置找不到,配置表名: {nameof (AIConfig)},配置id: {id}");
  37. }
  38. return item;
  39. }
  40. public bool Contain(int id)
  41. {
  42. return this.dict.ContainsKey(id);
  43. }
  44. public Dictionary<int, AIConfig> GetAll()
  45. {
  46. return this.dict;
  47. }
  48. public AIConfig GetOne()
  49. {
  50. if (this.dict == null || this.dict.Count <= 0)
  51. {
  52. return null;
  53. }
  54. return this.dict.Values.GetEnumerator().Current;
  55. }
  56. }
  57. [ProtoContract]
  58. public partial class AIConfig: ProtoObject, IConfig
  59. {
  60. [ProtoMember(1)]
  61. public int Id { get; set; }
  62. [ProtoMember(2)]
  63. public int AIConfigId { get; set; }
  64. [ProtoMember(3)]
  65. public int Order { get; set; }
  66. [ProtoMember(4)]
  67. public string Name { get; set; }
  68. [ProtoMember(6)]
  69. public int[] NodeParams { get; set; }
  70. }
  71. }