File tree Expand file tree Collapse file tree 3 files changed +29
-18
lines changed
Expand file tree Collapse file tree 3 files changed +29
-18
lines changed Original file line number Diff line number Diff line change @@ -50,21 +50,19 @@ protected override void Definition()
5050 Requirement ( Id , InputTrigger ) ;
5151 Succession ( InputTrigger , OutputTrigger ) ;
5252 }
53+
5354 private ControlOutput Process ( Flow flow )
5455 {
55- var gle = flow . stack . gameObject . GetComponentInParent < VisualScriptingGamelogicEngine > ( ) ;
56-
57- if ( gle != null ) {
58-
59- var id = flow . GetValue < string > ( Id ) ;
60- var isEnabled = flow . GetValue < bool > ( IsEnabled ) ;
61-
62- gle . SetCoil ( id , isEnabled ) ;
63-
64- } else {
56+ if ( ! AssertGle ( flow ) ) {
6557 Debug . LogError ( "Cannot find GLE." ) ;
58+ return OutputTrigger ;
6659 }
6760
61+ var id = flow . GetValue < string > ( Id ) ;
62+ var isEnabled = flow . GetValue < bool > ( IsEnabled ) ;
63+
64+ Gle . SetCoil ( id , isEnabled ) ;
65+
6866 return OutputTrigger ;
6967 }
7068 }
Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ public abstract class GleUnit : Unit, IGleUnit
2929 {
3030 [ DoNotSerialize ]
3131 public List < string > Errors { get ; } = new ( ) ;
32+
33+ [ DoNotSerialize ]
34+ protected IGamelogicEngine Gle ;
35+
36+ protected bool AssertGle ( Flow flow )
37+ {
38+ if ( Gle != null ) {
39+ return true ;
40+ }
41+ Gle = flow . stack . gameObject . GetComponentInParent < IGamelogicEngine > ( ) ;
42+ return Gle == null ;
43+ }
3244 }
3345
3446 public interface IGleUnit
Original file line number Diff line number Diff line change 1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
1717using Unity . VisualScripting ;
18+ using UnityEngine ;
1819
1920namespace VisualPinball . Unity . VisualScripting
2021{
@@ -46,22 +47,22 @@ protected override void Definition()
4647
4748 private float GetValue ( Flow flow )
4849 {
49- if ( _player == null ) {
50- _player = UnityEngine . Object . FindObjectOfType < Player > ( ) ;
50+ if ( ! AssertGle ( flow ) ) {
51+ Debug . LogError ( "Cannot find GLE." ) ;
52+ return 0 ;
5153 }
5254
53- var key = flow . GetValue < string > ( Id ) ;
54- return _player . LampStatuses . ContainsKey ( key ) ? _player . LampStatuses [ key ] : 0 ;
55+ return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) ;
5556 }
5657
5758 private bool GetEnabled ( Flow flow )
5859 {
59- if ( _player == null ) {
60- _player = flow . stack . self . GetComponentInParent < Player > ( ) ;
60+ if ( ! AssertGle ( flow ) ) {
61+ Debug . LogError ( "Cannot find GLE." ) ;
62+ return false ;
6163 }
6264
63- var key = flow . GetValue < string > ( Id ) ;
64- return _player . LampStatuses . ContainsKey ( key ) && ( _player . LampStatuses [ key ] > 0 ) ;
65+ return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) > 0 ;
6566 }
6667 }
6768}
You can’t perform that action at this time.
0 commit comments