1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00
xNode/Samples~/LogicToy/Nodes/ToggleNode.cs
Wang Cong 7b480b6242 changed: move folder Examples into Samples~
In Package Manager UI 2.0 (compatible with Unity 2019.1), you can include samples in a package.
    https://forum.unity.com/threads/samples-in-packages-manual-setup.623080/
2019-10-21 11:37:56 +08:00

27 lines
676 B
C#

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;
}
}
}