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("vector"); rot = ValueInput("rot"); forbidRot = ValueInput("forbidRot"); vectorNew = ValueOutput("vectorNew"); } protected override void Run(Flow flow) { var rotHalf = flow.GetValue(rot) * 0.5f; var forbidRotHalf = flow.GetValue(forbidRot) * 0.5f; var v = flow.GetValue(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); } } }