RemotePlayerSession.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace YooAsset.Editor
  5. {
  6. internal class RemotePlayerSession
  7. {
  8. private readonly List<DebugReport> _reportList = new List<DebugReport>();
  9. /// <summary>
  10. /// 用户ID
  11. /// </summary>
  12. public int PlayerId { private set; get; }
  13. /// <summary>
  14. /// 保存的报告最大数量
  15. /// </summary>
  16. public int MaxReportCount { private set; get; }
  17. public int MinRangeValue
  18. {
  19. get
  20. {
  21. return 0;
  22. }
  23. }
  24. public int MaxRangeValue
  25. {
  26. get
  27. {
  28. int index = _reportList.Count - 1;
  29. if (index < 0)
  30. index = 0;
  31. return index;
  32. }
  33. }
  34. public RemotePlayerSession(int playerId, int maxReportCount = 1000)
  35. {
  36. PlayerId = playerId;
  37. MaxReportCount = maxReportCount;
  38. }
  39. /// <summary>
  40. /// 清理缓存数据
  41. /// </summary>
  42. public void ClearDebugReport()
  43. {
  44. _reportList.Clear();
  45. }
  46. /// <summary>
  47. /// 添加一个调试报告
  48. /// </summary>
  49. public void AddDebugReport(DebugReport report)
  50. {
  51. if (report == null)
  52. Debug.LogWarning("Invalid debug report data !");
  53. if (_reportList.Count >= MaxReportCount)
  54. _reportList.RemoveAt(0);
  55. _reportList.Add(report);
  56. }
  57. /// <summary>
  58. /// 获取调试报告
  59. /// </summary>
  60. public DebugReport GetDebugReport(int rangeIndex)
  61. {
  62. if (_reportList.Count == 0)
  63. return null;
  64. if (rangeIndex < 0 || rangeIndex >= _reportList.Count)
  65. return null;
  66. return _reportList[rangeIndex];
  67. }
  68. /// <summary>
  69. /// 规范索引值
  70. /// </summary>
  71. public int ClampRangeIndex(int rangeIndex)
  72. {
  73. if (rangeIndex < 0)
  74. return 0;
  75. if (rangeIndex > MaxRangeValue)
  76. return MaxRangeValue;
  77. return rangeIndex;
  78. }
  79. }
  80. }