summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs
blob: ba71fa0d85312f3431b226053d27a74999daec29 (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
using System.Linq;
using UnityEngine;

namespace XNode.Examples.LogicToy {
	[NodeWidth(140), NodeTint(70,70,100)]
	public class ToggleNode : LogicNode {
		[Input, HideInInspector] public bool input;
		[Output, HideInInspector] public bool output;
		public override bool led { get { return output; } }

		protected override void OnInputChanged() {
			bool newInput = GetPort("input").GetInputValues<bool>().Any(x => x);

			if (!input && newInput) {
				input = newInput;
				output = !output;
				SendSignal(GetPort("output"));
			} else if (input && !newInput) {
				input = newInput;
			}
		}

		public override object GetValue(NodePort port) {
			return output;
		}
	}
}