|
| 1 | +// Visual Pinball Engine |
| 2 | +// Copyright (C) 2026 freezy and VPE Team |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +using Unity.VisualScripting; |
| 18 | +using UnityEngine; |
| 19 | + |
| 20 | +namespace VisualPinball.Unity.VisualScripting |
| 21 | +{ |
| 22 | + [UnitTitle("Nudge")] |
| 23 | + [UnitSurtitle("Player")] |
| 24 | + [UnitCategory("Pinball")] |
| 25 | + public class NudgeUnit : GleUnit |
| 26 | + { |
| 27 | + [DoNotSerialize] |
| 28 | + [PortLabelHidden] |
| 29 | + public ControlInput InputTrigger; |
| 30 | + |
| 31 | + [DoNotSerialize] |
| 32 | + [PortLabelHidden] |
| 33 | + public ControlOutput OutputTrigger; |
| 34 | + |
| 35 | + [DoNotSerialize] |
| 36 | + [PortLabel("Angle")] |
| 37 | + public ValueInput Angle { get; private set; } |
| 38 | + |
| 39 | + [DoNotSerialize] |
| 40 | + [PortLabel("Force")] |
| 41 | + public ValueInput Force { get; private set; } |
| 42 | + |
| 43 | + protected override void Definition() |
| 44 | + { |
| 45 | + InputTrigger = ControlInput(nameof(InputTrigger), Process); |
| 46 | + OutputTrigger = ControlOutput(nameof(OutputTrigger)); |
| 47 | + Angle = ValueInput(nameof(Angle), 0f); |
| 48 | + Force = ValueInput(nameof(Force), 2f); |
| 49 | + Requirement(Angle, InputTrigger); |
| 50 | + Requirement(Force, InputTrigger); |
| 51 | + Succession(InputTrigger, OutputTrigger); |
| 52 | + } |
| 53 | + |
| 54 | + private ControlOutput Process(Flow flow) |
| 55 | + { |
| 56 | + if (!AssertPlayer(flow)) { |
| 57 | + Debug.LogError("Cannot find Player."); |
| 58 | + return OutputTrigger; |
| 59 | + } |
| 60 | + |
| 61 | + Player.Nudge(flow.GetValue<float>(Angle), flow.GetValue<float>(Force)); |
| 62 | + return OutputTrigger; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments