Используя метод setMapTypeRoadMap(), я вижу, что начальная сопрограмма «StartCoroutine(UpdateMap());» не останавливается. и из-за этого для типа карты не установлено значение type.roadMap.
Я пробовал все, используя создание переменной и остановку переменной, настроенной с помощью моей сопрограммы, я пытался использовать Threads, но ничего не работает
// Utilized Libraries
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;
using System.Collections;
// Map
// This class represents an interactive map that updates every 5 seconds by taking the location from the server via phone app.
public class Map : MonoBehaviour
{
// Questo è la API di Google per l'utilizzo della API google STATIC Map API.
private string apiKey = "MY API";
public enum resolution { low = 1, high = 2 }; // MAP RESOLUTION
public resolution mapResolution = resolution.high; // HIGH RES.
public enum type { roadmap, satellite, gybrid, terrain }; // TYPES OF MAP OF GOOGLE STATIC MAP API
private type mapType = type.satellite; // INITIAL MAP TYPE
private int mapWidth = 800;
private int mapHeight = 540;
// Definition of latitude and longitude variables.
private float lat = 0;
private float lon = 0;
private int zoom = 18;
//DEFINITION OF URL
private string url = "";
private Rect rect;
// START
void Start()
{
StartCoroutine(UpdateMap());
}
IEnumerator UpdateMap()
{
while (true)
{
string latLast = "";
string lonLast = "";
//Request from the server to take the coordinates.
using (UnityWebRequest webRequest = UnityWebRequest.Get("MY SERVER"))
{
// SEND REQUEST
yield return webRequest.SendWebRequest();
if (webRequest.result != UnityWebRequest.Result.Success)
{ //Errore.
Debug.LogError("Error: " + webRequest.error);
}
else
{
// GET CORDINATES
Coordinates data = JsonUtility.FromJson(webRequest.downloadHandler.text);
// Debug.Log("Coordinate: " + data.coordinates);
//EXTRACT LAT AND LON.
String[] parts = data.coordinates.Split(',');
latLast = parts[0];
lonLast = parts[1];
//Taking map measurements on Unity
//rect = gameObject.GetComponent().rectTransform.rect;
//mapWidth = (int)Math.Round(rect.width);
//mapHeight = (int)Math.Round(rect.height);
//Query
Debug.Log(mapType);
url = "https://maps.googleapis.com/maps/api/staticmap?" +
"center=" + latLast + "," + lonLast +
"&zoom=" + zoom +
"&markers=color:red|" + latLast + "," + lonLast +
"&size=" + mapWidth + "x" + mapHeight +
"&scale=" + (int)resolution.high +
"&maptype=" + mapType +
"&key=" + apiKey;
// Get RAW IMAGE Unity.
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{//Errore
Debug.Log("WWW ERROR: " + www.error);
}
else
{
gameObject.GetComponent().texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
}
}
}
yield return new WaitForSeconds(2); // WAIT OF 5 SEC
}
}
[Serializable]
private class Coordinates
{
public string coordinates;
}
public void setMapTypeRoadMap()
{
StopAllCoroutines();
mapType = type.roadmap;
StartCoroutine(UpdateMap());
}
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... harp-unity
Невозможно остановить сопрограммы даже с помощью StopAllCoroutines(), C# Unity ⇐ C#
Место общения программистов C#
1714349736
Anonymous
Используя метод setMapTypeRoadMap(), я вижу, что начальная сопрограмма «StartCoroutine(UpdateMap());» не останавливается. и из-за этого для типа карты не установлено значение type.roadMap.
Я пробовал все, используя создание переменной и остановку переменной, настроенной с помощью моей сопрограммы, я пытался использовать Threads, но ничего не работает
// Utilized Libraries
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;
using System.Collections;
// Map
// This class represents an interactive map that updates every 5 seconds by taking the location from the server via phone app.
public class Map : MonoBehaviour
{
// Questo è la API di Google per l'utilizzo della API google STATIC Map API.
private string apiKey = "MY API";
public enum resolution { low = 1, high = 2 }; // MAP RESOLUTION
public resolution mapResolution = resolution.high; // HIGH RES.
public enum type { roadmap, satellite, gybrid, terrain }; // TYPES OF MAP OF GOOGLE STATIC MAP API
private type mapType = type.satellite; // INITIAL MAP TYPE
private int mapWidth = 800;
private int mapHeight = 540;
// Definition of latitude and longitude variables.
private float lat = 0;
private float lon = 0;
private int zoom = 18;
//DEFINITION OF URL
private string url = "";
private Rect rect;
// START
void Start()
{
StartCoroutine(UpdateMap());
}
IEnumerator UpdateMap()
{
while (true)
{
string latLast = "";
string lonLast = "";
//Request from the server to take the coordinates.
using (UnityWebRequest webRequest = UnityWebRequest.Get("MY SERVER"))
{
// SEND REQUEST
yield return webRequest.SendWebRequest();
if (webRequest.result != UnityWebRequest.Result.Success)
{ //Errore.
Debug.LogError("Error: " + webRequest.error);
}
else
{
// GET CORDINATES
Coordinates data = JsonUtility.FromJson(webRequest.downloadHandler.text);
// Debug.Log("Coordinate: " + data.coordinates);
//EXTRACT LAT AND LON.
String[] parts = data.coordinates.Split(',');
latLast = parts[0];
lonLast = parts[1];
//Taking map measurements on Unity
//rect = gameObject.GetComponent().rectTransform.rect;
//mapWidth = (int)Math.Round(rect.width);
//mapHeight = (int)Math.Round(rect.height);
//Query
Debug.Log(mapType);
url = "https://maps.googleapis.com/maps/api/staticmap?" +
"center=" + latLast + "," + lonLast +
"&zoom=" + zoom +
"&markers=color:red|" + latLast + "," + lonLast +
"&size=" + mapWidth + "x" + mapHeight +
"&scale=" + (int)resolution.high +
"&maptype=" + mapType +
"&key=" + apiKey;
// Get RAW IMAGE Unity.
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{//Errore
Debug.Log("WWW ERROR: " + www.error);
}
else
{
gameObject.GetComponent().texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
}
}
}
yield return new WaitForSeconds(2); // WAIT OF 5 SEC
}
}
[Serializable]
private class Coordinates
{
public string coordinates;
}
public void setMapTypeRoadMap()
{
StopAllCoroutines();
mapType = type.roadmap;
StartCoroutine(UpdateMap());
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78399994/cant-stop-a-coroutines-even-with-stopallcoroutines-c-sharp-unity[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия