TH1/Unity/Assets/Scripts/BTNodeCanvas/AIParamRandom.cs
2025-10-27 11:47:59 +08:00

43 lines
989 B
C#

/*
* @Author: 白哉
* @Description:
* @Date: 2025年06月06日 星期五 19:06:16
* @Modify:
*/
using System;
using System.Collections.Generic;
using Logic.AI;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using RuntimeData;
namespace NodeCanvas.Tasks.Actions
{
[Name("随机概率")]
[Category("AI节点")]
[Serializable]
public class AIParamRandom : BaseActionTask
{
public float Ratio = 50f;
protected override string desc => $"随机概率 >= {Ratio}";
protected override void OnExecute()
{
base.OnExecute();
// 直接从Blackboard获取AICalculatorData
var data = blackboard.GetVariable<AICalculatorData>("Data");
if (data?.value == null)
{
EndAction(false);
return;
}
var random = new System.Random();
EndAction(random.NextDouble() * 100f >= Ratio);
}
}
}