Skip to content

Commit d49b922

Browse files
committed
Improve path visualization and team checks for vehicles
Added team ownership checks to AirVehicle and GroundVehicle to ensure only the controlling player's team sees path visualizations. Enhanced GroundVehicle path drawing to use NavMesh calculations for clients without state authority. Added a ShowPoints method to PathVisualizer for flexible path rendering. Increased UnitCounts capacity in GameStateManager. Updated material files to adjust _SunDirection values. Removed unused import in InputController.
1 parent 667eaf2 commit d49b922

File tree

9 files changed

+68
-16
lines changed

9 files changed

+68
-16
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ public void CreateVehicle(VehicleTypes vehicleType)
2828
{
2929
var targetVehicleData = vehiclesDatabase.vehicles.FirstOrDefault(v => v.vehicleType == vehicleType);
3030

31-
if (targetVehicleData == null)
32-
{
33-
//Debug.LogError("Araç database'de bulunamadı!");
34-
return;
35-
}
31+
if (targetVehicleData == null) return;
3632

3733
bool limitReached = GameStateManager.Instance.HasReachedLimit(
3834
teamId,
@@ -42,7 +38,6 @@ public void CreateVehicle(VehicleTypes vehicleType)
4238

4339
if (limitReached)
4440
{
45-
//Debug.LogWarning("Araç limitine ulaşıldı!");
4641
NotificationSystem.NotificationSystem.Show(
4742
"Vehicle Creation Error",
4843
"You have reached the limit for creating " + targetVehicleData.vehicleName + ".",

Red Strike/Assets/GameStateSystem/GameStateManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class GameStateManager : NetworkBehaviour
1414
[Networked] public int WinningTeamId { get; set; } = -1;
1515
public int LocalPlayerTeamId = 0;
1616

17-
[Networked, Capacity(32)]
17+
[Networked, Capacity(128)]
1818
private NetworkDictionary<NetworkString<_32>, int> UnitCounts { get; }
1919

2020
private ChangeDetector _changes;

Red Strike/Assets/InputController/InputController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using AmmunitionSystem;
99
using UserSystem;
1010
using GameStateSystem;
11-
using ExitGames.Client.Photon.StructWrapping;
1211

1312
namespace InputController
1413
{

Red Strike/Assets/InputController/PathVisualizer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ private void Update()
4747
}
4848
}
4949

50+
public void ShowPoints(Vector3[] points, PathColor color)
51+
{
52+
if (points == null || points.Length < 2)
53+
{
54+
HidePath();
55+
return;
56+
}
57+
58+
DrawLineInternal(points, color);
59+
}
60+
5061
public void ShowNavMeshPath(PathColor color)
5162
{
5263
if (agent == null || !agent.hasPath)

Red Strike/Assets/PlanetAtmosphereSystem/AtmosphereMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Material:
4747
- _GunesYonu: {r: -0.91, g: 0.4, b: 3.24, a: 0}
4848
- _RenkUzak: {r: 0, g: 0.10166844, b: 2.152374, a: 1}
4949
- _RenkYakin: {r: 0, g: 5.670685, b: 8, a: 1}
50-
- _SunDirection: {r: 0.17163001, g: -0.15202178, b: -0.97336143, a: 0}
50+
- _SunDirection: {r: -0.13354853, g: -0.63915896, b: 0.757391, a: 0}
5151
m_BuildTextureStacks: []
5252
m_AllowLocking: 1
5353
--- !u!114 &1522106816477559216

Red Strike/Assets/PlanetAtmosphereSystem/CloudMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Material:
4343
m_Colors:
4444
- _Color: {r: 0, g: 3.8274493, b: 5.992155, a: 1}
4545
- _GunesYonu: {r: -1, g: 0, b: 0, a: 0}
46-
- _SunDirection: {r: 0.17163001, g: -0.15202178, b: -0.97336143, a: 0}
46+
- _SunDirection: {r: -0.13354853, g: -0.63915896, b: 0.757391, a: 0}
4747
m_BuildTextureStacks: []
4848
m_AllowLocking: 1
4949
--- !u!114 &8499732345945835446

Red Strike/Assets/PlanetAtmosphereSystem/FogMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ Material:
5454
- _QueueControl: 0
5555
- _QueueOffset: 0
5656
m_Colors:
57-
- _SunDirection: {r: 0.17163001, g: -0.15202178, b: -0.97336143, a: 0}
57+
- _SunDirection: {r: -0.13354853, g: -0.63915896, b: 0.757391, a: 0}
5858
m_BuildTextureStacks: []
5959
m_AllowLocking: 1

Red Strike/Assets/VehicleSystem/Vehicles/AirVehicle.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ private void UpdatePathVisuals()
8787
{
8888
if (pathVisualizer == null) return;
8989

90+
bool isMyTeam = false;
91+
if (InputController.InputController.Instance != null)
92+
{
93+
isMyTeam = (InputController.InputController.Instance.teamId == this.teamId);
94+
}
95+
96+
if (!isMyTeam)
97+
{
98+
pathVisualizer.HidePath();
99+
return;
100+
}
101+
90102
if (fuelLevel <= 0 || isRefueling)
91103
{
92104
if (nearestEnergyTower != null)

Red Strike/Assets/VehicleSystem/Vehicles/GroundVehicle.cs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace VehicleSystem.Vehicles
88
public class GroundVehicle : Vehicle
99
{
1010
private NavMeshAgent agent;
11+
private NavMeshPath tempPath;
1112

1213
[Header("Ground Combat Settings")]
1314
public float rocketAttackRange = 40f;
@@ -21,6 +22,8 @@ protected override void Start()
2122
{
2223
base.Start();
2324

25+
tempPath = new NavMeshPath();
26+
2427
agent = GetComponent<NavMeshAgent>();
2528
agent.speed = vehicleData.speed;
2629
agent.stoppingDistance = vehicleData.stoppingDistance;
@@ -57,27 +60,59 @@ private void UpdatePathVisuals()
5760
{
5861
if (pathVisualizer == null) return;
5962

60-
if (fuelLevel <= 0 || isRefueling)
63+
bool isMyTeam = false;
64+
if (InputController.InputController.Instance != null)
65+
{
66+
isMyTeam = (InputController.InputController.Instance.teamId == this.teamId);
67+
}
68+
69+
if (!isMyTeam)
70+
{
71+
pathVisualizer.HidePath();
72+
return;
73+
}
74+
75+
if (IsMovingToPosition)
6176
{
62-
pathVisualizer.ShowNavMeshPath(PathVisualizer.PathColor.Yellow);
77+
DrawPathForClient(TargetMovePosition, PathVisualizer.PathColor.Green);
6378
return;
6479
}
6580

6681
if (targetObject != null)
6782
{
68-
pathVisualizer.ShowNavMeshPath(PathVisualizer.PathColor.Red);
83+
DrawPathForClient(targetObject.transform.position, PathVisualizer.PathColor.Red);
6984
return;
7085
}
7186

72-
if (IsMovingToPosition)
87+
if (fuelLevel <= 0 || isRefueling)
7388
{
74-
pathVisualizer.ShowNavMeshPath(PathVisualizer.PathColor.Green);
89+
if (nearestEnergyTower != null)
90+
DrawPathForClient(nearestEnergyTower.transform.position, PathVisualizer.PathColor.Yellow);
7591
return;
7692
}
7793

7894
pathVisualizer.HidePath();
7995
}
8096

97+
private void DrawPathForClient(Vector3 targetPos, PathVisualizer.PathColor color)
98+
{
99+
if (Object.HasStateAuthority && agent != null && agent.enabled && agent.hasPath)
100+
{
101+
pathVisualizer.ShowNavMeshPath(color);
102+
}
103+
else
104+
{
105+
if (NavMesh.CalculatePath(transform.position, targetPos, NavMesh.AllAreas, tempPath))
106+
{
107+
pathVisualizer.ShowPoints(tempPath.corners, color);
108+
}
109+
else
110+
{
111+
pathVisualizer.ShowDirectLine(transform.position, targetPos, color);
112+
}
113+
}
114+
}
115+
81116
public override void FixedUpdateNetwork()
82117
{
83118
base.FixedUpdateNetwork();

0 commit comments

Comments
 (0)