MsgItem.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. public class MsgItem : MonoBehaviour
  7. {
  8. public Image headImage;
  9. public TMP_Text nameText;
  10. public string msgType;
  11. public FileItem fileItem;
  12. public List<ContentSizeFitter> refreshFitter;
  13. public GameObject messageItem;
  14. public Text msgText;
  15. private FileConfig fileConfig;
  16. public void Init( Sprite headImage, string name , string message )
  17. {
  18. if (headImage != null)
  19. this.headImage.sprite = headImage;
  20. nameText.text = name;
  21. this.fileItem.gameObject.SetActive(false);
  22. this.messageItem.SetActive(true);
  23. msgText.text = message;
  24. StartCoroutine(Refresh());
  25. }
  26. public void Init(Sprite headImage, FileConfig fileConfig)
  27. {
  28. this.fileConfig = fileConfig;
  29. fileItem.Init(fileConfig);
  30. nameText.text = fileConfig.From;
  31. this.fileItem.gameObject.SetActive(true);
  32. this.messageItem.SetActive(false);
  33. if (headImage != null)
  34. this.headImage.sprite = headImage;
  35. }
  36. private IEnumerator Refresh()
  37. {
  38. int i = 0;
  39. while(i<refreshFitter.Count)
  40. {
  41. yield return new WaitForFixedUpdate();
  42. LayoutRebuilder.ForceRebuildLayoutImmediate(refreshFitter[i++].GetComponent<RectTransform>());
  43. }
  44. }
  45. }