BaseList.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using SUIFW;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class BaseList : MonoBehaviour
  6. {
  7. [HideInInspector]
  8. public List<BaseConfig> configs = new List<BaseConfig>();
  9. [HideInInspector]
  10. public List<BaseView> Views = new List<BaseView>();
  11. [HideInInspector]
  12. private int maxCount;
  13. public virtual void InitList(List<BaseConfig> c)
  14. {
  15. if (Views.Count <= 0)
  16. {
  17. maxCount = 10;
  18. Views = new List<BaseView>();
  19. BaseView cloneView;
  20. for (int i = 0; i < maxCount; i++)
  21. {
  22. GameObject peerItemObj = ResourcesMgr.GetInstance().LoadAsset("ItemPrefabs/PeerItem", false);
  23. peerItemObj.transform.SetParent(this.transform);
  24. peerItemObj.transform.localScale = new Vector3(1, 1, 1);
  25. cloneView = peerItemObj.GetComponent<BaseView>();
  26. Views.Add(cloneView);
  27. }
  28. }
  29. configs = new List<BaseConfig>();
  30. c.ForEach(i => configs.Add(i));
  31. int vindex = 0;
  32. for (int i = 0; i < Views.Count; i++)
  33. {
  34. if (i < configs.Count)
  35. {
  36. Views[i].Init(i, configs[i], vindex);
  37. Views[i].baselist = this;
  38. Views[i].gameObject.SetActive(true);
  39. vindex++;
  40. }
  41. else
  42. {
  43. Views[i].gameObject.SetActive(false);
  44. }
  45. }
  46. }
  47. }