using UnityEngine; namespace Unity.VisualScripting { /// /// Returns the root at the nth degree of a radicand. /// [UnitCategory("Math/Scalar")] [UnitTitle("Root")] [UnitOrder(106)] public sealed class ScalarRoot : Unit { /// /// The radicand. /// [DoNotSerialize] [PortLabel("x")] public ValueInput radicand { get; private set; } /// /// The degree. /// [DoNotSerialize] [PortLabel("n")] public ValueInput degree { get; private set; } /// /// The nth degree root of the radicand. /// [DoNotSerialize] [PortLabel("\u207f\u221ax")] public ValueOutput root { get; private set; } protected override void Definition() { radicand = ValueInput(nameof(radicand), 1); degree = ValueInput(nameof(degree), 2); root = ValueOutput(nameof(root), Root); Requirement(radicand, root); Requirement(degree, root); } public float Root(Flow flow) { var degree = flow.GetValue(this.degree); var radicand = flow.GetValue(this.radicand); if (degree == 2) { return Mathf.Sqrt(radicand); } else { return Mathf.Pow(radicand, 1 / degree); } } } }