/// <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}");
            }
        }
예제 #2
0
 /// <summary>
 /// Event handler when a new vehicle spawns
 /// </summary>
 /// <param name="vehicle"></param>
 private void OnVehicleSpawn(TrafficManager.Vehicle vehicle)
 {
     if (SelectedTeam != null)
     {
         if (vehicle.NeighbourhoodModel.Team != SelectedTeam)
         {
             SetMaterials(vehicle.VehicleGameObject, true);
         }
     }
 }