Skip to content

Commit

Permalink
feat: add traffic control ui
Browse files Browse the repository at this point in the history
Signed-off-by: Alptuğ Cırıt <[email protected]>
  • Loading branch information
mozhoku committed Mar 28, 2024
1 parent f71f6aa commit 656daed
Show file tree
Hide file tree
Showing 39 changed files with 5,777 additions and 846 deletions.
4,460 changes: 3,617 additions & 843 deletions Assets/AWSIM/Scenes/Main/AutowareSimulation.unity

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Configuration
}

private EgoVehiclePositionManager egoVehiclePositionManager;
private TrafficControlManager trafficControlManager;

void Awake()
{
Expand Down Expand Up @@ -77,9 +78,29 @@ void Awake()
timeSourceSelector?.SetType(config.TimeSource);
}

egoVehiclePositionManager = gameObject.AddComponent<EgoVehiclePositionManager>();
egoVehiclePositionManager.EgoTransform = egoTransform;
egoVehiclePositionManager.enabled = true;
// Add EgoVehiclePositionManager
if (!egoTransform)
{
Debug.LogWarning("Missing EgoTransform reference.");
}
else
{
egoVehiclePositionManager = gameObject.AddComponent<EgoVehiclePositionManager>();
egoVehiclePositionManager.EgoTransform = egoTransform;
egoVehiclePositionManager.enabled = true;
}

// Add TrafficControlManager
if (!trafficManager)
{
Debug.LogWarning("Missing TrafficManager reference. ");
}
else
{
trafficControlManager = gameObject.AddComponent<TrafficControlManager>();
trafficControlManager.TrafficManager = trafficManager;
trafficControlManager.enabled = true;
}
}
}
}
57 changes: 57 additions & 0 deletions Assets/AWSIM/Scripts/UI/TrafficControlManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using AWSIM.TrafficSimulation;
using UnityEngine;

namespace AWSIM.Scripts.UI
{
public class TrafficControlManager : MonoBehaviour
{
public TrafficManager TrafficManager { private get; set; }

public void TrafficManagerPauseResumeToggle()
{
if (TrafficManager.gameObject.activeSelf)
{
TrafficManager.enabled = !TrafficManager.enabled;
}
else
Debug.Log("TrafficManager is not active. Can't pause/resume!");
}

public void TrafficManagerEnable()
{
TrafficManager.gameObject.SetActive(true);
TrafficManager.enabled = true;
}

public void TrafficManagerDisable()
{
TrafficManager.gameObject.SetActive(false);
}

public void TrafficManagerReset()
{
if (TrafficManager.gameObject.activeSelf)
{
TrafficManager.enabled = true;
TrafficManager.npcVehicleSimulator.ClearAll();
}
else
{
TrafficManager.gameObject.SetActive(true);
TrafficManager.enabled = true;
TrafficManager.npcVehicleSimulator.ClearAll();
}
}

public void TrafficMangerSetSeed(int seed)
{
if (!TrafficManager.gameObject.activeSelf)
{
Debug.LogWarning("TrafficManager is not active. Can't set seed!");
}

TrafficManager.seed = seed;
}
}
}
11 changes: 11 additions & 0 deletions Assets/AWSIM/Scripts/UI/TrafficControlManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Assets/AWSIM/Scripts/UI/UIBridge.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
using System;
using UnityEngine;
using UnityEngine.UI;

namespace AWSIM.Scripts.UI
{
public class UIBridge : MonoBehaviour
{
private EgoVehiclePositionManager egoVehiclePositionManager;
private TrafficControlManager trafficControlManager;
[SerializeField] InputField trafficSeedInputField;

private void Awake()
{
egoVehiclePositionManager = GetComponent<EgoVehiclePositionManager>();
trafficControlManager = GetComponent<TrafficControlManager>();
}

public void ResetEgoToSpawnPoint()
{
egoVehiclePositionManager.ResetEgoToSpawnPoint();
}

public void TrafficManagerPauseResumeToggle()
{
trafficControlManager.TrafficManagerPauseResumeToggle();
}

public void TrafficManagerEnable()
{
trafficControlManager.TrafficManagerEnable();
}

public void TrafficManagerDisable()
{
trafficControlManager.TrafficManagerDisable();
}

public void TrafficManagerReset()
{
trafficControlManager.TrafficManagerReset();
}

public void TrafficMangerSetSeed()
{
if (!trafficSeedInputField)
{
Debug.LogWarning("TrafficSeedInputField reference is missing. Can't set seed without it!");
return;
}

var seed = Convert.ToInt32(trafficSeedInputField.text);
trafficControlManager.TrafficMangerSetSeed(seed);
}
}
}
8 changes: 8 additions & 0 deletions Assets/Unity-UI-Rounded-Corners.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/Examples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/Examples/Lenna.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 656daed

Please sign in to comment.