summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs
blob: df34f94fafe60b3eff3faddd030a621f031b2c2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using UnityEngine;

namespace XNode.Examples.LogicToy {
	/// <summary> Base node for the LogicToy system </summary>
	public abstract class LogicNode : Node {
		public Action onStateChange;
		public abstract bool led { get; }

		public void SendSignal(NodePort output) {
			// Loop through port connections
			int connectionCount = output.ConnectionCount;
			for (int i = 0; i < connectionCount; i++) {
				NodePort connectedPort = output.GetConnection(i);

				// Get connected ports logic node
				LogicNode connectedNode = connectedPort.node as LogicNode;

				// Trigger it
				if (connectedNode != null) connectedNode.OnInputChanged();
			}
			if (onStateChange != null) onStateChange();
		}

		protected abstract void OnInputChanged();

		public override void OnCreateConnection(NodePort from, NodePort to) {
			OnInputChanged();
		}
	}
}