TH1/Unity/Assets/Scripts/BTNodeCanvas/AICalculateAction.cs
2025-12-26 19:33:10 +08:00

73 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: 白哉
* @Description:
* @Date: 2025年06月06日 星期五 19:06:16
* @Modify:
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Logic.Action;
using Logic.AI;
using Logic.CrashSight;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
namespace NodeCanvas.Tasks.Actions
{
[Name("评分策略")]
[Category("AI节点")]
[Serializable]
public class AICalculateAction : BaseActionTask
{
public List<CalculateType> CalculateTypes;
protected override string desc
{
get { return string.Format($"评分策略为 {CalculateTypes[0]}"); }
}
protected override void OnExecute()
{
base.OnExecute();
// 直接从Blackboard获取AICalculatorData
var data = blackboard.GetVariable<AICalculatorData>("Data");
if (data?.value == null)
{
EndAction(false);
return;
}
Stopwatch sw = new Stopwatch();
sw.Start();
data.value.MaxAiAction = AIActionScoreCalculator.CalculateAIActionScore(data.value, CalculateTypes, out var str);
sw.Stop();
// 加一个解散的目标点定位
if (data.value.MaxAiAction != null && data.value.MaxAiAction?.ActionLogic?.ActionId?.UnitActionType == UnitActionType.Disband)
{
LogSystem.LogError($"UnitActionType Disband NodeId: {NodeId}, {CalculateTypes[0]}");
}
if (sw.Elapsed.TotalMilliseconds > 40)
{
LogSystem.LogError($"duration out, duration{sw.Elapsed.TotalMilliseconds} ms, " +
$"NodeId: {NodeId}, {CalculateTypes[0]} Action 数量:{data.value.AIActions.Count} " +
$"是否成功: {data.value.MaxAiAction != null} \n " +
$" {str}");
}
if (data.value.MaxAiAction == null)
{
// LogSystem.LogError($"不干活的节点:{NodeId} 类型: {CalculateTypes[0]}");
EndAction(false);
return;
}
EndAction(true);
}
}
}