TaskListPanel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class TaskListPanel : MonoBehaviour
  7. {
  8. public Button taskTpye_allButton;
  9. public Button taskTpye_dianQiButton;
  10. public Button taskTpye_zhaZhanButton;
  11. public Button taskTpye_diFangButton;
  12. public Button taskTpye_jianZhuButton;
  13. public Button taskTpye_zhuanXiangButton;
  14. public InputField inputField;
  15. public GameObject taskItemPrefab;
  16. public Transform itemContent;
  17. public List<B08_TaskListItem> taskItemList = new List<B08_TaskListItem>();
  18. public GCYWLayer gcywLayer;
  19. public B08_TaskListData[] taskInfoList;
  20. private void Awake()
  21. {
  22. taskTpye_allButton.onClick.AddListener(()=>SetType("-1"));
  23. taskTpye_dianQiButton.onClick.AddListener(()=>SetType("0"));
  24. taskTpye_zhaZhanButton.onClick.AddListener(()=>SetType("1"));
  25. taskTpye_diFangButton.onClick.AddListener(()=>SetType("2"));
  26. taskTpye_jianZhuButton.onClick.AddListener(()=>SetType("3"));
  27. taskTpye_zhuanXiangButton.onClick.AddListener(()=>SetType("4"));
  28. inputField.onValueChanged.AddListener(Search);
  29. }
  30. public void Search(string inputStr)
  31. {
  32. for (int i = 0; i < taskItemList.Count; i++)
  33. {
  34. taskItemList[i].gameObject.SetActive(taskItemList[i].InfoData.title.Contains(inputStr));
  35. }
  36. }
  37. public void SetType(string type)
  38. {
  39. if (type.Equals("-1"))
  40. {
  41. for (int i = 0; i < taskItemList.Count; i++)
  42. {
  43. taskItemList[i].gameObject.SetActive(true);
  44. }
  45. return;
  46. }
  47. for (int i = 0; i < taskItemList.Count; i++)
  48. {
  49. taskItemList[i].gameObject.SetActive(taskItemList[i].InfoData.type.Equals(type));
  50. }
  51. }
  52. public void SetData(GCYWLayer baseLayer)
  53. {
  54. gcywLayer = baseLayer;
  55. for (int i = 0; i < taskItemList.Count; i++)
  56. {
  57. Destroy(taskItemList[i].gameObject);
  58. }
  59. taskItemList.Clear();
  60. taskInfoList = GlobalData.B08TaskListData.rows;
  61. if (taskInfoList != null)
  62. {
  63. for (int j = 0; j < taskInfoList.Length; j++)
  64. {
  65. B08_TaskListItem tempItem = Instantiate(taskItemPrefab, itemContent).GetComponent<B08_TaskListItem>();
  66. tempItem.Init();
  67. tempItem.SetData(gcywLayer, taskInfoList[j].infoData);
  68. taskItemList.Add(tempItem);
  69. }
  70. }
  71. }
  72. }