ToggleNode.cs 676 B

123456789101112131415161718192021222324252627
  1. using System.Linq;
  2. using UnityEngine;
  3. namespace XNode.Examples.LogicToy {
  4. [NodeWidth(140), NodeTint(70,70,100)]
  5. public class ToggleNode : LogicNode {
  6. [Input, HideInInspector] public bool input;
  7. [Output, HideInInspector] public bool output;
  8. public override bool led { get { return output; } }
  9. protected override void OnInputChanged() {
  10. bool newInput = GetPort("input").GetInputValues<bool>().Any(x => x);
  11. if (!input && newInput) {
  12. input = newInput;
  13. output = !output;
  14. SendSignal(GetPort("output"));
  15. } else if (input && !newInput) {
  16. input = newInput;
  17. }
  18. }
  19. public override object GetValue(NodePort port) {
  20. return output;
  21. }
  22. }
  23. }