Skip to content

Commit

Permalink
fix: traffic manager reference (#143)
Browse files Browse the repository at this point in the history
Signed-off-by: Alptuğ Cırıt <[email protected]>
  • Loading branch information
mozhoku authored Sep 18, 2024
1 parent ac4ff08 commit a094171
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
44 changes: 35 additions & 9 deletions Assets/AWSIM/Scripts/UI/TrafficControlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,48 @@ public void TrafficManagerReset()

public void TrafficManagerUpdate()
{
if (!TrafficManager.gameObject.activeSelf)
if (!TrafficManager)
{
Debug.LogWarning("TrafficManager is not active. Can't update traffic density!");
Debug.LogWarning("Traffic Manager does not exist!");
}
else
{
TrafficManager.enabled = true;
TrafficPlayToggleEvent.Invoke(TrafficManager.enabled);
if (!TrafficManager.gameObject.activeSelf)
{
Debug.LogWarning("TrafficManager is not active. Can't update traffic density!");
}
else
{
TrafficManager.enabled = true;
TrafficPlayToggleEvent.Invoke(TrafficManager.enabled);

TrafficManager.targetVehicleCount = TargetVehicleCount;
TrafficManager.seed = SeedInput;
TrafficManager.RestartTraffic();
}
}
}

TrafficManager.targetVehicleCount = TargetVehicleCount;
TrafficManager.seed = SeedInput;
TrafficManager.RestartTraffic();
public int GetMaxVehicleCount()
{
if (!TrafficManager)
{
Debug.LogWarning("Traffic Manager does not exist!");
return -999;
}

return TrafficManager.maxVehicleCount;
}

public int GetMaxVehicleCount() => TrafficManager.maxVehicleCount;
public int GetTargetVehicleCount() => TrafficManager.targetVehicleCount;
public int GetTargetVehicleCount()
{
if (!TrafficManager)
{
Debug.LogWarning("Traffic Manager does not exist!");
return -998;
}

return TrafficManager.targetVehicleCount;
}
}
}
12 changes: 7 additions & 5 deletions Assets/AWSIM/Scripts/UI/UITrafficVehicleDensity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ public void TrafficManagerSetTargetVehicleCount()
var targetValue = Convert.ToInt32(_trafficTargetVehicleCountSlider.value);
_trafficControlManager.TargetVehicleCount = targetValue;
_textField.text = targetValue.ToString();

_trafficControlManager.TrafficManagerUpdate();
}
private void InitializeSlider()
{
_trafficTargetVehicleCountSlider.maxValue = _trafficControlManager.GetMaxVehicleCount();
_trafficTargetVehicleCountSlider.value = _trafficControlManager.GetTargetVehicleCount();
_textField.text = _trafficTargetVehicleCountSlider.value.ToString(CultureInfo.InvariantCulture);
_textField.Rebuild(CanvasUpdate.PostLayout);
if (_trafficControlManager)
{
_trafficTargetVehicleCountSlider.maxValue = _trafficControlManager.GetMaxVehicleCount();
_trafficTargetVehicleCountSlider.value = _trafficControlManager.GetTargetVehicleCount();
_textField.text = _trafficTargetVehicleCountSlider.value.ToString(CultureInfo.InvariantCulture);
_textField.Rebuild(CanvasUpdate.PostLayout);
}
}
}
}

0 comments on commit a094171

Please sign in to comment.