Skip to content

Commit 50f07a3

Browse files
committed
Add building selection and HUD details display
Introduced building selection in InputController and added a BuildingHUDController to show building details in the UI. Added BoxCollider components to building prefabs for selection. Updated GameHUD.uxml and BuildingHUDController to display building name and health. Refactored GameHUDController to initialize UIDocument and root VisualElement in OnEnable.
1 parent a9c05f8 commit 50f07a3

File tree

10 files changed

+149
-35
lines changed

10 files changed

+149
-35
lines changed

Red Strike/Assets/BuildingPlacement/Buildings/Building.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ private void OnCollisionEnter(Collision collision)
3030
// Burada hasar hesaplaması yapılabilir.
3131
}
3232
}
33+
34+
public (string, float) GetBuildingStatus()
35+
{
36+
return (gameObject.name, health);
37+
}
3338
}
3439

3540
public enum PlayerType

Red Strike/Assets/BuildingPlacement/Buildings/EnergyTower/EnergyTower.prefab

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ GameObject:
1313
- component: {fileID: 7568800842816226781}
1414
- component: {fileID: 3418134255132300912}
1515
- component: {fileID: -4322946230525120543}
16+
- component: {fileID: 5647536224997323072}
1617
m_Layer: 6
1718
m_Name: EnergyTower
1819
m_TagString: Build
@@ -130,6 +131,27 @@ MonoBehaviour:
130131
buildEffects:
131132
- {fileID: 2273246402830813632}
132133
- {fileID: 9072490561556554335}
134+
--- !u!65 &5647536224997323072
135+
BoxCollider:
136+
m_ObjectHideFlags: 0
137+
m_CorrespondingSourceObject: {fileID: 0}
138+
m_PrefabInstance: {fileID: 0}
139+
m_PrefabAsset: {fileID: 0}
140+
m_GameObject: {fileID: 4083171081778293073}
141+
m_Material: {fileID: 0}
142+
m_IncludeLayers:
143+
serializedVersion: 2
144+
m_Bits: 0
145+
m_ExcludeLayers:
146+
serializedVersion: 2
147+
m_Bits: 0
148+
m_LayerOverridePriority: 0
149+
m_IsTrigger: 0
150+
m_ProvidesContacts: 0
151+
m_Enabled: 1
152+
serializedVersion: 3
153+
m_Size: {x: 4.9999995, y: 6.974897, z: 4.9999995}
154+
m_Center: {x: 0, y: 3.4874485, z: 0}
133155
--- !u!1001 &1993968208826293375
134156
PrefabInstance:
135157
m_ObjectHideFlags: 0

Red Strike/Assets/BuildingPlacement/Buildings/Hangar/Hangar.prefab

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ GameObject:
100100
- component: {fileID: 6352186733635222202}
101101
- component: {fileID: 5575137657921929340}
102102
- component: {fileID: 5840819227562748720}
103+
- component: {fileID: 7209396890379076767}
103104
m_Layer: 6
104105
m_Name: Hangar
105106
m_TagString: Build
@@ -220,6 +221,27 @@ MonoBehaviour:
220221
buildEffects:
221222
- {fileID: 1855726554393846403}
222223
- {fileID: 4273443631821389091}
224+
--- !u!65 &7209396890379076767
225+
BoxCollider:
226+
m_ObjectHideFlags: 0
227+
m_CorrespondingSourceObject: {fileID: 0}
228+
m_PrefabInstance: {fileID: 0}
229+
m_PrefabAsset: {fileID: 0}
230+
m_GameObject: {fileID: 2490931318532185407}
231+
m_Material: {fileID: 0}
232+
m_IncludeLayers:
233+
serializedVersion: 2
234+
m_Bits: 0
235+
m_ExcludeLayers:
236+
serializedVersion: 2
237+
m_Bits: 0
238+
m_LayerOverridePriority: 0
239+
m_IsTrigger: 0
240+
m_ProvidesContacts: 0
241+
m_Enabled: 1
242+
serializedVersion: 3
243+
m_Size: {x: 10.000004, y: 10.84212, z: 15.000002}
244+
m_Center: {x: 0, y: 5.421059, z: 0}
223245
--- !u!1 &4485302380233545425
224246
GameObject:
225247
m_ObjectHideFlags: 0

Red Strike/Assets/BuildingPlacement/Buildings/MainStation/MainStation.prefab

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ GameObject:
1313
- component: {fileID: 3935020676131032200}
1414
- component: {fileID: 5269824642355325504}
1515
- component: {fileID: 9197393951426874775}
16+
- component: {fileID: 8693801915148640960}
1617
m_Layer: 6
1718
m_Name: MainStation
1819
m_TagString: Build
@@ -132,6 +133,27 @@ Animator:
132133
m_AllowConstantClipSamplingOptimization: 1
133134
m_KeepAnimatorStateOnDisable: 0
134135
m_WriteDefaultValuesOnDisable: 0
136+
--- !u!65 &8693801915148640960
137+
BoxCollider:
138+
m_ObjectHideFlags: 0
139+
m_CorrespondingSourceObject: {fileID: 0}
140+
m_PrefabInstance: {fileID: 0}
141+
m_PrefabAsset: {fileID: 0}
142+
m_GameObject: {fileID: 8096343076459658438}
143+
m_Material: {fileID: 0}
144+
m_IncludeLayers:
145+
serializedVersion: 2
146+
m_Bits: 0
147+
m_ExcludeLayers:
148+
serializedVersion: 2
149+
m_Bits: 0
150+
m_LayerOverridePriority: 0
151+
m_IsTrigger: 0
152+
m_ProvidesContacts: 0
153+
m_Enabled: 1
154+
serializedVersion: 3
155+
m_Size: {x: 10, y: 7.0085044, z: 10}
156+
m_Center: {x: 0, y: 3.5042522, z: 0}
135157
--- !u!1 &8342596905262714567
136158
GameObject:
137159
m_ObjectHideFlags: 0

Red Strike/Assets/InputController/InputController.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using UnityEngine;
3-
using UnityEngine.UI;
4-
using VehicleSystem;
3+
using VehicleSystem.Vehicles;
54
using BuildingPlacement;
65
using UISystem;
76
using System.Linq;
@@ -19,6 +18,7 @@ public class InputController : MonoBehaviour
1918
private List<GameObject> placedObjects = new List<GameObject>();
2019
public float minDistanceBetweenObjects = 5f;
2120
public VehiclesHUDController vehiclesHUDController;
21+
public BuildingHUDController buildingHUDController;
2222

2323
private void Start()
2424
{
@@ -107,23 +107,32 @@ private void SelectObject()
107107
switch (hitInfo.collider.tag)
108108
{
109109
case "Build":
110-
Debug.Log("Bina seçildi: " + hitInfo.collider.name);
110+
BuildingPlacement.Buildings.Building building = hitInfo.collider.GetComponent<BuildingPlacement.Buildings.Building>();
111+
buildingHUDController.ShowBuildingDetails(building);
112+
vehiclesHUDController.HideVehicleDetails();
111113
break;
112114
case "Vehicle":
113-
VehicleSystem.Vehicles.Vehicle clickedVehicle = hitInfo.collider.GetComponent<VehicleSystem.Vehicles.Vehicle>();
115+
Vehicle clickedVehicle = hitInfo.collider.GetComponent<Vehicle>();
114116
vehiclesHUDController.ShowVehicleDetails(clickedVehicle);
117+
buildingHUDController.HideBuildingDetails();
115118
break;
116119
default:
117-
vehiclesHUDController.HideVehicleDetails();
120+
DeselectAll();
118121
break;
119122
}
120123
}
121124
else
122125
{
123-
vehiclesHUDController.HideVehicleDetails();
126+
DeselectAll();
124127
}
125128
}
126129

130+
private void DeselectAll()
131+
{
132+
vehiclesHUDController.HideVehicleDetails();
133+
buildingHUDController.HideBuildingDetails();
134+
}
135+
127136
private bool IsPositionValid(Vector3 position)
128137
{
129138
foreach (GameObject placedObject in placedObjects)

Red Strike/Assets/Scenes/SampleScene.unity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ MonoBehaviour:
870870
buildingsDatabase: {fileID: 11400000, guid: 93b080ce34c08df468e7afea3e6569c6, type: 2}
871871
minDistanceBetweenObjects: 25
872872
vehiclesHUDController: {fileID: 422005013}
873+
buildingHUDController: {fileID: 422005014}
873874
--- !u!1 &1702380761
874875
GameObject:
875876
m_ObjectHideFlags: 0

Red Strike/Assets/UISystem/BuildingHUDController.cs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using ExitGames.Client.Photon.StructWrapping;
12
using UnityEngine;
23
using UnityEngine.UIElements;
4+
using BuildingPlacement.Buildings;
35

46
namespace UISystem
57
{
@@ -9,17 +11,22 @@ public class BuildingHUDController : GameHUDController
911
private Button hangarButton;
1012
private Button energyTowerButton;
1113

14+
15+
#region Main Station Details
16+
private VisualElement mainStationDetailsPanel;
17+
private Label mainStationNameLabel;
18+
private Label mainStationHealthLabel;
19+
20+
private Building currentlySelectedBuilding;
21+
#endregion
22+
1223
protected override void OnEnable()
1324
{
1425
base.OnEnable();
1526

16-
uiDocument = GetComponent<UIDocument>();
17-
if (uiDocument == null)
18-
{
19-
Debug.LogError("Bu objede UIDocument bileşeni bulunamadı!", this);
20-
return;
21-
}
22-
var root = uiDocument.rootVisualElement;
27+
mainStationDetailsPanel = root.Q<VisualElement>("main-station-details-panel");
28+
mainStationNameLabel = mainStationDetailsPanel.Q<Label>("build-type-label");
29+
mainStationHealthLabel = mainStationDetailsPanel.Q<Label>("building-health-label");
2330

2431
mainStationButton = root.Q<Button>("main-station-button");
2532
hangarButton = root.Q<Button>("hangar-button");
@@ -28,6 +35,8 @@ protected override void OnEnable()
2835
mainStationButton.clicked += OnMainStationClicked;
2936
hangarButton.clicked += OnHangarClicked;
3037
energyTowerButton.clicked += OnEnergyTowerClicked;
38+
39+
HideBuildingDetails();
3140
}
3241

3342
protected override void OnDisable()
@@ -39,6 +48,37 @@ protected override void OnDisable()
3948
energyTowerButton.clicked -= OnEnergyTowerClicked;
4049
}
4150

51+
protected override void Update()
52+
{
53+
base.Update();
54+
55+
if (currentlySelectedBuilding != null)
56+
{
57+
RefreshVehicleDetails();
58+
}
59+
}
60+
61+
private void RefreshVehicleDetails()
62+
{
63+
var status = currentlySelectedBuilding.GetBuildingStatus();
64+
string buildingName = status.Item1;
65+
string health = status.Item2.ToString("F1");
66+
mainStationNameLabel.text = buildingName;
67+
mainStationHealthLabel.text = "Health: " + health;
68+
}
69+
70+
public void HideBuildingDetails()
71+
{
72+
currentlySelectedBuilding = null;
73+
mainStationDetailsPanel.style.display = DisplayStyle.None;
74+
}
75+
76+
public void ShowBuildingDetails(Building buildingToShow)
77+
{
78+
currentlySelectedBuilding = buildingToShow;
79+
mainStationDetailsPanel.style.display = DisplayStyle.Flex;
80+
}
81+
4282
private void OnBuildingButtonClicked(string buildingName)
4383
{
4484
if (inputController != null)

Red Strike/Assets/UISystem/GameHUD.uxml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@
1616
</ui:VisualElement>
1717
<ui:VisualElement name="main-station-details-panel" class="info-panel" visible="false" >
1818
<ui:Label text="Build Type:" name="build-type-label" class="details-title" />
19-
<ui:Label text="Health:" name="health-label" class="details-text" />
20-
</ui:VisualElement>
21-
<ui:VisualElement name="hangar-details-panel" class="info-panel" visible="false" >
22-
<ui:Label text="Build Type:" name="build-type-label" class="details-title" />
23-
<ui:Label text="Health:" name="health-label" class="details-text" />
24-
<ui:Label text="IsReady:" name="is-ready-label" class="details-text" />
25-
<ui:Label text="Being Produced:" name="being-produced-label" class="details-text" />
26-
</ui:VisualElement>
27-
<ui:VisualElement name="energy-tower-details-panel" class="info-panel" visible="false" >
28-
<ui:Label text="Build Type:" name="build-type-label" class="details-title" />
29-
<ui:Label text="Health:" name="health-label" class="details-text" />
30-
<ui:Label text="Occupancy:" name="occupancy-label" class="details-text" />
31-
<ui:Label text="Density:" name="density-label" class="details-text" />
19+
<ui:Label text="Health:" name="building-health-label" class="details-text" />
3220
</ui:VisualElement>
21+
3322
</ui:VisualElement>
3423
</ui:UXML>

Red Strike/Assets/UISystem/GameHUDController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ public class GameHUDController : MonoBehaviour
77
{
88
public InputController.InputController inputController;
99
protected UIDocument uiDocument;
10+
protected VisualElement root;
1011

11-
protected virtual void OnEnable() { /* Boş bırakıldı, alt sınıflar tarafından geçersiz kılınabilir */ }
12+
protected virtual void OnEnable()
13+
{
14+
uiDocument = GetComponent<UIDocument>();
15+
if (uiDocument == null)
16+
{
17+
Debug.LogError("Bu objede UIDocument bileşeni bulunamadı!", this);
18+
return;
19+
}
20+
root = uiDocument.rootVisualElement;
21+
}
1222

1323
protected virtual void OnDisable() { /* Boş bırakıldı, alt sınıflar tarafından geçersiz kılınabilir */ }
1424

Red Strike/Assets/UISystem/VehiclesHUDController.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ protected override void OnEnable()
1919
{
2020
base.OnEnable();
2121

22-
uiDocument = GetComponent<UIDocument>();
23-
if (uiDocument == null)
24-
{
25-
Debug.LogError("Bu objede UIDocument bileşeni bulunamadı!", this);
26-
return;
27-
}
28-
var root = uiDocument.rootVisualElement;
29-
3022
detailsPanel = root.Q<VisualElement>("details-panel");
3123

3224
vehicleNameLabel = root.Q<Label>("vehicle-name-label");
3325
fuelLabel = root.Q<Label>("fuel-label");
3426
ammoLabel = root.Q<Label>("ammo-label");
3527
targetLabel = root.Q<Label>("target-label");
28+
29+
HideVehicleDetails();
3630
}
3731

3832
protected override void Update()

0 commit comments

Comments
 (0)