Skip to content

Commit df642ca

Browse files
committed
Refactor unit selection and add unitType to units
Introduces a unitType property to units and updates prefabs and scene objects to use it. Refactors InputController selection logic to use unitType and teamId for friendly/enemy checks. Removes PlayerType.cs and moves enums into Unit.cs for better encapsulation.
1 parent a21c7e6 commit df642ca

File tree

8 files changed

+86
-70
lines changed

8 files changed

+86
-70
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,18 @@ MonoBehaviour:
126126
m_Script: {fileID: 11500000, guid: 1a6eab0dde3f71446a801665164dc283, type: 3}
127127
m_Name:
128128
m_EditorClassIdentifier:
129+
teamId: 0
129130
playerType: 0
131+
unitType: 1
130132
buildingData: {fileID: -4322946230525120543}
131133
buildEffects:
132134
- {fileID: 2273246402830813632}
133135
- {fileID: 9072490561556554335}
136+
maxCapacity: 500
137+
currentCapacity: 0
138+
maxDensity: 3
139+
rechargeRate: 10
140+
isActive: 1
134141
--- !u!65 &5647536224997323072
135142
BoxCollider:
136143
m_ObjectHideFlags: 0

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ MonoBehaviour:
216216
m_Script: {fileID: 11500000, guid: d1b395b496c5ad441bf15c92bfc1c719, type: 3}
217217
m_Name:
218218
m_EditorClassIdentifier:
219+
teamId: 0
219220
playerType: 1
221+
unitType: 1
220222
buildingData: {fileID: 5840819227562748720}
221223
buildEffects:
222224
- {fileID: 1855726554393846403}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ MonoBehaviour:
104104
m_Script: {fileID: 11500000, guid: 43fdd334c99237f47ae7f97bed928889, type: 3}
105105
m_Name:
106106
m_EditorClassIdentifier:
107+
teamId: 0
107108
playerType: 0
109+
unitType: 1
108110
buildingData: {fileID: 5269824642355325504}
109111
buildEffects:
110112
- {fileID: 8204242674232356029}
111113
- {fileID: 4710826401873965783}
112114
radarTransform: {fileID: 7222708778872805534}
113115
radarRotationSpeed: 280
116+
ShieldAmount: 100
114117
--- !u!95 &9197393951426874775
115118
Animator:
116119
serializedVersion: 7

Red Strike/Assets/InputController/InputController.cs

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class InputController : MonoBehaviour
3030

3131
private SelectionHighlighter tempBuildingHighlighter;
3232

33+
public int teamId = 0;
34+
3335
private void Start()
3436
{
3537
mainCamera = Camera.main;
@@ -135,83 +137,90 @@ private void HandleObjectSelection()
135137
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
136138
RaycastHit hitInfo;
137139

138-
if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, selectableLayer))
140+
if (!Physics.Raycast(ray, out hitInfo, Mathf.Infinity, selectableLayer))
139141
{
140-
GameObject hitObject = hitInfo.collider.gameObject;
142+
DeselectAll();
143+
return;
144+
}
141145

142-
if (currentSelectedVehicle != null && hitObject.CompareTag("Enemy"))
143-
{
144-
Debug.Log($"Araç ({currentSelectedVehicle.name}) hedefe ({hitObject.name}) kilitlendi.");
145-
currentSelectedVehicle.SetTargetEnemy(hitObject);
146+
var unit = hitInfo.collider.GetComponent<Unit.Unit>();
147+
if (unit == null)
148+
{
149+
DeselectAll();
150+
return;
151+
}
146152

147-
if (targetHighlighter != null)
148-
targetHighlighter.DisableHighlight();
153+
bool isFriendly = unit.teamId == teamId;
154+
bool isEnemy = unit.teamId != teamId;
149155

150-
targetHighlighter = GetHighlighter(hitObject);
151-
if (targetHighlighter != null)
152-
targetHighlighter.EnableHighlight();
156+
if (isEnemy && currentSelectedVehicle == null)
157+
{
158+
Debug.Log("Düşman hedef seçemezsin çünkü önce bir araç seçmen lazım.");
159+
return;
160+
}
153161

154-
return;
155-
}
162+
if (isEnemy)
163+
{
164+
Debug.Log($"Araç {currentSelectedVehicle.name} hedefe kilitlendi: {unit.name}");
156165

157-
DeselectAll();
166+
currentSelectedVehicle.SetTargetEnemy(unit.gameObject);
158167

159-
switch (hitObject.tag)
160-
{
161-
case "Vehicle":
162-
currentSelectedVehicle = hitObject.GetComponent<Vehicle>();
168+
if (targetHighlighter != null)
169+
targetHighlighter.DisableHighlight();
163170

164-
if (currentSelectedVehicle != null)
165-
{
166-
vehicleHighlighter = GetHighlighter(hitObject);
167-
if (vehicleHighlighter != null)
168-
vehicleHighlighter.EnableHighlight();
169-
170-
if (currentSelectedVehicle.targetObject != null)
171-
{
172-
targetHighlighter = GetHighlighter(currentSelectedVehicle.targetObject);
173-
if (targetHighlighter != null)
174-
targetHighlighter.EnableHighlight();
175-
}
176-
177-
if (vehiclesHUDController != null)
178-
vehiclesHUDController.ShowVehicleDetails(currentSelectedVehicle);
179-
}
180-
break;
181-
182-
case "Build":
183-
tempBuildingHighlighter = GetHighlighter(hitObject);
184-
if (tempBuildingHighlighter != null)
185-
tempBuildingHighlighter.EnableHighlight();
186-
187-
var b = hitObject.GetComponent<BuildingPlacement.Buildings.Building>();
188-
if (b != null) buildingHUDController.ShowBuildingDetails(b);
189-
break;
190-
191-
case "Enemy":
192-
tempBuildingHighlighter = GetHighlighter(hitObject);
193-
if (tempBuildingHighlighter != null)
194-
tempBuildingHighlighter.EnableHighlight();
195-
break;
196-
197-
default:
198-
DeselectAll();
199-
break;
200-
}
171+
targetHighlighter = GetHighlighter(unit.gameObject);
172+
if (targetHighlighter != null)
173+
targetHighlighter.EnableHighlight();
174+
175+
return;
201176
}
202-
else
177+
178+
DeselectAll();
179+
180+
switch (unit.unitType)
203181
{
204-
DeselectAll();
182+
case Unit.UnitType.Vehicle:
183+
currentSelectedVehicle = unit.GetComponent<Vehicle>();
184+
185+
if (currentSelectedVehicle != null)
186+
{
187+
vehicleHighlighter = GetHighlighter(unit.gameObject);
188+
if (vehicleHighlighter != null)
189+
vehicleHighlighter.EnableHighlight();
190+
191+
if (currentSelectedVehicle.targetObject != null)
192+
{
193+
targetHighlighter = GetHighlighter(currentSelectedVehicle.targetObject);
194+
if (targetHighlighter != null)
195+
targetHighlighter.EnableHighlight();
196+
}
197+
198+
vehiclesHUDController?.ShowVehicleDetails(currentSelectedVehicle);
199+
}
200+
break;
201+
202+
case Unit.UnitType.Building:
203+
tempBuildingHighlighter = GetHighlighter(unit.gameObject);
204+
tempBuildingHighlighter?.EnableHighlight();
205+
206+
var building = unit.GetComponent<BuildingPlacement.Buildings.Building>();
207+
if (building != null)
208+
buildingHUDController.ShowBuildingDetails(building);
209+
210+
break;
211+
212+
default:
213+
DeselectAll();
214+
break;
205215
}
206216
}
207217

218+
208219
private void DeselectAll()
209220
{
210-
// 1. UI Kapat
211221
if (vehiclesHUDController != null) vehiclesHUDController.HideVehicleDetails();
212222
if (buildingHUDController != null) buildingHUDController.HideBuildingDetails();
213223

214-
// 2. Outline'ları Kapat
215224
if (vehicleHighlighter != null)
216225
{
217226
vehicleHighlighter.DisableHighlight();
@@ -230,7 +239,6 @@ private void DeselectAll()
230239
tempBuildingHighlighter = null;
231240
}
232241

233-
// 3. Hafızayı Temizle
234242
currentSelectedVehicle = null;
235243
currentSelectedBuilding = null;
236244
}

Red Strike/Assets/Scenes/GameScene.unity

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ MonoBehaviour:
777777
m_EditorClassIdentifier:
778778
teamId: 5
779779
playerType: 0
780+
unitType: 0
780781
--- !u!1 &483664587 stripped
781782
GameObject:
782783
m_CorrespondingSourceObject: {fileID: 224654450759790032, guid: 652e336fe8416d44694bb7c08b2b9f16, type: 3}
@@ -1236,6 +1237,7 @@ MonoBehaviour:
12361237
minDistanceBetweenObjects: 25
12371238
vehiclesHUDController: {fileID: 422005013}
12381239
buildingHUDController: {fileID: 422005014}
1240+
teamId: 0
12391241
--- !u!1 &1702380761
12401242
GameObject:
12411243
m_ObjectHideFlags: 0

Red Strike/Assets/Unit/PlayerType.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

Red Strike/Assets/Unit/PlayerType.cs.meta

Lines changed: 0 additions & 2 deletions
This file was deleted.

Red Strike/Assets/Unit/Unit.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ public class Unit : MonoBehaviour
77
[Header("Unit Info")]
88
public int teamId;
99
public PlayerType playerType;
10+
public UnitType unitType;
1011

1112
public virtual void TakeDamage(float damage)
1213
{
1314
// Implement damage logic here
1415
}
1516
}
17+
18+
public enum PlayerType { Red, Blue }
19+
public enum UnitType { Vehicle, Building }
1620
}

0 commit comments

Comments
 (0)