WeatherUnit.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 Sprite[] 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. Vector3 temp = CoordinateConverter.GeoToUGUISmall(lgtd, lttd);
  19. this.GetComponent<RectTransform>().anchoredPosition3D = temp;
  20. nameText.text = na;
  21. //digitText.text = di;
  22. switch (we) {
  23. case "9":
  24. weatherText.text = "晴天";
  25. image.sprite = weatherSprite[0];
  26. break;
  27. case "8":
  28. weatherText.text = "阴天";
  29. image.sprite = weatherSprite[1];
  30. break;
  31. case "7":
  32. weatherText.text = "雨天";
  33. image.sprite = weatherSprite[2];
  34. break;
  35. case "6":
  36. weatherText.text = "雨夹雪";
  37. image.sprite = weatherSprite[3];
  38. break;
  39. case "5":
  40. weatherText.text = "雪天";
  41. image.sprite = weatherSprite[4];
  42. break;
  43. }
  44. }
  45. // Update is called once per frame
  46. void Update()
  47. {
  48. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  49. }
  50. }