using ShadowStudio.Model; using ShadowStudio.UI; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using XRTool.WorldUI; public class ZiYuanFileView : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { public Button button; public GameObject enterImage; public GameObject blueImage; public GameObject grayImage; public XRIcon icon; public Text nametext; private ArtInfo info; private ArtHandler handler; // Start is called before the first frame update void Start() { ZiYuanKuDlg.Instance.ShowOrHideGrayImage += ShowOrHideGray; ZiYuanKuDlg.Instance.CanelLoadAction += CanelLoad; button.onClick.AddListener(ValueChange); } private void CanelLoad() { blueImage.SetActive(false); grayImage.SetActive(false); } private void ShowOrHideGray(int num) { if (!blueImage.activeSelf) { if (num >= 3) { grayImage.SetActive(true); } else { grayImage.SetActive(false); } } } private void ValueChange() { if (!grayImage.activeSelf) { if (!blueImage.activeSelf) { blueImage.SetActive(true); if (this.info != null) { ZiYuanKuDlg.Instance.NeedLoadartInfos.Add(this.info); } } else { blueImage.SetActive(false); if (this.info != null) { ZiYuanKuDlg.Instance.NeedLoadartInfos.Remove(this.info); } } ZiYuanKuDlg.Instance.ShowOrHideGrayImage?.Invoke(ZiYuanKuDlg.Instance.NeedLoadartInfos.Count); } else { ConsoleDlg.Instance.ShowTipPop("一次最多选中三个文件哦"); } } public void Init(ArtInfo artInfo) { this.info = artInfo; nametext.text = artInfo.ArtName; handler = ArtInfoMgr.Instance.CreateArtHandler(info); var sprite = handler.GetIcon(); if (sprite) { icon.icon = sprite as Texture2D; icon.AutoSetSprite(); } else { handler.GetIcon((tex) => { sprite = tex; if (sprite) { icon.icon = sprite as Texture2D; icon.AutoSetSprite(); } }); } } public void OnPointerEnter(PointerEventData eventData) { if (blueImage.activeSelf || grayImage.activeSelf) { return; } this.enterImage.SetActive(true); } public void OnPointerExit(PointerEventData eventData) { if (blueImage.activeSelf || grayImage.activeSelf) { return; } this.enterImage.SetActive(false); } private void OnDestroy() { if (ZiYuanKuDlg.Instance) { ZiYuanKuDlg.Instance.ShowOrHideGrayImage -= ShowOrHideGray; ZiYuanKuDlg.Instance.CanelLoadAction -= CanelLoad; } } }