FileList.cs 3.1 KB

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