In rare cases, you may want to create a custom event node specific to your project and where the existing event nodes do not suffice or are otherwise not adequate. As such, you can create a custom event node to handle almost everything you require. Here is an example for the included “Input Button” event node.
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 32 33 34 35 36 37 38 39 40 41 42 43 |
using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; namespace FlowCanvas.Nodes{ [Name("Input Button")] [Category("Events/Input")] [Description("Calls respective outputs when the defined Button is pressed down, held down or released.\nButtons are configured in Unity Input Manager.")] public class InputButtonEvents : EventNode, IUpdatable { [RequiredField] public BBParameter<string> buttonName = "Fire1"; private FlowOutput down; private FlowOutput up; private FlowOutput pressed; public override string name{ get {return string.Format("{0} [{1}]", base.name, buttonName);} } protected override void RegisterPorts(){ down = AddFlowOutput("Down"); pressed = AddFlowOutput("Pressed"); up = AddFlowOutput("Up"); } void IUpdatable.Update(){ var value = buttonName.value; if (Input.GetButtonDown(value)){ down.Call(new Flow()); } if (Input.GetButton(value)){ pressed.Call(new Flow()); } if (Input.GetButtonUp(value)){ up.Call(new Flow()); } } } } |
Do note, that the above node implements the IUpdatable interface. Since the Unity input system does not work based on regular events (UnityEvent or C# Event), we need to check the input in a per-frame basis. In such cases, the IUpdatable interface needs to be implemented along with its single “Update” method of course.
© Paradox Notion 2015-2024. All rights reserved.