You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.8 KiB
C#
158 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using Bolt;
|
|
|
|
namespace Game
|
|
{
|
|
[UnitTitle("空")]
|
|
[UnitSubtitle("NodeEmpty")]
|
|
[UnitCategory("Game-Logic")]
|
|
public class NodeEmpty : NodeDefault
|
|
{ }
|
|
|
|
[UnitTitle("布尔判断")]
|
|
[UnitSubtitle("NodeIf")]
|
|
[UnitCategory("Game-Logic")]
|
|
public class NodeIf : Unit
|
|
{
|
|
public ControlInput input;
|
|
public ControlOutput outputTrue;
|
|
public ControlOutput outputFalse;
|
|
public ValueInput condition;
|
|
protected override void Definition()
|
|
{
|
|
|
|
input = ControlInput("in", Enter);
|
|
outputTrue = ControlOutput("True");
|
|
outputFalse = ControlOutput("False");
|
|
|
|
condition = ValueInput<bool>("condition");
|
|
}
|
|
public ControlOutput Enter(Flow flow)
|
|
{
|
|
if (flow.GetValue<bool>(condition))
|
|
return outputTrue;
|
|
else
|
|
{
|
|
return outputFalse;
|
|
}
|
|
}
|
|
}
|
|
[UnitTitle("随机检测[0-1]")]
|
|
[UnitSubtitle("NodeIf")]
|
|
[UnitCategory("Game-Logic")]
|
|
public class NodeRandomCheck : Unit
|
|
{
|
|
public ControlInput input;
|
|
public ControlOutput outputTrue;
|
|
public ControlOutput outputFalse;
|
|
public ValueInput condition;
|
|
protected override void Definition()
|
|
{
|
|
input = ControlInput("in", Enter);
|
|
outputTrue = ControlOutput("True");
|
|
outputFalse = ControlOutput("False");
|
|
condition = ValueInput<float>("condition", 0);
|
|
}
|
|
public ControlOutput Enter(Flow flow)
|
|
{
|
|
if (GameRandom.Roll(flow.GetValue<float>(condition)))
|
|
{
|
|
return outputTrue;
|
|
}
|
|
else
|
|
{
|
|
return outputFalse;
|
|
}
|
|
}
|
|
}
|
|
[UnitTitle("实体排序")]
|
|
[UnitSubtitle("NodeSort")]
|
|
[UnitCategory("Game-Logic")]
|
|
public class NodeSort : Unit
|
|
{
|
|
public ControlInput input; //初始进入
|
|
public ControlOutput output; //最终退出
|
|
public ControlInput loop; //循环入口
|
|
public ControlOutput comp; //循环出口
|
|
public ValueInput list;
|
|
public ValueInput compResult;
|
|
public ValueOutput result;
|
|
public ValueOutput left;
|
|
public ValueOutput right;
|
|
private List<int> entityList;
|
|
private int tempI;
|
|
private int tempJ;
|
|
protected override void Definition()
|
|
{
|
|
input = ControlInput("in", Enter);
|
|
output = ControlOutput("out");
|
|
loop = ControlInput("loop", Loop);
|
|
comp = ControlOutput("comp");
|
|
list = ValueInput<List<int>>("list");
|
|
compResult = ValueInput<int>("compResult");
|
|
result = ValueOutput<List<int>>("result");
|
|
left = ValueOutput<int>("left");
|
|
right = ValueOutput<int>("right");
|
|
}
|
|
public ControlOutput Enter(Flow flow)
|
|
{
|
|
entityList = flow.GetValue<List<int>>(list);
|
|
tempI = 0;
|
|
tempJ = 0;
|
|
return comp;
|
|
}
|
|
public ControlOutput Loop(Flow flow)
|
|
{
|
|
tempJ++;
|
|
if (tempJ >= entityList.Count)
|
|
{
|
|
tempI++;
|
|
if (tempI >= entityList.Count)
|
|
{
|
|
flow.SetValue(result, entityList);
|
|
return output;
|
|
}
|
|
tempJ = tempI;
|
|
return comp;
|
|
}
|
|
var compValue = flow.GetValue<int>(compResult);
|
|
if (compValue > 0)
|
|
{
|
|
Swap();
|
|
}
|
|
flow.SetValue(left, entityList[tempI]);
|
|
flow.SetValue(right, entityList[tempJ]);
|
|
return comp;
|
|
}
|
|
public void Swap()
|
|
{
|
|
var temp = entityList[tempI];
|
|
entityList[tempI] = entityList[tempJ];
|
|
entityList[tempJ] = temp;
|
|
}
|
|
}
|
|
[UnitTitle("列表内容交换")]
|
|
[UnitSubtitle("NodeSwap")]
|
|
[UnitCategory("Game-Logic")]
|
|
public class NodeSwap : NodeDefault
|
|
{
|
|
public ValueInput list;
|
|
public ValueInput indexI;
|
|
public ValueInput indexJ;
|
|
protected override void Def()
|
|
{
|
|
list = ValueInput<List<int>>("list");
|
|
indexI = ValueInput<int>("indexI");
|
|
indexJ = ValueInput<int>("indexJ");
|
|
}
|
|
protected override void Run(Flow flow)
|
|
{
|
|
var l = flow.GetValue<List<int>>(list);
|
|
var i = flow.GetValue<int>(indexI);
|
|
var j = flow.GetValue<int>(indexJ);
|
|
var temp = l[i];
|
|
l[i] = l[j];
|
|
l[j] = temp;
|
|
}
|
|
}
|
|
} |