ConfigModel.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using XRTool.Util;
  5. public class ConfigModel : UnitySingleton<ConfigModel>
  6. {
  7. /// <summary>
  8. /// 存储菜单项数据(链表结构)
  9. /// </summary>
  10. CircleList<RoomConfig> _itemLinklist = new CircleList<RoomConfig>();
  11. /// <summary>
  12. /// 获取头节点(第一个数据)
  13. /// </summary>
  14. /// <returns></returns>
  15. public DoubleLinkNode<RoomConfig> GetFirstMenuItem()
  16. {
  17. return _itemLinklist.First;
  18. }
  19. /// <summary>
  20. /// 获取尾节点(最后一个数据)
  21. /// </summary>
  22. /// <returns></returns>
  23. public DoubleLinkNode<RoomConfig> GetLastMenuItem()
  24. {
  25. return _itemLinklist.Last;
  26. }
  27. /// <summary>
  28. /// 添加数据
  29. /// </summary>
  30. public void AddElement(RoomConfig itemConfig)
  31. {
  32. if (itemConfig.Id == "")
  33. {
  34. _itemLinklist.AddNode(itemConfig);
  35. }
  36. else
  37. {
  38. DoubleLinkNode<RoomConfig> _node = _itemLinklist.First;
  39. while (_node.PreNode != _itemLinklist.First)
  40. {
  41. if (_node.Value.Id == "")
  42. {
  43. _node.Value = itemConfig;
  44. break;
  45. }
  46. }
  47. }
  48. }
  49. /// <summary>
  50. /// 读取数据
  51. /// </summary>
  52. /// <param name="itemConfig"></param>
  53. public void InitElement(RoomConfig itemConfig)
  54. {
  55. _itemLinklist.AddNode(itemConfig);
  56. }
  57. /// <summary>
  58. /// 删除指定的节点
  59. /// </summary>
  60. /// <param name="ic"></param>
  61. public void RemoveElement(DoubleLinkNode<RoomConfig> ic)
  62. {
  63. _itemLinklist.RemoveNode(ic);
  64. }
  65. /// <summary>
  66. /// 数据的数量
  67. /// </summary>
  68. /// <returns></returns>
  69. public int Count
  70. {
  71. get
  72. {
  73. return _itemLinklist.Count;
  74. }
  75. }
  76. /// <summary>
  77. /// 清除所有数据
  78. /// </summary>
  79. public void Clear()
  80. {
  81. _itemLinklist.Clear();
  82. }
  83. }