RemotePlayerSession.cs 2.2 KB

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