MsgItem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if (headImage != null)
  32. this.headImage.sprite = headImage;
  33. }
  34. private IEnumerator Refresh()
  35. {
  36. int i = 0;
  37. while(i<refreshFitter.Count)
  38. {
  39. yield return new WaitForFixedUpdate();
  40. LayoutRebuilder.ForceRebuildLayoutImmediate(refreshFitter[i++].GetComponent<RectTransform>());
  41. }
  42. }
  43. }