Esempio n. 1
0
        void ShowCityInfo(City city)
        {
            if (city == null)
            {
                return;
            }

            // Update text labels
            cityName.text     = city.name;
            population.text   = city.population.ToString();
            countryName.text  = map.GetCityCountryName(city);
            provinceName.text = map.GetCityProvinceName(city);

            // Reposition UI Panel over the viewport
            Vector3 worldPos = map.Map2DToWorldPosition(map.cursorLocation, 1f);

            canvas.transform.position = worldPos;
            canvas.transform.rotation = map.renderViewport.transform.rotation;
            canvas.SetActive(true);
        }
Esempio n. 2
0
        void ShowCityInfo(City city)
        {
            if (city == null)
            {
                return;
            }

            // Update text labels
            cityName.text     = city.name;
            population.text   = city.population.ToString();
            countryName.text  = map.GetCityCountryName(city);
            provinceName.text = map.GetCityProvinceName(city);

            // Reposition UI Panel next to current cursor location on screen

            // We need the screen coordinates of the current map cursor location. We can simply use Input.mousePosition but we'll obtain it transforming
            // the cursorLocation into screen coordinates in case you need to do this on other locations:
            Vector3 worldPos  = map.transform.TransformPoint(map.cursorLocation);
            Vector2 screenPos = Camera.main.WorldToScreenPoint(worldPos);

            // Now, since our Panel is anchored on left/bottom and screen coordinates have 0,0 on left/bottom as well, we simply pass the screenPos to the anchoredPosition property
            panel.anchoredPosition = screenPos;
        }