TH1/Unity/Assets/Scripts/BTNodeCanvas/AIGeneratorAction.cs

65 lines
1.7 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 AIGeneratorAction : BaseActionTask
{
public List<CommonActionType> ActionTypes;
protected override string desc
{
get { return string.Format($"构建 {ActionTypes[0]} 行为"); }
}
protected override void OnExecute()
{
base.OnExecute();
// 直接从Blackboard获取AICalculatorData
var data = blackboard.GetVariable<AICalculatorData>("Data");
if (data?.value == null)
{
EndAction(false);
return;
}
data.value.AIActions.Clear();
data.value.MaxAiAction = null;
Stopwatch sw = new Stopwatch();
sw.Start();
foreach (var actionType in ActionTypes) AIActionGenerator.GeneratorActionIds(data.value, actionType);
sw.Stop();
if (sw.Elapsed.TotalMilliseconds > 50)
{
LogSystem.LogInfo($"duration out, duration{sw.Elapsed.TotalMilliseconds} ms, NodeId: {NodeId} {ActionTypes[0]}");
}
if (data.value.AIActions.Count == 0)
{
EndAction(false);
return;
}
EndAction(true);
}
}
}