Skip to content

Commit 50183aa

Browse files
committed
Add networked vehicle spawning and refactor prefabs
Implemented RPC_SpawnVehicle in CommanderData for networked vehicle instantiation. Updated Hangar to use the new RPC for spawning vehicles. Refactored vehicle prefab locations to Resources folder and updated references. Adjusted InputController to support VehiclesDatabase and fixed type usage. Minor prefab and scene adjustments for new references and spawn positions. Updated Vehicle.cs to use Runner.Despawn for networked destruction.
1 parent 93cbb93 commit 50183aa

22 files changed

+43
-25
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using VehicleSystem;
3+
using NetworkingSystem;
34

45
namespace BuildingPlacement.Buildings
56
{
@@ -40,7 +41,7 @@ private void CreateVehicleInstance(VehicleTypes vehicleType)
4041
{
4142
if (item.vehicleType == vehicleType)
4243
{
43-
Instantiate(item.vehiclePrefab, vehicleSpawnPoint, Quaternion.identity);
44+
CommanderData.LocalCommander.RPC_SpawnVehicle(item.vehicleName, vehicleSpawnPoint);
4445
InProductionUnitName = "None";
4546
IsReady = true;
4647
return;

Red Strike/Assets/InputController/InputController.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22
using UnityEngine;
3-
using VehicleSystem.Vehicles;
3+
using VehicleSystem;
44
using BuildingPlacement;
55
using UISystem;
66
using System.Linq;
@@ -16,6 +16,7 @@ public class InputController : MonoBehaviour
1616
[Header("UI & Database")]
1717
public UIDocument gameUIDocument;
1818
public BuildingsDatabase buildingsDatabase;
19+
public VehiclesDatabase vehiclesDatabase;
1920

2021
[Header("Layers & Camera")]
2122
public LayerMask terrainLayer;
@@ -27,12 +28,13 @@ public class InputController : MonoBehaviour
2728
public int teamId = 0;
2829

2930
private Building currentSelectedBuilding;
30-
private Vehicle currentSelectedVehicle;
31+
private VehicleSystem.Vehicles.Vehicle currentSelectedVehicle;
3132

3233
private VehiclesHUDController vehiclesHUDController;
3334
private BuildingHUDController buildingHUDController;
3435

3536
private SelectionHighlighter vehicleHighlighter;
37+
3638
private SelectionHighlighter targetHighlighter;
3739
private SelectionHighlighter tempBuildingHighlighter;
3840

@@ -206,7 +208,7 @@ private void HandleObjectSelection()
206208
switch (unit.unitType)
207209
{
208210
case Unit.UnitType.Vehicle:
209-
currentSelectedVehicle = unit.GetComponent<Vehicle>();
211+
currentSelectedVehicle = unit.GetComponent<VehicleSystem.Vehicles.Vehicle>();
210212
if (currentSelectedVehicle != null)
211213
{
212214
vehicleHighlighter = GetHighlighter(unit.gameObject);

Red Strike/Assets/NetworkingSystem/CommanderData.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using UnityEngine;
22
using Fusion;
33
using System.Linq;
4-
using InputController;
54

65
namespace NetworkingSystem
76
{
@@ -90,5 +89,32 @@ public void RPC_SpawnBuilding(string buildingName, Vector3 position)
9089
Debug.LogError($"Server: {buildingName} prefabı bulunamadı!");
9190
}
9291
}
92+
93+
[Rpc(RpcSources.InputAuthority, RpcTargets.StateAuthority)]
94+
public void RPC_SpawnVehicle(string vehicleName, Vector3 position)
95+
{
96+
Debug.Log($"Server: {Object.InputAuthority} oyuncusu {vehicleName} üretmek istiyor.");
97+
98+
if (InputController.InputController.Instance == null) return;
99+
100+
var database = InputController.InputController.Instance.vehiclesDatabase;
101+
var vehicleData = database.vehicles.FirstOrDefault(v => v.vehicleName == vehicleName);
102+
103+
if (vehicleData != null && vehicleData.vehiclePrefab != null)
104+
{
105+
NetworkObject spawnedObj = Runner.Spawn(vehicleData.vehiclePrefab, position, Quaternion.identity, Object.InputAuthority);
106+
107+
var unitScript = spawnedObj.GetComponent<Unit.Unit>();
108+
if (unitScript != null)
109+
{
110+
unitScript.teamId = PlayerTeamID;
111+
Debug.Log($"Araç üretildi ({vehicleData.vehicleName}). Takım ID: {PlayerTeamID} atandı.");
112+
}
113+
}
114+
else
115+
{
116+
Debug.LogError($"Server: {vehicleData.vehicleName} prefabı bulunamadı!");
117+
}
118+
}
93119
}
94120
}

Red Strike/Assets/Resources/Hangar.prefab

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Transform:
2727
m_GameObject: {fileID: 1825945093530936561}
2828
serializedVersion: 2
2929
m_LocalRotation: {x: 0, y: -0.00000008742281, z: -0, w: 1}
30-
m_LocalPosition: {x: 0, y: 0.36947754, z: 0.03}
30+
m_LocalPosition: {x: 0, y: 0.37, z: 3}
3131
m_LocalScale: {x: 1, y: 1, z: 1}
3232
m_ConstrainProportionsScale: 0
3333
m_Children:
@@ -198,7 +198,6 @@ MonoBehaviour:
198198
m_Name:
199199
m_EditorClassIdentifier:
200200
_teamId: 0
201-
playerType: 1
202201
unitType: 1
203202
buildingData: {fileID: 11400000, guid: a20ea262914989645a27af443d4c8b0b, type: 2}
204203
buildEffects:
@@ -322,13 +321,13 @@ Transform:
322321
m_PrefabAsset: {fileID: 0}
323322
m_GameObject: {fileID: 4485302380233545425}
324323
serializedVersion: 2
325-
m_LocalRotation: {x: 0.61684436, y: 2.475547e-14, z: 2.5341901e-14, w: 0.7870851}
324+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
326325
m_LocalPosition: {x: 0.0000024414062, y: -2.261367, z: 0.22929443}
327326
m_LocalScale: {x: 1, y: 1, z: 1}
328327
m_ConstrainProportionsScale: 0
329328
m_Children: []
330329
m_Father: {fileID: 4523665396325921815}
331-
m_LocalEulerAnglesHint: {x: 76.172, y: 0, z: 0}
330+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
332331
--- !u!33 &6794653063612178352
333332
MeshFilter:
334333
m_ObjectHideFlags: 0
@@ -409,7 +408,7 @@ Transform:
409408
m_GameObject: {fileID: 4548672385823307540}
410409
serializedVersion: 2
411410
m_LocalRotation: {x: -2.0843212e-14, y: 0.00000023841856, z: 0.00000008742278, w: 1}
412-
m_LocalPosition: {x: -0, y: 2.5170312, z: -0.89}
411+
m_LocalPosition: {x: 0, y: 2.5170312, z: 2}
413412
m_LocalScale: {x: 1, y: 1, z: 1}
414413
m_ConstrainProportionsScale: 1
415414
m_Children:
@@ -495,14 +494,14 @@ Transform:
495494
m_PrefabAsset: {fileID: 0}
496495
m_GameObject: {fileID: 5121454307228710264}
497496
serializedVersion: 2
498-
m_LocalRotation: {x: -0.978599, y: -5.329071e-15, z: -7.105428e-15, w: 0.20577654}
497+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
499498
m_LocalPosition: {x: -0, y: 2.173198, z: 1.7164638}
500499
m_LocalScale: {x: 1, y: 1, z: 1}
501500
m_ConstrainProportionsScale: 0
502501
m_Children:
503502
- {fileID: 5330188872981299249}
504503
m_Father: {fileID: 6575102193581802611}
505-
m_LocalEulerAnglesHint: {x: -156.25, y: 0, z: 0}
504+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
506505
--- !u!33 &4146610404216206157
507506
MeshFilter:
508507
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)