PulseNode.cs 792 B

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. namespace XNode.Examples.LogicToy {
  3. [NodeWidth(140), NodeTint(70,100,70)]
  4. public class PulseNode : LogicNode, ITimerTick {
  5. [Space(-18)]
  6. public float interval = 1f;
  7. [Output, HideInInspector] public bool output;
  8. public override bool led { get { return output; } }
  9. private float timer;
  10. public void Tick(float deltaTime) {
  11. timer += deltaTime;
  12. if (!output && timer > interval) {
  13. timer -= interval;
  14. output = true;
  15. SendSignal(GetPort("output"));
  16. } else if (output) {
  17. output = false;
  18. SendSignal(GetPort("output"));
  19. }
  20. }
  21. /// <summary> This node can not receive signals, so this is not used </summary>
  22. protected override void OnInputChanged() { }
  23. public override object GetValue(NodePort port) {
  24. return output;
  25. }
  26. }
  27. }