StartSceneConfig.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public override void EndInit()
  23. {
  24. foreach (StartSceneConfig config in list)
  25. {
  26. config.EndInit();
  27. this.dict.Add(config.Id, config);
  28. }
  29. this.AfterEndInit();
  30. }
  31. public StartSceneConfig Get(int id)
  32. {
  33. this.dict.TryGetValue(id, out StartSceneConfig item);
  34. if (item == null)
  35. {
  36. throw new Exception($"配置找不到,配置表名: {nameof (StartSceneConfig)},配置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, StartSceneConfig> GetAll()
  45. {
  46. return this.dict;
  47. }
  48. public StartSceneConfig 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 StartSceneConfig: ProtoObject, IConfig
  59. {
  60. [ProtoMember(1)]
  61. public int Id { get; set; }
  62. [ProtoMember(2)]
  63. public int Process { get; set; }
  64. [ProtoMember(3)]
  65. public int Zone { get; set; }
  66. [ProtoMember(4)]
  67. public int Index { get; set; }
  68. [ProtoMember(5)]
  69. public string SceneType { get; set; }
  70. [ProtoMember(6)]
  71. public string Name { get; set; }
  72. [ProtoMember(7)]
  73. public int OuterPort { get; set; }
  74. }
  75. }