2
0
Fork 0
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.

41 lines
1.4 KiB
C#

using UnityEngine;
using Bolt;
namespace Game
{
[UnitTitle("随机角度")]
[UnitSubtitle("NodeRandVector")]
[UnitCategory("Game-Math")]
public class NodeRandVector : NodeDefault
{
public ValueInput vector { get; private set; }
public ValueInput rot { get; private set; }
public ValueInput forbidRot { get; private set; }
public ValueOutput vectorNew { get; private set; }
protected override void Def()
{
vector = ValueInput<Vector3>("vector");
rot = ValueInput<float>("rot");
forbidRot = ValueInput<float>("forbidRot");
vectorNew = ValueOutput<Vector3>("vectorNew");
}
protected override void Run(Flow flow)
{
var rotHalf = flow.GetValue<float>(rot) * 0.5f;
var forbidRotHalf = flow.GetValue<float>(forbidRot) * 0.5f;
var v = flow.GetValue<Vector3>(vector);
var vNew = v;
if (rotHalf != 0)
{
if (rotHalf <= forbidRotHalf)
{
forbidRotHalf = 0;
}
var rotAdd = GameRandom.Random(forbidRotHalf, rotHalf) * GameRandom.RollSymbol(0.5f);
vNew = Quaternion.AngleAxis(rotAdd, Vector3.up) * v;
}
flow.SetValue(vectorNew, vNew);
}
}
}