52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using Logic.Action;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using RuntimeData;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Name("Action 随机")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamActionRandom : BaseActionTask
|
|
{
|
|
protected override string desc => $"Action 随机";
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
if (data.value.AIActions.Count == 0)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
// 随机选择一个保留
|
|
int randomIndex = UnityEngine.Random.Range(0, data.value.AIActions.Count);
|
|
var selectedAction = data.value.AIActions[randomIndex];
|
|
data.value.AIActions.Clear();
|
|
data.value.AIActions.Add(selectedAction);
|
|
|
|
EndAction(true);
|
|
}
|
|
}
|
|
} |