| using System; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
| //武将筛选 | 
| public class HeroSelectBehaviour : MonoBehaviour | 
| { | 
|     [SerializeField] Transform unFoldForm;  //展开后的容器 | 
|     [SerializeField] Button foldBtn;    //收起按钮 | 
|     [SerializeField] Transform foldForm;    //收起容器 | 
|     [SerializeField] Button unFoldBtn;  //展开按钮 | 
|     [SerializeField] GroupButtonEx[] jobsBtn; | 
|     [SerializeField] GroupButtonEx[] countrysBtn; | 
|     [SerializeField] GroupButtonExManager jobManager; | 
|     [SerializeField] GroupButtonExManager countryManager; | 
|   | 
|     int m_Job = 0; | 
|     int m_Country = 0; | 
|     int foldState = 0;  //0 收起,1 展开 | 
|   | 
|     //点击按钮需通知响应外部事件 | 
|     private Action<int, int> selectAction; | 
|   | 
|   | 
|   | 
|   | 
|     void Awake() | 
|     { | 
|         foldBtn.AddListener(() => | 
|         { | 
|             foldState = 0; | 
|             RefreshFolState(); | 
|         }); | 
|         unFoldBtn.AddListener(() => | 
|         { | 
|             foldState = 1; | 
|             RefreshFolState(); | 
|         }); | 
|   | 
|         for (int i = 0; i < jobsBtn.Length; i++) | 
|         { | 
|             int index = i; | 
|             jobsBtn[i].AddListener(() => | 
|             { | 
|                 m_Job = index; | 
|                 RefreshJobsBtn(); | 
|                 selectAction?.Invoke(m_Job, m_Country); | 
|             }); | 
|         } | 
|   | 
|         for (int i = 0; i < countrysBtn.Length; i++) | 
|         { | 
|             int index = i; | 
|             countrysBtn[i].AddListener(() => | 
|             { | 
|                 m_Country = index; | 
|                 RefreshCountryBtn(); | 
|                 selectAction?.Invoke(m_Job, m_Country); | 
|             }); | 
|         } | 
|   | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 国家职业筛选 | 
|     /// </summary> | 
|     /// <param name="state"> 0收起,1展开</param> | 
|     /// <param name="job"></param> | 
|     /// <param name="country"></param> | 
|     /// <param name="onRefresh"> 点击按钮需通知响应外部事件</param> | 
|     public void Display(int state, int job, int country, Action<int, int> onRefresh) | 
|     { | 
|         foldState = state; | 
|         m_Job = job; | 
|         m_Country = country; | 
|   | 
|         RefreshFolState(); | 
|         RefreshJobsBtn(); | 
|         RefreshCountryBtn(); | 
|         selectAction = onRefresh; | 
|   | 
|     } | 
|   | 
|   | 
|     //刷新全部分类  | 
|     void RefreshJobsBtn() | 
|     { | 
|         jobManager.SelectButton(jobsBtn[m_Job]); | 
|     } | 
|     //刷新全部分类 | 
|     void RefreshCountryBtn() | 
|     { | 
|         countryManager.SelectButton(countrysBtn[m_Country]); | 
|     } | 
|     //刷新展开收起状态 | 
|     void RefreshFolState() | 
|     { | 
|         unFoldForm.SetActive(foldState == 1); | 
|         foldForm.SetActive(foldState == 0); | 
|     } | 
|      | 
|   | 
|     private void LateUpdate() | 
|     { | 
|         if (foldState == 0) | 
|             return; | 
|         if (Input.GetMouseButtonDown(0)) | 
|         { | 
|             if (!RectTransformUtility.RectangleContainsScreenPoint(this.transform as RectTransform, Input.mousePosition, CameraManager.uiCamera)) | 
|             { | 
|                 foldBtn.onClick.Invoke(); | 
|             } | 
|         } | 
|     } | 
| } |