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 展开
|
|
//点击按钮需通知响应外部事件
|
public 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);
|
});
|
}
|
|
}
|
|
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()
|
{
|
unFoldBtn.SetActive(foldState == 1);
|
foldBtn.SetActive(foldState == 0);
|
}
|
}
|