using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Drow : MonoBehaviour
{
//下拉框面板
public GameObject Dro;
string str;
//
public List<Toggle> to;
List<string> strlist=new List<string>();
List<int> intlist = new List<int>();
//提示框显示选中字 显示选中得第一个字
public GameObject Te;
//选中框对应Image亮
public List<Image> ImageList;
int MI = 0;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < to.Count; i++)
{
int L = i;
to[L].onValueChanged.AddListener((bool b) => SetTo(b, L));
to[L].transform.Find("Label").GetComponent<Text>().text = to[i].name;
}
}
void SetTo(bool b,int j)
{
if (j == 0 )
{
StrMethod(0, b);
}
else if (j == 1 )
{
StrMethod(1,b);
}
else if (j == 2 )
{
StrMethod(2, b);
}
else if (j == 3 )
{
StrMethod(3, b);
}
else if (j == 4 )
{
StrMethod(4, b);
}
else if (j == 5 )
{
StrMethod(5, b);
}
else if (j == 6 )
{
StrMethod(6, b);
}
}
//判断ison
private void StrMethod(int i,bool b)
{
if (b)
{
strlist.Add(to[i].name);
intlist.Add(i);
}
else
{
intlist.Remove(i);
}
}
//下拉框箭头按钮
public void Setbool()
{
Dro.SetActive(!Dro.activeSelf);
if (Dro.activeSelf==false)
{
ImageMethod(intlist);
//foreach (var item in strlist)
//{
// print(item);
//}
//for (int i = 0; i < to.Count; i++)
//{
// if (to[i].isOn)
// {
// intlist.Add(i);
// }
//}
for (int i = 0; i < to.Count; i++)
{
if (intlist[MI]==i)
{
ImageList[i].color = Color.yellow;
if (MI<intlist.Count-1)
{
MI++;
print(MI);
}
}
else
{
ImageList[i].color = Color.red;
}
}
MI = 0;
// Te.GetComponent<Text>(). text = strlist[0];
}
else
{
strlist.Clear();
// intlist.Clear();
}
}
//排序
private void ImageMethod(List<int> li)
{
for (int i = 0; i < li.Count - 1; i++) //外层循环需要循环n - 1次
{
for (int j = 0; j < li.Count - 1 - i; j++)
{
if (li[j] > li[j + 1]) //从小到大排序
{
int temp = li[j + 1]; //定义一个值用于交换使用 如果数组第二个数小于前一个数,那么把第二个小的数显存放着
li[j + 1] = li[j]; //把前一个大的数放到后面
li[j] = temp; //再把存放在temp中小的数放在后面
}
}
}
}
}