FileList.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 void Init(List<FileConfig> fileConfiglist)
  9. {
  10. if (transform.childCount > 0)
  11. {
  12. for (int i = 0; i < transform.childCount; i++)
  13. {
  14. Destroy(transform.GetChild(i).gameObject);
  15. }
  16. }
  17. for (int i = 0; i < fileConfiglist.Count; i++)
  18. {
  19. AddItem(fileConfiglist[i]);
  20. }
  21. fileConfiglist.Clear();
  22. }
  23. public void AddItem(FileConfig fileConfig)
  24. {
  25. if (!RoomFile.Instance.allFile.activeSelf)
  26. {
  27. RoomFile.fileUpdataCount++;
  28. RoomFile.Instance.UpdataCountAction?.Invoke(RoomFile.fileUpdataCount);
  29. }
  30. GameObject obj = Instantiate(Item, transform) as GameObject;
  31. obj.transform.GetComponent<FileItem>().Init(fileConfig);
  32. if (RoomMainInfo.isCreator == "0")
  33. {
  34. RoomFile.Instance.ShowClearBtn();
  35. }
  36. if (RoomInfo.Instance && fileConfig != null)
  37. {
  38. RoomInfo.Instance.ctManager.SetText(fileConfig.From + "发送了文件:" + fileConfig.FileName);
  39. }
  40. RoomFile.Instance.showfileCountText.text = "文件-" + transform.childCount.ToString();
  41. }
  42. public void RemoveItem(FileConfig fileConfig)
  43. {
  44. if (this.transform.childCount == 1 && RoomMainInfo.isCreator == "0")
  45. {
  46. RoomFile.Instance.HideClearBtn();
  47. }
  48. if (RoomInfo.Instance && fileConfig != null)
  49. {
  50. //RoomInfo.Instance.ctManager.SetText(fileConfig.From + "删除了文件:" + fileConfig.FileName);
  51. }
  52. if (this.transform.childCount >= 1)
  53. {
  54. RoomFile.Instance.showfileCountText.text = "文件-" + (transform.childCount - 1).ToString();
  55. }
  56. }
  57. public void DestoryAll()
  58. {
  59. if (transform.childCount > 0)
  60. {
  61. for (int i = 0; i < transform.childCount; i++)
  62. {
  63. Destroy(transform.GetChild(i).gameObject);
  64. }
  65. }
  66. RoomFile.Instance.showfileCountText.text = "文件-" + 0;
  67. }
  68. }