FacilityDetailsListViewer.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FacilityDetailsListViewer : MonoBehaviour
  5. {
  6. public void CreateFacilityDetailsList<T>(int itemCount, Action<int, T> onCreateItem) where T : FacilityDetailsListViewer.FacilityDetailsUI
  7. {
  8. this.m_ListViewerFacilityDetails.Show<Transform>(itemCount, delegate(int index, Transform trans)
  9. {
  10. onCreateItem(index, trans.gameObject.AddComponent<T>());
  11. });
  12. }
  13. public bool IsExistItemList()
  14. {
  15. NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
  16. return this.m_ListViewerFacilityDetails.ItemArray != null && this.m_ListViewerFacilityDetails.ItemArray.Length > 0;
  17. }
  18. public int GetItemCount()
  19. {
  20. NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
  21. if (!this.IsExistItemList())
  22. {
  23. return 0;
  24. }
  25. return this.m_ListViewerFacilityDetails.ItemArray.Length;
  26. }
  27. public T GetItem<T>(int index) where T : Component
  28. {
  29. NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
  30. GameObject[] itemArray = this.m_ListViewerFacilityDetails.ItemArray;
  31. if (itemArray == null)
  32. {
  33. return (T)((object)null);
  34. }
  35. if (itemArray.Length <= index)
  36. {
  37. return (T)((object)null);
  38. }
  39. return itemArray[index].GetComponent<T>();
  40. }
  41. public List<T> GetAllItem<T>() where T : Component
  42. {
  43. NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
  44. GameObject[] itemArray = this.m_ListViewerFacilityDetails.ItemArray;
  45. if (itemArray == null)
  46. {
  47. return null;
  48. }
  49. List<T> list = new List<T>();
  50. int num = itemArray.Length;
  51. for (int i = 0; i < num; i++)
  52. {
  53. list.Add(this.GetItem<T>(i));
  54. }
  55. return list;
  56. }
  57. [SerializeField]
  58. private uGUIListViewer m_ListViewerFacilityDetails;
  59. public class FacilityDetailsUI : MonoBehaviour
  60. {
  61. public FacilityInfoUI facilityInfoUI
  62. {
  63. get
  64. {
  65. FacilityInfoUI result;
  66. if ((result = this.m_InfoUI) == null)
  67. {
  68. result = (this.m_InfoUI = base.GetComponent<FacilityInfoUI>());
  69. }
  70. return result;
  71. }
  72. }
  73. private FacilityInfoUI m_InfoUI;
  74. }
  75. }