Skip to content

Commit a9c05f8

Browse files
committed
Refactor HUD controllers and add Build tag
Moved building button logic from GameHUDController to BuildingHUDController for better separation of concerns. Updated SampleScene to use the new BuildingHUDController and added the 'Build' tag in TagManager.asset.
1 parent 3a7cbfe commit a9c05f8

File tree

4 files changed

+62
-59
lines changed

4 files changed

+62
-59
lines changed

Red Strike/Assets/Scenes/SampleScene.unity

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ GameObject:
422422
- component: {fileID: 422005012}
423423
- component: {fileID: 422005011}
424424
- component: {fileID: 422005013}
425+
- component: {fileID: 422005014}
425426
m_Layer: 5
426427
m_Name: UIDocument
427428
m_TagString: Untagged
@@ -472,7 +473,20 @@ MonoBehaviour:
472473
m_GameObject: {fileID: 422005010}
473474
m_Enabled: 1
474475
m_EditorHideFlags: 0
475-
m_Script: {fileID: 11500000, guid: 1319797b3d6c7554099d236168d17075, type: 3}
476+
m_Script: {fileID: 11500000, guid: b9196fefff361e148875260ff54b24a4, type: 3}
477+
m_Name:
478+
m_EditorClassIdentifier:
479+
inputController: {fileID: 1556403732}
480+
--- !u!114 &422005014
481+
MonoBehaviour:
482+
m_ObjectHideFlags: 0
483+
m_CorrespondingSourceObject: {fileID: 0}
484+
m_PrefabInstance: {fileID: 0}
485+
m_PrefabAsset: {fileID: 0}
486+
m_GameObject: {fileID: 422005010}
487+
m_Enabled: 1
488+
m_EditorHideFlags: 0
489+
m_Script: {fileID: 11500000, guid: 70d5e1bc8a892c841afaa940cb019eb1, type: 3}
476490
m_Name:
477491
m_EditorClassIdentifier:
478492
inputController: {fileID: 1556403732}
@@ -855,7 +869,7 @@ MonoBehaviour:
855869
m_Bits: 64
856870
buildingsDatabase: {fileID: 11400000, guid: 93b080ce34c08df468e7afea3e6569c6, type: 2}
857871
minDistanceBetweenObjects: 25
858-
gameHUDController: {fileID: 422005013}
872+
vehiclesHUDController: {fileID: 422005013}
859873
--- !u!1 &1702380761
860874
GameObject:
861875
m_ObjectHideFlags: 0

Red Strike/Assets/UISystem/BuildingHUDController.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
using UnityEngine;
2+
using UnityEngine.UIElements;
23

34
namespace UISystem
45
{
56
public class BuildingHUDController : GameHUDController
67
{
8+
private Button mainStationButton;
9+
private Button hangarButton;
10+
private Button energyTowerButton;
11+
712
protected override void OnEnable()
813
{
14+
base.OnEnable();
15+
916
uiDocument = GetComponent<UIDocument>();
1017
if (uiDocument == null)
1118
{
@@ -22,5 +29,41 @@ protected override void OnEnable()
2229
hangarButton.clicked += OnHangarClicked;
2330
energyTowerButton.clicked += OnEnergyTowerClicked;
2431
}
32+
33+
protected override void OnDisable()
34+
{
35+
base.OnDisable();
36+
37+
mainStationButton.clicked -= OnMainStationClicked;
38+
hangarButton.clicked -= OnHangarClicked;
39+
energyTowerButton.clicked -= OnEnergyTowerClicked;
40+
}
41+
42+
private void OnBuildingButtonClicked(string buildingName)
43+
{
44+
if (inputController != null)
45+
{
46+
inputController.SelectBuildingToPlace(buildingName);
47+
}
48+
else
49+
{
50+
Debug.LogError("InputController referansı GameHUDController'da atanmamış!");
51+
}
52+
}
53+
54+
private void OnMainStationClicked()
55+
{
56+
OnBuildingButtonClicked("Main Station");
57+
}
58+
59+
private void OnHangarClicked()
60+
{
61+
OnBuildingButtonClicked("Hangar");
62+
}
63+
64+
private void OnEnergyTowerClicked()
65+
{
66+
OnBuildingButtonClicked("Energy Tower");
67+
}
2568
}
2669
}
Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,17 @@
11
using UnityEngine;
22
using UnityEngine.UIElements;
3-
using VehicleSystem.Vehicles;
43

54
namespace UISystem
65
{
76
public class GameHUDController : MonoBehaviour
87
{
98
public InputController.InputController inputController;
10-
11-
private Button mainStationButton;
12-
private Button hangarButton;
13-
private Button energyTowerButton;
14-
159
protected UIDocument uiDocument;
1610

17-
protected virtual void OnEnable()
18-
{
19-
uiDocument = GetComponent<UIDocument>();
20-
if (uiDocument == null)
21-
{
22-
Debug.LogError("Bu objede UIDocument bileşeni bulunamadı!", this);
23-
return;
24-
}
25-
var root = uiDocument.rootVisualElement;
26-
27-
mainStationButton = root.Q<Button>("main-station-button");
28-
hangarButton = root.Q<Button>("hangar-button");
29-
energyTowerButton = root.Q<Button>("energy-tower-button");
30-
31-
mainStationButton.clicked += OnMainStationClicked;
32-
hangarButton.clicked += OnHangarClicked;
33-
energyTowerButton.clicked += OnEnergyTowerClicked;
34-
}
11+
protected virtual void OnEnable() { /* Boş bırakıldı, alt sınıflar tarafından geçersiz kılınabilir */ }
3512

36-
private void OnDisable()
37-
{
38-
mainStationButton.clicked -= OnMainStationClicked;
39-
hangarButton.clicked -= OnHangarClicked;
40-
energyTowerButton.clicked -= OnEnergyTowerClicked;
41-
}
13+
protected virtual void OnDisable() { /* Boş bırakıldı, alt sınıflar tarafından geçersiz kılınabilir */ }
4214

4315
protected virtual void Update() { /* Boş bırakıldı, alt sınıflar tarafından geçersiz kılınabilir */ }
44-
45-
private void OnBuildingButtonClicked(string buildingName)
46-
{
47-
if (inputController != null)
48-
{
49-
inputController.SelectBuildingToPlace(buildingName);
50-
}
51-
else
52-
{
53-
Debug.LogError("InputController referansı GameHUDController'da atanmamış!");
54-
}
55-
}
56-
57-
private void OnMainStationClicked()
58-
{
59-
OnBuildingButtonClicked("Main Station");
60-
}
61-
62-
private void OnHangarClicked()
63-
{
64-
OnBuildingButtonClicked("Hangar");
65-
}
66-
67-
private void OnEnergyTowerClicked()
68-
{
69-
OnBuildingButtonClicked("Energy Tower");
70-
}
7116
}
7217
}

Red Strike/ProjectSettings/TagManager.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ TagManager:
66
tags:
77
- Enemy
88
- Vehicle
9+
- Build
910
layers:
1011
- Default
1112
- TransparentFX

0 commit comments

Comments
 (0)