StartSceneConfig.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using MongoDB.Bson.Serialization.Options;
  5. using System.ComponentModel;
  6. namespace ET
  7. {
  8. [Config]
  9. public partial class StartSceneConfigCategory : Singleton<StartSceneConfigCategory>, IMerge
  10. {
  11. [BsonElement]
  12. [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
  13. private Dictionary<int, StartSceneConfig> dict = new();
  14. public void Merge(object o)
  15. {
  16. StartSceneConfigCategory s = o as StartSceneConfigCategory;
  17. foreach (var kv in s.dict)
  18. {
  19. this.dict.Add(kv.Key, kv.Value);
  20. }
  21. }
  22. public StartSceneConfig Get(int id)
  23. {
  24. this.dict.TryGetValue(id, out StartSceneConfig item);
  25. if (item == null)
  26. {
  27. throw new Exception($"配置找不到,配置表名: {nameof (StartSceneConfig)},配置id: {id}");
  28. }
  29. return item;
  30. }
  31. public bool Contain(int id)
  32. {
  33. return this.dict.ContainsKey(id);
  34. }
  35. public Dictionary<int, StartSceneConfig> GetAll()
  36. {
  37. return this.dict;
  38. }
  39. public StartSceneConfig GetOne()
  40. {
  41. if (this.dict == null || this.dict.Count <= 0)
  42. {
  43. return null;
  44. }
  45. return this.dict.Values.GetEnumerator().Current;
  46. }
  47. }
  48. public partial class StartSceneConfig: ProtoObject, IConfig
  49. {
  50. /// <summary>Id</summary>
  51. public int Id { get; set; }
  52. /// <summary>所属进程</summary>
  53. public int Process { get; set; }
  54. /// <summary>所属区</summary>
  55. public int Zone { get; set; }
  56. /// <summary>类型</summary>
  57. public string SceneType { get; set; }
  58. /// <summary>名字</summary>
  59. public string Name { get; set; }
  60. /// <summary>外网端口</summary>
  61. public int Port { get; set; }
  62. }
  63. }