WeatherUnit.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class WeatherUnit : MonoBehaviour
  6. {
  7. public Text nameText;
  8. public Text weatherText;
  9. public Image image;
  10. public GameObject[] weatherSprite;
  11. public GameObject bingObj;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. }
  16. public void Init(double lgtd, double lttd, string na, string we)
  17. {
  18. for (int i = 0; i < weatherSprite.Length; i++) {
  19. weatherSprite[i].gameObject.SetActive(false);
  20. }
  21. Vector3 temp = CoordinateConverter.GeoToUGUISmall(lgtd, lttd);
  22. this.GetComponent<RectTransform>().anchoredPosition3D = temp;
  23. nameText.text = na.Trim();
  24. //digitText.text = di;
  25. switch (we) {
  26. case "9":
  27. weatherText.text = "晴天";
  28. weatherSprite[0].gameObject.SetActive(true);
  29. break;
  30. case "8":
  31. weatherText.text = "阴天";
  32. weatherSprite[1].gameObject.SetActive(true);
  33. break;
  34. case "7":
  35. weatherText.text = "雨天";
  36. weatherSprite[2].gameObject.SetActive(true);
  37. break;
  38. case "6":
  39. weatherText.text = "雨夹雪";
  40. weatherSprite[3].gameObject.SetActive(true);
  41. break;
  42. case "5":
  43. weatherText.text = "雪天";
  44. weatherSprite[4].gameObject.SetActive(true);
  45. break;
  46. }
  47. }
  48. // Update is called once per frame
  49. void Update()
  50. {
  51. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  52. }
  53. }