WeatherUnit.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class WeatherUnit : MonoBehaviour
  7. {
  8. public Text nameText;
  9. public Text dropText;
  10. public Image image;
  11. public GameObject[] weatherSprite;
  12. public Sprite[] sprites;
  13. public GameObject bingObj;
  14. private int index = 0;
  15. private float currentIndex = 0;
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. }
  20. public void Init(double lgtd, double lttd, string na, string we,float drop)
  21. {
  22. for (int i = 0; i < weatherSprite.Length; i++) {
  23. weatherSprite[i].gameObject.SetActive(false);
  24. }
  25. dropText.text = drop.ToString();
  26. Vector3 temp = CoordinateConverter.GeoToUGUISmall(lgtd, lttd);
  27. this.GetComponent<RectTransform>().anchoredPosition3D = temp;
  28. nameText.text = na.Trim();
  29. image.sprite = sprites[0];
  30. currentIndex = 0;
  31. index = (int)Mathf.Clamp(Mathf.Round(drop / 2.0f), 0, 9);
  32. switch (we) {
  33. case "9":
  34. weatherSprite[0].gameObject.SetActive(true);
  35. break;
  36. case "8":
  37. weatherSprite[1].gameObject.SetActive(true);
  38. break;
  39. case "7":
  40. weatherSprite[2].gameObject.SetActive(true);
  41. break;
  42. case "6":
  43. weatherSprite[3].gameObject.SetActive(true);
  44. break;
  45. case "5":
  46. weatherSprite[4].gameObject.SetActive(true);
  47. break;
  48. }
  49. }
  50. // Update is called once per frame
  51. void Update()
  52. {
  53. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  54. if (index > currentIndex)
  55. {
  56. //Debug.Log((int)(currentIndex));
  57. currentIndex += Time.deltaTime;
  58. image.sprite = sprites[(int)(currentIndex)];
  59. }
  60. }
  61. }