Skip to content

Commit 2f1f7df

Browse files
firefighters tutorial: added UI button to reposition the bucket brigade lines
1 parent 4a66021 commit 2f1f7df

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

EntitiesSamples/Assets/Tutorials/Firefighters/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ This step adds behiour to the bots, who are organized into teams. Each team form
2222

2323
# Step 4: Animation and UI
2424

25-
This step replaces the bot capsules with animated characters. A UI HUD element displays the total count of fires that have been doused.
25+
This step replaces the bot capsules with animated characters. A UI HUD element displays the total count of fires that have been doused. Clicking a HUD button triggers repositioning of the bucket brigade lines.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
2-
<ui:Label tabindex="-1" text="Number of fires doused: 0" parse-escape-sequences="true" display-tooltip-when-elided="true" name="DouseCounter" style="font-size: 28px; color: rgb(255, 255, 255);" />
2+
<ui:Label tabindex="-1" text="Number of fires doused: 0" parse-escape-sequences="true" display-tooltip-when-elided="true" name="DouseCounter" style="font-size: 28px; color: rgb(0, 0, 0);" />
3+
<ui:Button text="Reposition the bucket brigade lines" parse-escape-sequences="true" display-tooltip-when-elided="true" name="RepositionButton" style="font-size: 28px; -unity-text-align: middle-left; width: 30%;" />
34
</ui:UXML>

EntitiesSamples/Assets/Tutorials/Firefighters/Step 4/UIController.cs

+19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
using UnityEditor.Compilation;
12
using UnityEngine;
23
using UnityEngine.UIElements;
34

45
public class UIController : MonoBehaviour
56
{
67
private Label dousedLabel;
8+
private Button repositionButton;
9+
10+
private bool reposition = false;
711

812
private void OnEnable()
913
{
1014
var root = GetComponent<UIDocument>().rootVisualElement;
1115
dousedLabel = root.Q<Label>();
16+
repositionButton = root.Q<Button>();
17+
18+
repositionButton.clicked += OnRepositionButton;
19+
}
20+
21+
private void OnRepositionButton()
22+
{
23+
reposition = true;
24+
}
25+
26+
public bool ShouldReposition()
27+
{
28+
var temp = reposition;
29+
reposition = false;
30+
return temp;
1231
}
1332

1433
public void SetNumFiresDoused(int numFiresDoused)

EntitiesSamples/Assets/Tutorials/Firefighters/Step 4/UISystem.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tutorials.Firefighters
66
{
7+
[UpdateBefore(typeof(LineSystem))]
78
public partial struct UISystem : ISystem
89
{
910
private bool initialized;
@@ -29,10 +30,19 @@ public void OnUpdate(ref SystemState state)
2930
configManaged.UIController = GameObject.FindObjectOfType<UIController>();
3031
}
3132

33+
var shouldReposition = configManaged.UIController.ShouldReposition();
3234
var totalFiresDoused = 0;
33-
foreach (var team in SystemAPI.Query<RefRO<Team>>())
35+
36+
foreach (var (team, entity) in
37+
SystemAPI.Query<RefRO<Team>>()
38+
.WithEntityAccess())
3439
{
3540
totalFiresDoused += team.ValueRO.NumFiresDoused;
41+
42+
if (shouldReposition)
43+
{
44+
SystemAPI.SetComponentEnabled<RepositionLine>(entity, true);
45+
}
3646
}
3747

3848
configManaged.UIController.SetNumFiresDoused(totalFiresDoused);

0 commit comments

Comments
 (0)