ZiYuanFileView.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using ShadowStudio.Model;
  2. using ShadowStudio.UI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. using UnityEngine.UI;
  9. using XRTool.WorldUI;
  10. public class ZiYuanFileView : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  11. {
  12. public Button button;
  13. public GameObject enterImage;
  14. public GameObject blueImage;
  15. public GameObject grayImage;
  16. public XRIcon icon;
  17. public Text nametext;
  18. private ArtInfo info;
  19. private ArtHandler handler;
  20. // Start is called before the first frame update
  21. void Start()
  22. {
  23. ZiYuanKuDlg.Instance.ShowOrHideGrayImage += ShowOrHideGray;
  24. ZiYuanKuDlg.Instance.CanelLoadAction += CanelLoad;
  25. button.onClick.AddListener(ValueChange);
  26. }
  27. private void CanelLoad()
  28. {
  29. blueImage.SetActive(false);
  30. grayImage.SetActive(false);
  31. }
  32. private void ShowOrHideGray(int num)
  33. {
  34. if (!blueImage.activeSelf)
  35. {
  36. if (num >= 3)
  37. {
  38. grayImage.SetActive(true);
  39. }
  40. else
  41. {
  42. grayImage.SetActive(false);
  43. }
  44. }
  45. }
  46. private void ValueChange()
  47. {
  48. if (!grayImage.activeSelf)
  49. {
  50. if (!blueImage.activeSelf)
  51. {
  52. blueImage.SetActive(true);
  53. if (this.info != null)
  54. {
  55. ZiYuanKuDlg.Instance.NeedLoadartInfos.Add(this.info);
  56. }
  57. }
  58. else
  59. {
  60. blueImage.SetActive(false);
  61. if (this.info != null)
  62. {
  63. ZiYuanKuDlg.Instance.NeedLoadartInfos.Remove(this.info);
  64. }
  65. }
  66. ZiYuanKuDlg.Instance.ShowOrHideGrayImage?.Invoke(ZiYuanKuDlg.Instance.NeedLoadartInfos.Count);
  67. }
  68. else
  69. {
  70. ConsoleDlg.Instance.ShowTipPop("一次最多选中三个文件哦");
  71. }
  72. }
  73. public void Init(ArtInfo artInfo)
  74. {
  75. this.info = artInfo;
  76. nametext.text = artInfo.ArtName;
  77. handler = ArtInfoMgr.Instance.CreateArtHandler(info);
  78. var sprite = handler.GetIcon();
  79. if (sprite)
  80. {
  81. icon.icon = sprite as Texture2D;
  82. icon.AutoSetSprite();
  83. }
  84. else
  85. {
  86. handler.GetIcon((tex) =>
  87. {
  88. sprite = tex;
  89. if (sprite)
  90. {
  91. icon.icon = sprite as Texture2D;
  92. icon.AutoSetSprite();
  93. }
  94. });
  95. }
  96. }
  97. public void OnPointerEnter(PointerEventData eventData)
  98. {
  99. if (blueImage.activeSelf || grayImage.activeSelf)
  100. {
  101. return;
  102. }
  103. this.enterImage.SetActive(true);
  104. }
  105. public void OnPointerExit(PointerEventData eventData)
  106. {
  107. if (blueImage.activeSelf || grayImage.activeSelf)
  108. {
  109. return;
  110. }
  111. this.enterImage.SetActive(false);
  112. }
  113. private void OnDestroy()
  114. {
  115. if (ZiYuanKuDlg.Instance)
  116. {
  117. ZiYuanKuDlg.Instance.ShowOrHideGrayImage -= ShowOrHideGray;
  118. ZiYuanKuDlg.Instance.CanelLoadAction -= CanelLoad;
  119. }
  120. }
  121. }