PersonalFileView.cs 3.2 KB

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