forked from tier4/AWSIM
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMapManager.cs
151 lines (134 loc) · 4.82 KB
/
MapManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Linq;
namespace AWSIM.Loader
{
/// <summary>
/// Manager for configuring the Ego.
/// </summary>
public class MapManager : MonoBehaviour, IConfigurableManager
{
[Tooltip("Scene names that can't be used and aren't shown in a GUI selector.")]
public List<string> forbiddenSceneNames = new List<string>() { "AWSIMSimulation" };
[HideInInspector]
public string spawnedMapName;
[HideInInspector]
public string loaderSceneName = "LoaderScene";
public MapConfiguration mapConfiguration { private set; get; }
/// <summary>
/// Map configuration.
/// </summary>
public MapConfiguration MapConfiguration => mapConfiguration;
[Tooltip("Map dropdown selector.")]
public Dropdown mapUISelecor;
/// <summary>
/// Log callback.
/// </summary>
public Action<LogLevel, string> Log { get; set; }
private EgosManager _egosManager;
public void Start()
{
if (!forbiddenSceneNames.Contains(SceneManager.GetActiveScene().name))
{
forbiddenSceneNames.Add(SceneManager.GetActiveScene().name);
}
_egosManager = GameObject.FindObjectOfType<EgosManager>();
}
/// <summary>
/// Additively loads a map specified in a configuration.
/// </summary>
public AsyncOperation LoadMap()
{
Log(LogLevel.LOG_INFO, $"Loading scene {mapConfiguration.mapName}");
spawnedMapName = mapConfiguration.mapName;
return SceneManager.LoadSceneAsync(mapConfiguration.mapName, LoadSceneMode.Additive);
}
/// <summary>
/// Set up the UI for map configuration
/// </summary>
public void LoadUI()
{
mapUISelecor.options.Clear();
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i)
{
bool sceneNameValid = true;
var sceneName = SceneUtility.GetScenePathByBuildIndex(i).Split('/').Last().Replace(".unity", "");
foreach (var scene in forbiddenSceneNames)
{
if (scene == sceneName)
{
sceneNameValid = false;
break;
}
}
if (sceneNameValid)
{
mapUISelecor.options.Add(
new Dropdown.OptionData(
sceneName
)
);
}
}
mapUISelecor.value = 0;
mapUISelecor.RefreshShownValue();
mapUISelecor.onValueChanged.AddListener(delegate { UpdateFields(mapUISelecor.options[mapUISelecor.value]); });
}
/// <summary>
/// Load and validate config.
/// </summary>
public bool LoadConfig(AWSIMConfiguration config)
{
this.mapConfiguration = config.mapConfiguration;
// Validate config
if (SceneUtility.GetBuildIndexByScenePath(mapConfiguration.mapName) < 0)
{
Log(LogLevel.LOG_ERROR, $"Map '{mapConfiguration.mapName}' not found.");
return false;
}
foreach (var scene in forbiddenSceneNames)
{
if (scene == mapConfiguration.mapName)
{
Log(LogLevel.LOG_ERROR, $"Scene name '{mapConfiguration.mapName}' is reserved and cannot be used.");
return false;
}
}
return true;
}
// Sin (other part is in EgosManager.cs)
private void UpdateFields(Dropdown.OptionData data)
{
double mapPosX = 0;
double mapPosY = 0;
double mapPosZ = 0;
double mapRotX = 0;
double mapRotY = 0;
double mapRotZ = 0;
switch (data.text)
{
case "Shinjuku" or "ShinjukuNight":
mapPosX = 81380.72;
mapPosY = 49918.78;
mapPosZ = 41.57;
mapRotX = 0;
mapRotY = 0;
mapRotZ = 35;
break;
case "Parking Area":
mapPosX = 81580.52;
mapPosY = 50083.58;
mapPosZ = 41;
mapRotX = 0;
mapRotY = 0;
mapRotZ = 100;
break;
}
_egosManager.UpdateMapDefaultSpawn(mapPosX, mapPosY, mapPosZ, mapRotX, mapRotY, mapRotZ);
}
}
}