StartSceneConfig.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 StartSceneConfigCategory : ProtoObject
  10. {
  11. public static StartSceneConfigCategory Instance;
  12. [ProtoIgnore]
  13. [BsonIgnore]
  14. private Dictionary<int, StartSceneConfig> dict = new Dictionary<int, StartSceneConfig>();
  15. [BsonElement]
  16. [ProtoMember(1)]
  17. private List<StartSceneConfig> list = new List<StartSceneConfig>();
  18. public StartSceneConfigCategory()
  19. {
  20. Instance = this;
  21. }
  22. [ProtoAfterDeserialization]
  23. public void AfterDeserialization()
  24. {
  25. foreach (StartSceneConfig config in list)
  26. {
  27. this.dict.Add(config.Id, config);
  28. }
  29. list.Clear();
  30. this.EndInit();
  31. }
  32. public StartSceneConfig Get(int id)
  33. {
  34. this.dict.TryGetValue(id, out StartSceneConfig item);
  35. if (item == null)
  36. {
  37. throw new Exception($"配置找不到,配置表名: {nameof (StartSceneConfig)},配置id: {id}");
  38. }
  39. return item;
  40. }
  41. public bool Contain(int id)
  42. {
  43. return this.dict.ContainsKey(id);
  44. }
  45. public Dictionary<int, StartSceneConfig> GetAll()
  46. {
  47. return this.dict;
  48. }
  49. public StartSceneConfig GetOne()
  50. {
  51. if (this.dict == null || this.dict.Count <= 0)
  52. {
  53. return null;
  54. }
  55. return this.dict.Values.GetEnumerator().Current;
  56. }
  57. }
  58. [ProtoContract]
  59. public partial class StartSceneConfig: ProtoObject, IConfig
  60. {
  61. [ProtoMember(1, IsRequired = true)]
  62. public int Id { get; set; }
  63. [ProtoMember(2, IsRequired = true)]
  64. public int Process { get; set; }
  65. [ProtoMember(3, IsRequired = true)]
  66. public int Zone { get; set; }
  67. [ProtoMember(4, IsRequired = true)]
  68. public string SceneType { get; set; }
  69. [ProtoMember(5, IsRequired = true)]
  70. public string Name { get; set; }
  71. [ProtoMember(6, IsRequired = true)]
  72. public int OuterPort { get; set; }
  73. [ProtoAfterDeserialization]
  74. public void AfterDeserialization()
  75. {
  76. this.EndInit();
  77. }
  78. }
  79. }