78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using UnityEngine;
|
||
|
||
namespace CapabilitySystem.Examples
|
||
{
|
||
/// <summary>
|
||
/// 展示如何使用 TemporalLogger 记录调试数据
|
||
/// </summary>
|
||
[TickOrder(TickGroup.Gameplay, 0)]
|
||
public class DebugCapabilityExample : Capability
|
||
{
|
||
private float chargeAmount = 0f;
|
||
private int hitCount = 0;
|
||
|
||
protected override void Setup()
|
||
{
|
||
// TemporalLogger 会自动记录激活/停用和位置
|
||
// 这里展示如何记录自定义数据
|
||
}
|
||
|
||
protected override bool ShouldActivate()
|
||
{
|
||
return Input.GetKeyDown(KeyCode.E);
|
||
}
|
||
|
||
protected override void OnActivated()
|
||
{
|
||
chargeAmount = 0f;
|
||
hitCount = 0;
|
||
|
||
// 记录自定义数据
|
||
TemporalLogger?.Log($"{Owner.name}.ChargeAmount", chargeAmount);
|
||
TemporalLogger?.Log($"{Owner.name}.HitCount", hitCount);
|
||
}
|
||
|
||
protected override void TickActive(float deltaTime)
|
||
{
|
||
// 模拟蓄力
|
||
chargeAmount += deltaTime;
|
||
|
||
// 每帧记录蓄力值
|
||
TemporalLogger?.Log($"{Owner.name}.ChargeAmount", chargeAmount);
|
||
|
||
// 记录颜色变化(可视化)
|
||
Color chargeColor = Color.Lerp(Color.white, Color.red, chargeAmount / 3f);
|
||
TemporalLogger?.Log($"{Owner.name}.ChargeColor", chargeColor);
|
||
|
||
// 模拟攻击
|
||
if (Input.GetKeyDown(KeyCode.Space))
|
||
{
|
||
hitCount++;
|
||
TemporalLogger?.Log($"{Owner.name}.HitCount", hitCount);
|
||
TemporalLogger?.Log($"{Owner.name}.LastHitTime", Time.time);
|
||
}
|
||
|
||
// 记录动画状态(如果有 Animator)
|
||
var animator = GetComponent<Animator>();
|
||
if (animator != null)
|
||
{
|
||
TemporalLogger?.LogAnimation($"{Owner.name}.Anim", animator, "Charge");
|
||
}
|
||
}
|
||
|
||
protected override bool ShouldDeactivate()
|
||
{
|
||
return chargeAmount >= 3f || Input.GetKeyUp(KeyCode.E);
|
||
}
|
||
|
||
protected override void OnDeactivated()
|
||
{
|
||
Debug.Log($"[DebugCapability] 蓄力完成: {chargeAmount:F2}s, 攻击次数: {hitCount}");
|
||
|
||
// 记录最终状态
|
||
TemporalLogger?.Log($"{Owner.name}.FinalCharge", chargeAmount);
|
||
TemporalLogger?.Log($"{Owner.name}.FinalHitCount", hitCount);
|
||
}
|
||
}
|
||
}
|