|
14 | 14 | // You should have received a copy of the GNU General Public License |
15 | 15 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | | -using System.Collections.Generic; |
18 | 17 | using Unity.VisualScripting; |
19 | 18 | using UnityEngine; |
20 | 19 | using VisualPinball.Engine.Math; |
21 | 20 |
|
22 | 21 | namespace VisualPinball.Unity.VisualScripting |
23 | 22 | { |
24 | 23 | [UnitTitle("Set Light Sequence")] |
| 24 | + [UnitSurtitle("Scene")] |
25 | 25 | [UnitCategory("Visual Pinball")] |
26 | | - public class SetLightSequenceUnit : Unit |
| 26 | + public class SetLightSequenceUnit : GleUnit |
27 | 27 | { |
28 | 28 | [DoNotSerialize] |
29 | 29 | [PortLabelHidden] |
30 | | - public ControlInput enter { get; private set; } |
| 30 | + public ControlInput InputTrigger; |
31 | 31 |
|
32 | 32 | [DoNotSerialize] |
33 | 33 | [PortLabelHidden] |
34 | | - public ValueInput gameObjects; |
| 34 | + public ControlOutput OutputTrigger; |
35 | 35 |
|
36 | 36 | [DoNotSerialize] |
37 | | - [PortLabelHidden] |
38 | | - public ValueInput value; |
| 37 | + [PortLabel("Light Group")] |
| 38 | + public ValueInput LightGroup; |
39 | 39 |
|
40 | 40 | [DoNotSerialize] |
41 | | - [PortLabelHidden] |
42 | | - public ValueInput colorChannel; |
| 41 | + [PortLabel("Intensity")] |
| 42 | + public ValueInput Value; |
43 | 43 |
|
44 | 44 | [DoNotSerialize] |
45 | | - public ValueInput step; |
| 45 | + [PortLabel("Color Channel")] |
| 46 | + public ValueInput ColorChannel; |
46 | 47 |
|
47 | 48 | [DoNotSerialize] |
48 | | - [PortLabelHidden] |
49 | | - public ControlOutput exit { get; private set; } |
| 49 | + [PortLabel("Step")] |
| 50 | + public ValueInput Step; |
50 | 51 |
|
51 | | - private Player _player; |
52 | | - private int _currentIndex = 0; |
| 52 | + private int _currentIndex; |
53 | 53 |
|
54 | 54 | protected override void Definition() |
55 | 55 | { |
56 | | - enter = ControlInput(nameof(enter), Process); |
| 56 | + InputTrigger = ControlInput(nameof(InputTrigger), Process); |
| 57 | + OutputTrigger = ControlOutput(nameof(OutputTrigger)); |
57 | 58 |
|
58 | | - gameObjects = ValueInput<List<GameObject>>(nameof(gameObjects)); |
| 59 | + LightGroup = ValueInput<LightGroupComponent>(nameof(LightGroup)); |
59 | 60 |
|
60 | | - value = ValueInput<float>(nameof(value), 0); |
61 | | - colorChannel = ValueInput(nameof(colorChannel), ColorChannel.Alpha); |
62 | | - step = ValueInput<int>(nameof(step), 1); |
| 61 | + Value = ValueInput<float>(nameof(Value), 0); |
| 62 | + ColorChannel = ValueInput(nameof(ColorChannel), Engine.Math.ColorChannel.Alpha); |
| 63 | + Step = ValueInput<int>(nameof(Step), 1); |
63 | 64 |
|
64 | | - exit = ControlOutput(nameof(exit)); |
| 65 | + Requirement(Lights, InputTrigger); |
| 66 | + Requirement(Value, InputTrigger); |
| 67 | + Succession(InputTrigger, OutputTrigger); |
65 | 68 | } |
66 | 69 |
|
67 | 70 | private ControlOutput Process(Flow flow) |
68 | 71 | { |
69 | | - if (_player == null) { |
70 | | - _player = Object.FindObjectOfType<Player>(); |
| 72 | + if (!AssertPlayer(flow)) { |
| 73 | + Debug.LogError("Cannot find player."); |
| 74 | + return OutputTrigger; |
71 | 75 | } |
72 | 76 |
|
73 | | - var valueRaw = flow.GetValue<float>(value); |
74 | | - var colorChannelRaw = flow.GetValue<ColorChannel>(colorChannel); |
75 | | - var stepRaw = flow.GetValue<int>(step); |
76 | | - |
77 | | - var lights = new List<ILampDeviceComponent>(); |
78 | | - |
79 | | - foreach (var go in flow.GetValue<List<GameObject>>(gameObjects)) { |
80 | | - if (go != null) { |
81 | | - foreach (var lamp in go.GetComponentsInChildren<ILampDeviceComponent>()) { |
82 | | - if (lamp is LightGroupComponent lightGroup) { |
83 | | - lights.AddRange(lightGroup.Lights); |
84 | | - } else { |
85 | | - lights.Add(lamp); |
86 | | - } |
87 | | - } |
88 | | - } |
89 | | - } |
| 77 | + var valueRaw = flow.GetValue<float>(Value); |
| 78 | + var colorChannelRaw = flow.GetValue<ColorChannel>(ColorChannel); |
| 79 | + var stepRaw = flow.GetValue<int>(Step); |
| 80 | + var lamps = flow.GetValue<LightGroupComponent>(LightGroup).Lights; |
90 | 81 |
|
91 | | - for (var index = 0; index < lights.Count; index++) { |
92 | | - _player.Lamp(lights[index]).OnLamp( |
| 82 | + for (var index = 0; index < lamps.Count; index++) { |
| 83 | + Player.Lamp(lamps[index]).OnLamp( |
93 | 84 | index >= _currentIndex * stepRaw && index < (_currentIndex + 1) * stepRaw ? valueRaw : 0, |
94 | 85 | colorChannelRaw); |
95 | 86 | } |
96 | 87 |
|
97 | | - if (++_currentIndex >= lights.Count / stepRaw) { |
| 88 | + if (++_currentIndex >= lamps.Count / stepRaw) { |
98 | 89 | _currentIndex = 0; |
99 | 90 | } |
100 | 91 |
|
101 | | - return exit; |
| 92 | + return OutputTrigger; |
102 | 93 | } |
103 | 94 | } |
104 | 95 | } |
0 commit comments