8000
Skip to content
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
10 changes: 5 additions & 5 deletions Assets/Awsim/Scenes/AutowareSimulationDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -266543,11 +266543,11 @@ MonoBehaviour:
_randomTrafficSims:
- _enableSimulation: 1
_trafficSimNpcVehiclePrefabs:
- {fileID: 1252738011092766975, guid: 6d7d303c5e4defa16b508cece3ef599e, type: 3}
- {fileID: 6165415753350049284, guid: a4db0a3241fc6cbcdb523a20abe25ec9, type: 3}
- {fileID: 6632081074653058128, guid: 2aab0ce90015ebadfadf702af88b666e, type: 3}
- {fileID: 7027408765914110385, guid: 467a68bbdca38cddda59c3c6af539d63, type: 3}
- {fileID: 8279803077700154773, guid: cd6e20f712013db92912be3accdca402, type: 3}
- {fileID: 2563257946706820547, guid: 6d7d303c5e4defa16b508cece3ef599e, type: 3}
- {fileID: -2738266875521181682, guid: a4db0a3241fc6cbcdb523a20abe25ec9, type: 3}
- {fileID: 6508327500362848844, guid: cd6e20f712013db92912be3accdca402, type: 3}
- {fileID: 8544599814613540701, guid: 2aab0ce90015ebadfadf702af88b666e, type: 3}
- {fileID: 8478247347008641927, guid: 467a68bbdca38cddda59c3c6af539d63, type: 3}
_spawnableTrafficLanes:
- {fileID: 226374874}
- {fileID: 1362998551}
Expand Down
10 changes: 5 additions & 5 deletions Assets/Awsim/Scenes/AutowareSimulationURPDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -258203,11 +258203,11 @@ MonoBehaviour:
_randomTrafficSims:
- _enableSimulation: 1
_trafficSimNpcVehiclePrefabs:
- {fileID: 1252738011092766975, guid: 5c643d7707cd41f77ac0bff3ef39954c, type: 3}
- {fileID: 6165415753350049284, guid: 7bab18aca6215d54fa8ee68bb595bec3, type: 3}
- {fileID: 6632081074653058128, guid: 9a11b607502a658f1aa503f127d82d2d, type: 3}
- {fileID: 7027408765914110385, guid: 378087bf43313d6119ea339dda5147fb, type: 3}
- {fileID: 8279803077700154773, guid: 8d82c1af41bf717b5885d6a2769f29c6, type: 3}
- {fileID: 2563257946706820547, guid: 5c643d7707cd41f77ac0bff3ef39954c, type: 3}
- {fileID: -2738266875521181682, guid: 7bab18aca6215d54fa8ee68bb595bec3, type: 3}
- {fileID: 6508327500362848844, guid: 8d82c1af41bf717b5885d6a2769f29c6, type: 3}
- {fileID: 8544599814613540701, guid: 9a11b607502a658f1aa503f127d82d2d, type: 3}
- {fileID: 8478247347008641927, guid: 378087bf43313d6119ea339dda5147fb, type: 3}
_spawnableTrafficLanes:
- {fileID: 1218941626}
- {fileID: 1289732061}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public interface ITrafficSimulator
/// <param name="spawnPoint"></param>
/// <param name="spawnedVehicle"></param>
/// <returns>True if spawned, False is failed to spawn.</returns>
public bool Spawn(GameObject prefab, NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle spawnedVehicle);
public bool Spawn(TrafficSimNpcVehicle prefab, NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle spawnedVehicle);

/// <summary>
/// Gets random spawn point and NPC prefab.
/// </summary>
public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out GameObject prefab);
public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle prefab);

/// <summary>
/// Increase the traffic simulator spawn priority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class NpcVehicleSpawner
/// Get random NPC vehicle prefab.
/// </summary>
/// <returns>NPC vehicle prefab</returns>
public GameObject GetRandomPrefab()
public TrafficSimNpcVehicle GetRandomPrefab()
=> _prefabs[Random.Range(0, _prefabs.Length)];

/// <summary>
Expand All @@ -57,7 +57,7 @@ public GameObject GetRandomPrefab()
public NpcVehicleSpawnPoint GetRandomSpawnPoint()
=> _spawnPoints[Random.Range(0, _spawnPoints.Length)];

GameObject[] _prefabs;
TrafficSimNpcVehicle[] _prefabs;
NpcVehicleSpawnPoint[] _spawnPoints;
GameObject _NpcVehicleParentsObj;

Expand All @@ -66,7 +66,7 @@ public NpcVehicleSpawnPoint GetRandomSpawnPoint()
/// </summary>
/// <param name="prefabs">NPC vehicle prefabs to be spawned.</param>
/// <param name="spawnableLanes">Lanes where vehicles can spawn.</param>
public NpcVehicleSpawner(GameObject parentsObj, GameObject[] prefabs, TrafficLane[] spawnableLanes)
public NpcVehicleSpawner(GameObject parentsObj, TrafficSimNpcVehicle[] prefabs, TrafficLane[] spawnableLanes)
{
this._NpcVehicleParentsObj = parentsObj;
this._prefabs = prefabs;
Expand Down Expand Up @@ -123,7 +123,7 @@ public bool TryGetRandomSpawnablePoint(GameObject prefab, out NpcVehicleSpawnPoi
/// <param name="prefab">NPC vehicle prefab</param>
/// <param name="npcVehicleSpawnPoint">Spawn point</param>
/// <returns>Spawned NPC vehicle.</returns>
public TrafficSimNpcVehicle Spawn(GameObject prefab, uint vehicleId, NpcVehicleSpawnPoint npcVehicleSpawnPoint)
public TrafficSimNpcVehicle Spawn(TrafficSimNpcVehicle prefab, uint vehicleId, NpcVehicleSpawnPoint npcVehicleSpawnPoint)
{
var obj = Object.Instantiate(prefab, npcVehicleSpawnPoint.Position, Quaternion.identity);
obj.name = obj.name + "_" + vehicleId.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RandomTrafficSimulatorConfiguration
{
public bool EnableSimulation => _enableSimulation;

public GameObject[] TrafficSimNpcVehiclePrefabs => _trafficSimNpcVehiclePrefabs;
public TrafficSimNpcVehicle[] TrafficSimNpcVehiclePrefabs => _trafficSimNpcVehiclePrefabs;

public TrafficLane[] SpawnableTrafficLanes => _spawnableTrafficLanes;

Expand All @@ -36,7 +36,7 @@ public class RandomTrafficSimulatorConfiguration

[Tooltip("NPCs to be spawned.")]
[SerializeField]
GameObject[] _trafficSimNpcVehiclePrefabs;
TrafficSimNpcVehicle[] _trafficSimNpcVehiclePrefabs;

[Tooltip("TrafficLanes where NPC vehicles can spawn.")]
[SerializeField]
Expand Down Expand Up @@ -71,7 +71,7 @@ public class RandomTrafficSimulator : ITrafficSimulator

private int spawnPriority = 0;

private GameObject nextPrefabToSpawn = null;
private TrafficSimNpcVehicle nextPrefabToSpawn = null;

public void IncreasePriority(int priority)
{
Expand All @@ -95,7 +95,7 @@ public bool IsEnabled()
}

public RandomTrafficSimulator(GameObject parent,
GameObject[]
TrafficSimNpcVehicle[]
prefabs,
TrafficLane[]
spawnableLanes,
Expand All @@ -108,7 +108,7 @@ public RandomTrafficSimulator(GameObject parent,
npcVehicleSpawner = new NpcVehicleSpawner(parent, prefabs, spawnableLanes);
}

public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out GameObject prefab)
public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle prefab)
{
// NPC prefab is randomly chosen and is fixed until it is spawned. This is due to avoid prefab "bound" race conditions
// when smaller cars will always be chosen over larger ones while the spawning process checks if the given prefab can be
Expand All @@ -124,7 +124,7 @@ public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out GameObje
spawnPoint = npcVehicleSpawner.GetRandomSpawnPoint();
}

public bool Spawn(GameObject prefab, NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle spawnedVehicle)
public bool Spawn(TrafficSimNpcVehicle prefab, NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle spawnedVehicle)
{
if (IsMaximumSpawnsNumberReached())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct RouteTrafficSimulatorConfiguration
{
public bool EnableSimulation => _enableSimulation;

public GameObject[] TrafficSimNpcVehiclePrefabs => _trafficSimNpcVehiclePrefabs;
public TrafficSimNpcVehicle[] TrafficSimNpcVehiclePrefabs => _trafficSimNpcVehiclePrefabs;

public TrafficLane[] RouteLanes => _routeLanes;

Expand All @@ -36,7 +36,7 @@ public struct RouteTrafficSimulatorConfiguration
bool _enableSimulation;

[SerializeField]
GameObject[] _trafficSimNpcVehiclePrefabs;
TrafficSimNpcVehicle[] _trafficSimNpcVehiclePrefabs;

[Tooltip("Route to follow. The first element also acts as a spawn lane.")]
[SerializeField]
Expand Down Expand Up @@ -66,7 +66,7 @@ public class RouteTrafficSimulator : ITrafficSimulator
private NpcVehicleSpawner npcVehicleSpawner;
private int currentSpawnNumber = 0;
private int spawnPriority = 0;
private GameObject nextPrefabToSpawn = null;
private TrafficSimNpcVehicle nextPrefabToSpawn = null;

public void IncreasePriority(int priority)
{
Expand All @@ -90,7 +90,7 @@ public bool IsEnabled()
}

public RouteTrafficSimulator(GameObject parent,
GameObject[] npcPrefabs,
TrafficSimNpcVehicle[] npcPrefabs,
TrafficLane[] npcRoute,
NpcVehicleSimulator vehicleSimulator,
int maxSpawns = 0)
Expand All @@ -102,7 +102,7 @@ public RouteTrafficSimulator(GameObject parent,
npcVehicleSpawner = new NpcVehicleSpawner(parent, npcPrefabs, spawnableLane);
}

public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out GameObject prefab)
public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle prefab)
{
// NPC prefab is randomly chosen and is fixed until it is spawned. This is due to avoid prefab "bound" race conditions
// when smaller cars will always be chosen over larger ones while the spawning process checks if the given prefab can be
Expand All @@ -118,7 +118,7 @@ public void GetRandomSpawnInfo(out NpcVehicleSpawnPoint spawnPoint, out GameObje
spawnPoint = npcVehicleSpawner.GetRandomSpawnPoint();
}

public bool Spawn(GameObject prefab, NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle spawnedVehicle)
public bool Spawn(TrafficSimNpcVehicle prefab, NpcVehicleSpawnPoint spawnPoint, out TrafficSimNpcVehicle spawnedVehicle)
{
if (IsMaximumSpawnsNumberReached())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class TrafficSimulator : MonoBehaviour
[SerializeField] RouteTrafficSimulatorConfiguration[] _routeTrafficSims;
[SerializeField] NpcVehicleSimulator _npcVehicleSimulator;
List<ITrafficSimulator> _trafficSimulatorNodes;
Dictionary<NpcVehicleSpawnPoint, Dictionary<ITrafficSimulator, GameObject>> _spawnLanes;
Dictionary<NpcVehicleSpawnPoint, Dictionary<ITrafficSimulator, TrafficSimNpcVehicle>> _spawnLanes;
List<TrafficSimNpcVehicle> _trafficSimNpcVehicleList;

bool _isTrafficIntersectionInitialized = false; // TODO: Consider how to reset the traffic simulator without having flags.
Expand Down Expand Up @@ -97,7 +97,7 @@ public void Initialize()

Random.InitState(_seed);

_spawnLanes = new Dictionary<NpcVehicleSpawnPoint, Dictionary<ITrafficSimulator, GameObject>>();
_spawnLanes = new Dictionary<NpcVehicleSpawnPoint, Dictionary<ITrafficSimulator, TrafficSimNpcVehicle>>();

_npcVehicleSimulator = new NpcVehicleSimulator(_vehicleConfig, _obstacleLayerMask, _groundLayerMask, _maxVehicleCount, _egoVehicle);

Expand Down Expand Up @@ -169,7 +169,7 @@ public void OnFixedUpdate()
}
else
{
var tsims = new Dictionary<ITrafficSimulator, GameObject>();
var tsims = new Dictionary<ITrafficSimulator, TrafficSimNpcVehicle>();
tsims.Add(trafficSimulator, prefab);
_spawnLanes.Add(spawnPoint, tsims);
}
Expand All @@ -192,7 +192,7 @@ public void OnFixedUpdate()
var tsimAndPrefab = spawnLoc.Value.First();
var trafficSim = tsimAndPrefab.Key;
var prefab = tsimAndPrefab.Value;
if (!NpcVehicleSpawner.IsSpawnable(prefab.GetComponent<TrafficSimNpcVehicle>().NpcVehicle.Bounds, spawnLoc.Key))
if (!NpcVehicleSpawner.IsSpawnable(prefab.NpcVehicle.Bounds, spawnLoc.Key))
continue;
var spawned = trafficSim.Spawn(prefab, spawnLoc.Key, out spawnedVehicle);
}
Expand All @@ -201,7 +201,7 @@ public void OnFixedUpdate()
var priorityTrafficSimList = spawnLoc.Value.OrderByDescending(x => x.Key.GetCurrentPriority());
var priorityTrafficSimGo = priorityTrafficSimList.First();
var prefab = priorityTrafficSimGo.Value;
if (!NpcVehicleSpawner.IsSpawnable(prefab.GetComponent<TrafficSimNpcVehicle>().NpcVehicle.Bounds, spawnLoc.Key))
if (!NpcVehicleSpawner.IsSpawnable(prefab.NpcVehicle.Bounds, spawnLoc.Key))
{
continue;
}
Expand Down
0