File tree Expand file tree Collapse file tree 4 files changed +19
-15
lines changed
Expand file tree Collapse file tree 4 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,12 @@ Material assigned to the Radial Menu control can be used to draw the background
2424``` cs
2525public class RadialMenuUsageExample : Script
2626{
27- public Actor ActorRadialMenu ;
27+ public ControlReference < RadialMenu > ActorRadialMenu ;
2828 private RadialMenu _radialMenu ;
2929
3030 public override void OnStart ()
3131 {
32- _radialMenu = ActorRadialMenu .As < UIControl >(). Control as RadialMenu ;
32+ _radialMenu = ActorRadialMenu .Control ;
3333 _radialMenu .Selected += OnOptionSelected ;
3434 }
3535
Original file line number Diff line number Diff line change @@ -9,13 +9,13 @@ The **Slider** responds to a value changed event from the user to change a value
99Here is a c# example of how to get and use a slider's ` ValueChanged ` event in a script:
1010
1111``` cs
12- public UIControl SliderUIControl ;
12+ public ControlReference < Slider > Slider ;
1313private Slider _slider ;
1414
1515public override void OnStart ()
1616{
17- if (SliderUIControl )
18- _slider = SliderUIControl . Get < Slider >() ;
17+ if (Slider )
18+ _slider = Slider . Control ;
1919 if (_slider != null )
2020 _slider .ValueChanged += OnValueChanged ;
2121}
@@ -28,6 +28,9 @@ private void OnValueChanged()
2828public override void OnDestroy ()
2929{
3030 if (_slider != null )
31+ {
3132 _slider .ValueChanged -= OnValueChanged ;
33+ _slider = null ;
34+ }
3235}
33- ```
36+ ```
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ using FlaxEngine.GUI;
4747public class MainMenu : Script
4848{
4949 [Tooltip (" The menu buttons." )]
50- public List <UIControl > Buttons ;
50+ public List <ControlReference < UIControl > > Buttons ;
5151
5252 public override void OnStart ()
5353 {
@@ -59,7 +59,7 @@ public class MainMenu : Script
5959
6060 foreach (var button in Buttons )
6161 {
62- button .Get < Button >() .ButtonClicked += OnButtonClicked ;
62+ button .Control .ButtonClicked += OnButtonClicked ;
6363 }
6464 }
6565
Original file line number Diff line number Diff line change @@ -46,30 +46,31 @@ namespace Game
4646 public float Health { get ; set ; } = 100 . 0 f ;
4747
4848 [Tooltip (" Reference to the player health progress bar control" )]
49- public UIControl HealthBar { get ; set ; }
49+ public ControlReference < ProgressBar > HealthBar { get ; set ; }
5050
5151 private ProgressBar _healthBar ;
5252
5353 public override void OnStart ()
5454 {
55- if (HealthBar == null || ! HealthBar .Is <ProgressBar >())
55+ // Cache health bar control
56+ _healthBar = HealthBar .Control ;
57+ if (_healthBar == null )
5658 {
57- Debug .LogError (" Missing or invalid health bar control" );
59+ Debug .LogError (" Missing health bar control" );
5860 return ;
5961 }
60-
61- _healthBar = HealthBar .Get <ProgressBar >();
6262 }
6363
6464 public override void OnUpdate ()
6565 {
66+ // Control the health value with keys
6667 if (Input .GetKey (KeyboardKeys .Q ))
6768 Health -= 5 ;
68-
6969 if (Input .GetKey (KeyboardKeys .E ))
7070 Health += 5 ;
71-
7271 Health = Mathf .Clamp (Health , 0 , 100 );
72+
73+ // Update the progress bar
7374 _healthBar .Value = Health ;
7475 }
7576 }
You can’t perform that action at this time.
0 commit comments