/// <summary> /// Function to highlight vehicles when clicked. /// </summary> /// <param name="clickedObject"></param> public void HighlightVehicle(GameObject clickedObject) { InfoPanel.gameObject.SetActive(true); try { string infoText = string.Empty; if (clickedObject.CompareTag("Tank")) { TankNavigator tankNavigator = clickedObject.GetComponent <TankNavigator>(); if (tankNavigator.IsStandby || tankNavigator.Target == null) { infoText = "Tank is in stand-by mode"; } else { NeighbourhoodModel neighbourhoodModel = CityManager.Instance.GameModel.Neighbourhoods .Select(x => x).SingleOrDefault(x => x.VisualizedObjects.Contains(tankNavigator.Target)); string firingEnabled = tankNavigator.IsFiringEnabled ? "yes" : "no"; if (neighbourhoodModel != null) { infoText = $"Target: {neighbourhoodModel.Name}\r\nFiring enabled: {firingEnabled}"; } } } else { TrafficManager.Vehicle v = TrafficManager.Instance.Vehicles.Single(x => x.VehicleGameObject == clickedObject); // Check if vehicle is visible if (clickedObject.GetComponentsInChildren <Renderer>().Any(x => !x.enabled)) { return; } infoText = v.NeighbourhoodModel == null ? "Vehicle driving towards deleted neighbourhood" : $"Vehicle driving towards {v.NeighbourhoodModel.Name}"; } InfoPanel.GetComponentInChildren <TMP_Text>().text = infoText; NavMeshAgent agent = clickedObject.GetComponent <NavMeshAgent>(); if (agent != null) { CameraController.Instance.FollowTarget(clickedObject, agent.speed * 0.1f); } Renderer[] renderComponents = clickedObject.GetComponentsInChildren <Renderer>(); foreach (Renderer renderComponent in renderComponents) { _clickedObjects.Add(renderComponent, renderComponent.material.color); renderComponent.material.color = Color.green; } } catch (Exception e) { Debug.LogError($"[OnObjectClickManager] {e.Message}"); } }
/// <summary> /// City is initialized so now we start spawning our tank and air plane. /// </summary> private void GridInitialized() { // Check if chaos is enabled. Settings are already loaded on grid initialization. if (SettingsManager.Instance.Settings.Chaos.Enabled) { if (SettingsManager.Instance.Settings.Chaos.TankEnabled) { KeyValuePair <Vector3, Quaternion> spawnPoint = GridManager.Instance.VehicleSpawnPoints.PickRandom(); // Initialize Tank _tankGameObject = Instantiate( AssetsManager.Instance.GetPredefinedPrefab(AssetsManager.PrefabType.Tank), spawnPoint.Key, spawnPoint.Value); _tankNavigator = _tankGameObject.AddComponent <TankNavigator>(); CameraManager.Instance.TankCamera = _tankGameObject.GetComponentInChildren <Camera>(); CameraManager.Instance.TankCamera.gameObject.SetActive(false); } else { Destroy(TankUiImage); } if (SettingsManager.Instance.Settings.Chaos.PlaneEnabled) { // Initialize Plane // Plane is determining it's own spawn point _planeGameObject = Instantiate( AssetsManager.Instance.GetPredefinedPrefab(AssetsManager.PrefabType.Plane), new Vector3(0f, 80f, 0f), Quaternion.Euler(0f, 90f, 0f)); _planeNavigator = _planeGameObject.AddComponent <PlaneNavigator>(); CameraManager.Instance.PlaneCamera = _planeGameObject.GetComponentInChildren <Camera>(); CameraManager.Instance.PlaneCamera.gameObject.SetActive(false); } else { Destroy(PlaneUiImage); } _minimumBuildings = SettingsManager.Instance.Settings.Chaos.MinimumBuildings; } else { Destroy(ToggleAttackModeCheckbox); } CityManager.Instance.CityUpdatedEvent.RemoveListener(GridInitialized); }