Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add traffic control ui #17

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

21 changes: 21 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Kirill Evdokimov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/LICENSE.meta

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

52 changes: 52 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Unity-UI-Rounded-Corners

These components and shaders allow you to add rounded corners to UI elements!


---

![](title.gif)

## How to install
### Option 1: Package Manager (Unity 2019.3 and higher)
![](how-to-install.gif)
URL to copypaste:
```
https://github.com/kirevdokimov/Unity-UI-Rounded-Corners.git
```

### Option 2: Package Manager (Manual)
- Open `%projectname%/Packages/manifest.json`
- Add the following to the dependencies section:
```
"com.nobi.roundedcorners": "https://github.com/kirevdokimov/Unity-UI-Rounded-Corners.git"
```

### Option 3: Unity Package
Get `.unitypackage` from [releases](https://github.com/kirevdokimov/Unity-UI-Rounded-Corners/releases)

## How to use
#### Symmetrical roundness
- Add `ImageWithRoundedCorners` component to a GameObject with an `Image`
- Adjust `Radius` property
#### Certain roundness value for each corner
- Add `ImageWithIndependentRoundedCorners` to a GameObject with an `Image`
- Adjust `r` Vector4 property. Each vector component represent radius, clockwise, starting with top-left corner
#### Important thing
If you need to add or change the image at runtime, call `Validate()` and then `Refresh()` to update the materials.


# Features
## Changing roundness separately or all at once
![](separate-roundness.gif)
## Keeps round while resizing
![](gif-01.gif)
## Better quality than sprites
![](image-00.png)
## Supports Unity Mask
![](gif-02.gif)
## Supports Tint
![](gif-04.gif)

# Giving back
If this project has helped you and you'd like to contribute back, you can always [buy me a ☕](https://ko-fi.com/X8X03ULFQ)!
7 changes: 7 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/README.md.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/UiRoundedCorners.meta

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

15 changes: 15 additions & 0 deletions Assets/Unity-UI-Rounded-Corners/UiRoundedCorners/DestroyHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using UnityEngine;

internal static class DestroyHelper {
internal static void Destroy(Object @object) {
#if UNITY_EDITOR
if (Application.isPlaying) {
Object.Destroy(@object);
} else {
Object.DestroyImmediate(@object);
}
#else
Object.Destroy(@object);
#endif
}
}

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/UiRoundedCorners/Editor.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if UNITY_EDITOR

using UnityEditor;
using UnityEngine.UI;

namespace Nobi.UiRoundedCorners.Editor {
[CustomEditor(typeof(ImageWithIndependentRoundedCorners))]
public class ImageWithIndependentRoundedCornersInspector : UnityEditor.Editor {
private ImageWithIndependentRoundedCorners script;

private void OnEnable() {
script = (ImageWithIndependentRoundedCorners)target;
}

public override void OnInspectorGUI() {
base.OnInspectorGUI();

if (!script.TryGetComponent<Image>(out var _)) {
EditorGUILayout.HelpBox("This script requires an Image component on the same gameobject", MessageType.Warning);
}
}
}
}

#endif

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if UNITY_EDITOR

using UnityEditor;
using UnityEngine.UI;

namespace Nobi.UiRoundedCorners.Editor {
[CustomEditor(typeof(ImageWithRoundedCorners))]
public class ImageWithRoundedCornersInspector : UnityEditor.Editor {
private ImageWithRoundedCorners script;

private void OnEnable() {
script = (ImageWithRoundedCorners)target;
}

public override void OnInspectorGUI() {
base.OnInspectorGUI();

if (!script.TryGetComponent<Image>(out var _)) {
EditorGUILayout.HelpBox("This script requires an Image component on the same gameobject", MessageType.Warning);
}
}
}
}

#endif

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

Loading
Loading