LogicNode.cs 860 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using UnityEngine;
  3. namespace XNode.Examples.LogicToy {
  4. /// <summary> Base node for the LogicToy system </summary>
  5. public abstract class LogicNode : Node {
  6. public Action onStateChange;
  7. public abstract bool led { get; }
  8. public void SendSignal(NodePort output) {
  9. // Loop through port connections
  10. int connectionCount = output.ConnectionCount;
  11. for (int i = 0; i < connectionCount; i++) {
  12. NodePort connectedPort = output.GetConnection(i);
  13. // Get connected ports logic node
  14. LogicNode connectedNode = connectedPort.node as LogicNode;
  15. // Trigger it
  16. if (connectedNode != null) connectedNode.OnInputChanged();
  17. }
  18. if (onStateChange != null) onStateChange();
  19. }
  20. protected abstract void OnInputChanged();
  21. public override void OnCreateConnection(NodePort from, NodePort to) {
  22. OnInputChanged();
  23. }
  24. }
  25. }