using System.Collections.Generic; using Gameplay.Vehicle.Impl; namespace Gameplay.Vehicle { public class VehicleManager { private Dictionary> _troopVehicles = new Dictionary>(); public VehicleManager() { } public void AddVehicle(NormalVehicle vehicle) { var troopId = vehicle.commonData.troopId; if (!_troopVehicles.ContainsKey(troopId)) { _troopVehicles.Add(troopId, new List()); } _troopVehicles[troopId].Add(vehicle); } public void RemoveVehicle(NormalVehicle vehicle) { var troopId = vehicle.commonData.troopId; if (_troopVehicles.ContainsKey(troopId)) { _troopVehicles[troopId].Remove(vehicle); } } public NormalVehicle GetVehicleByTroop(int troopId) { if (_troopVehicles.TryGetValue(troopId, out var vehicle)) { if (vehicle.Count > 0) { return vehicle[0]; } } return null; } } }