LIstTextManager.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class LIstTextManager : MonoBehaviour
  6. {
  7. public Text t;
  8. public static List<string> showstr=new List<string>();
  9. List<GameObject> showGame=new List<GameObject>();
  10. public void showTip()
  11. {
  12. if(showstr.Count>0)
  13. {
  14. this.gameObject.SetActive(true);
  15. }
  16. for (int i = 0;i<showstr.Count;i++)
  17. {
  18. GameObject go =GameObject.Instantiate( t.gameObject,t.transform.parent);
  19. go.SetActive(true);
  20. go.GetComponent<Text>().text = showstr[i];
  21. showGame.Add(go);
  22. }
  23. }
  24. public void closeTip()
  25. {
  26. for (int i = 0;i<showGame.Count;i++)
  27. {
  28. Destroy(showGame[i]);
  29. }
  30. showGame=new List<GameObject>();
  31. this.gameObject.SetActive(false);
  32. }
  33. private float Px, Py;
  34. private void Update() {
  35. float fz =this.transform.parent.localScale.x *this.transform.parent.parent.localScale.x;
  36. this.transform.GetComponent<RectTransform>().localPosition = new Vector3(-Screen.width/2/fz+Input.mousePosition.x/fz, -Screen.height/2/fz+Input.mousePosition.y /fz ,0); // 设置浮窗位置
  37. }
  38. }