FileList.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using XRTool.Util;
  6. public class FileList : UnitySingleton<FileList>
  7. {
  8. public GameObject Item;
  9. public GameObject MesItem;
  10. public RectTransform FileContent;
  11. public void Init(List<FileConfig> fileConfiglist)
  12. {
  13. if (transform.childCount > 0)
  14. {
  15. for (int i = 0; i < transform.childCount; i++)
  16. {
  17. Destroy(transform.GetChild(i).gameObject);
  18. }
  19. }
  20. for (int i = 0; i < fileConfiglist.Count; i++)
  21. {
  22. AddItem(fileConfiglist[i]);
  23. }
  24. fileConfiglist.Clear();
  25. // FileContent.anchoredPosition += new Vector2(0, 500);
  26. }
  27. public void AddItem(FileConfig fileConfig)
  28. {
  29. if (!RoomFile.Instance.allFile.activeSelf)
  30. {
  31. RoomFile.fileUpdataCount++;
  32. RoomFile.Instance.UpdataCountAction?.Invoke(RoomFile.fileUpdataCount);
  33. }
  34. //GameObject obj = Instantiate(Item, transform) as GameObject;
  35. //obj.transform.GetComponent<FileItem>().Init(fileConfig);
  36. if (RoomMainInfo.isCreator == "0")
  37. {
  38. RoomFile.Instance.ShowClearBtn();
  39. }
  40. if (RoomInfo.Instance && fileConfig != null)
  41. {
  42. RoomInfo.Instance.ctManager.SetText(fileConfig.From + "发送了文件:" + fileConfig.FileName);
  43. }
  44. RoomFile.Instance.showfileCountText.text = "文件-" + transform.childCount.ToString();
  45. GameObject MsgItem = GameObject.Instantiate(MesItem, transform) as GameObject;
  46. MsgItem.GetComponent<MsgItem>().Init(null, fileConfig);
  47. if (FileContent == null)
  48. FileContent = transform.GetComponent<RectTransform>();
  49. else
  50. FileContent.anchoredPosition3D += new Vector3(0, 300, 0);
  51. LayoutRebuilder.ForceRebuildLayoutImmediate(FileContent);
  52. }
  53. public void AddMsgItem(Sprite head, string name , string msg)
  54. {
  55. GameObject MsgItem = GameObject.Instantiate(MesItem, transform) as GameObject;
  56. MsgItem.GetComponent<MsgItem>().Init(null, name, msg);
  57. if (FileContent == null)
  58. FileContent = transform.GetComponent<RectTransform>();
  59. else
  60. FileContent.anchoredPosition3D += new Vector3(0, 300, 0);
  61. LayoutRebuilder.ForceRebuildLayoutImmediate(FileContent);
  62. }
  63. public void RemoveItem(FileConfig fileConfig)
  64. {
  65. if (this.transform.childCount == 1 && RoomMainInfo.isCreator == "0")
  66. {
  67. RoomFile.Instance.HideClearBtn();
  68. }
  69. if (RoomInfo.Instance && fileConfig != null)
  70. {
  71. //RoomInfo.Instance.ctManager.SetText(fileConfig.From + "删除了文件:" + fileConfig.FileName);
  72. }
  73. if (this.transform.childCount >= 1)
  74. {
  75. RoomFile.Instance.showfileCountText.text = "文件-" + (transform.childCount - 1).ToString();
  76. }
  77. }
  78. public void DestoryAll()
  79. {
  80. if (transform.childCount > 0)
  81. {
  82. for (int i = 0; i < transform.childCount; i++)
  83. {
  84. Destroy(transform.GetChild(i).gameObject);
  85. }
  86. }
  87. RoomFile.Instance.showfileCountText.text = "文件-" + 0;
  88. }
  89. }