A game about forced loneliness, made by TACStudios
1using UnityEngine; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Returns the root at the nth degree of a radicand. 7 /// </summary> 8 [UnitCategory("Math/Scalar")] 9 [UnitTitle("Root")] 10 [UnitOrder(106)] 11 public sealed class ScalarRoot : Unit 12 { 13 /// <summary> 14 /// The radicand. 15 /// </summary> 16 [DoNotSerialize] 17 [PortLabel("x")] 18 public ValueInput radicand { get; private set; } 19 20 /// <summary> 21 /// The degree. 22 /// </summary> 23 [DoNotSerialize] 24 [PortLabel("n")] 25 public ValueInput degree { get; private set; } 26 27 /// <summary> 28 /// The nth degree root of the radicand. 29 /// </summary> 30 [DoNotSerialize] 31 [PortLabel("\u207f\u221ax")] 32 public ValueOutput root { get; private set; } 33 34 protected override void Definition() 35 { 36 radicand = ValueInput<float>(nameof(radicand), 1); 37 degree = ValueInput<float>(nameof(degree), 2); 38 root = ValueOutput(nameof(root), Root); 39 40 Requirement(radicand, root); 41 Requirement(degree, root); 42 } 43 44 public float Root(Flow flow) 45 { 46 var degree = flow.GetValue<float>(this.degree); 47 var radicand = flow.GetValue<float>(this.radicand); 48 49 if (degree == 2) 50 { 51 return Mathf.Sqrt(radicand); 52 } 53 else 54 { 55 return Mathf.Pow(radicand, 1 / degree); 56 } 57 } 58 } 59}