com.alicizax.unity.tuyoogam.../Editor/AssetBundleDebugger/RemotePlayerSession.cs

94 lines
2.2 KiB
C#
Raw Permalink Normal View History

2025-01-09 11:31:04 +08:00
using System;
using System.Collections.Generic;
2025-04-01 21:12:28 +08:00
using System.Linq;
2025-01-09 11:31:04 +08:00
using UnityEngine;
namespace YooAsset.Editor
{
internal class RemotePlayerSession
{
2025-04-01 21:12:28 +08:00
private readonly Queue<DebugReport> _reports = new Queue<DebugReport>();
2025-01-09 11:31:04 +08:00
/// <summary>
/// 用户ID
/// </summary>
public int PlayerId { private set; get; }
/// <summary>
/// 保存的报告最大数量
/// </summary>
public int MaxReportCount { private set; get; }
public int MinRangeValue
{
get
{
return 0;
}
}
public int MaxRangeValue
{
get
{
2025-04-01 21:12:28 +08:00
int index = _reports.Count - 1;
2025-01-09 11:31:04 +08:00
if (index < 0)
index = 0;
return index;
}
}
2025-04-01 21:12:28 +08:00
public RemotePlayerSession(int playerId, int maxReportCount = 500)
2025-01-09 11:31:04 +08:00
{
PlayerId = playerId;
MaxReportCount = maxReportCount;
}
/// <summary>
/// 清理缓存数据
/// </summary>
public void ClearDebugReport()
{
2025-04-01 21:12:28 +08:00
_reports.Clear();
2025-01-09 11:31:04 +08:00
}
/// <summary>
/// 添加一个调试报告
/// </summary>
public void AddDebugReport(DebugReport report)
{
if (report == null)
Debug.LogWarning("Invalid debug report data !");
2025-04-01 21:12:28 +08:00
if (_reports.Count >= MaxReportCount)
_reports.Dequeue();
_reports.Enqueue(report);
2025-01-09 11:31:04 +08:00
}
/// <summary>
/// 获取调试报告
/// </summary>
public DebugReport GetDebugReport(int rangeIndex)
{
2025-04-01 21:12:28 +08:00
if (_reports.Count == 0)
2025-01-09 11:31:04 +08:00
return null;
2025-04-01 21:12:28 +08:00
if (rangeIndex < 0 || rangeIndex >= _reports.Count)
2025-01-09 11:31:04 +08:00
return null;
2025-04-01 21:12:28 +08:00
return _reports.ElementAt(rangeIndex);
2025-01-09 11:31:04 +08:00
}
/// <summary>
/// 规范索引值
/// </summary>
public int ClampRangeIndex(int rangeIndex)
{
if (rangeIndex < 0)
return 0;
if (rangeIndex > MaxRangeValue)
return MaxRangeValue;
return rangeIndex;
}
}
}