|
| 1 | +// Visual Pinball Engine |
| 2 | +// Copyright (C) 2021 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 | + |
| 23 | + [UnitTitle("Create Ball")] |
| 24 | + [UnitCategory("Events\\Visual Pinball")] |
| 25 | + public class CreateBallUnit : GleUnit |
| 26 | + { |
| 27 | + [DoNotSerialize] |
| 28 | + [PortLabelHidden] |
| 29 | + public ControlInput InputTrigger; |
| 30 | + |
| 31 | + [DoNotSerialize] |
| 32 | + [PortLabelHidden] |
| 33 | + public ControlOutput OutputTrigger; |
| 34 | + |
| 35 | + [DoNotSerialize] |
| 36 | + [PortLabel("Position")] |
| 37 | + public ValueInput Position { get; private set; } |
| 38 | + |
| 39 | + [DoNotSerialize] |
| 40 | + [PortLabel("Kick Angle")] |
| 41 | + public ValueInput KickAngle { get; private set; } |
| 42 | + |
| 43 | + [DoNotSerialize] |
| 44 | + [PortLabel("Kick Force")] |
| 45 | + public ValueInput KickForce { get; private set; } |
| 46 | + |
| 47 | + protected override void Definition() |
| 48 | + { |
| 49 | + InputTrigger = ControlInput(nameof(InputTrigger), Process); |
| 50 | + OutputTrigger = ControlOutput(nameof(OutputTrigger)); |
| 51 | + |
| 52 | + Position = ValueInput<Vector3>(nameof(Position), Vector3.zero); |
| 53 | + KickAngle = ValueInput<float>(nameof(KickAngle), 0); |
| 54 | + KickForce = ValueInput<float>(nameof(KickForce), 0); |
| 55 | + |
| 56 | + Requirement(Position, InputTrigger); |
| 57 | + Succession(InputTrigger, OutputTrigger); |
| 58 | + } |
| 59 | + |
| 60 | + private ControlOutput Process(Flow flow) |
| 61 | + { |
| 62 | + if (!AssertGle(flow)) { |
| 63 | + Debug.LogError("Cannot find GLE."); |
| 64 | + return OutputTrigger; |
| 65 | + } |
| 66 | + |
| 67 | + if (Gle is VisualScriptingGamelogicEngine vsGle) { |
| 68 | + var pos = flow.GetValue<Vector3>(Position); |
| 69 | + var kickAngle = flow.GetValue<float>(KickAngle); |
| 70 | + var kickForce = flow.GetValue<float>(KickForce); |
| 71 | + vsGle.BallManager.CreateBall(new DebugBallCreator(pos.x, pos.y, pos.z, kickAngle, kickForce)); |
| 72 | + } |
| 73 | + |
| 74 | + return OutputTrigger; |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments