GQ_Communicate/GQ_VR/Assets/script/MenuCarousel/CarouselMenuALL.cs

277 lines
7.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using Toolset.UI;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using static BaseConf;
public class CarouselMenuALL : MonoBehaviour
{
public static CarouselMenuALL Inst;
public Button sb_bt;//设备
public Button bk_bt;//板卡
public Button fs_bt;//风扇
public Button dc_bt;//电池
public Sprite init_img;
public CarouselMenu carouselMenu;
public CarouselMenu Init_carouselMenu;
public Button left_bt;
public Button right_bt;
public List<GameObject> gameObjects;
public GameObject sb_game;
public GameObject bk_game;
public GameObject fs_game;
public GameObject dc_game;
/// <summary>
/// 自动筛选板卡元素列表
/// </summary>
public List<DragController> list = new List<DragController>();
/// <summary>
/// 所有子菜单
/// </summary>
public List<ItemMenuText> itemMenus = new List<ItemMenuText>();
public Button search_bt;
public TMP_InputField InputField;
private void Awake()
{
Inst = this;
}
private void OnEnable()
{
carouselMenu = Init_carouselMenu;
InputField.text = string.Empty;
if (list.Count <= 0)
{
for (int i = 0; i < sb_game.transform.childCount; i++)
{
var dc = sb_game.transform.GetChild(i).GetComponent<DragController>();
if (!dc.oriObjectPrefab)
dc.oriObjectPrefab = Resources.Load<DragTest1>("古泉站机房模型90个型号/" + dc.name);
}
for (int i = 0; i < bk_game.transform.childCount; i++)
{
var dc = bk_game.transform.GetChild(i).GetComponent<DragController>();
list.Add(dc);
if (!dc.oriObjectPrefab)
dc.oriObjectPrefab = Resources.Load<DragTest1>("古泉站机房模型90个型号/" + dc.name);
}
}
init();
//carouselMenu.Refresh();
}
private void OnDisable()
{
}
// Start is called before the first frame update
void Start()
{
itemMenus = GetComponentsInChildren<ItemMenuText>(true).ToList();
sb_bt.onClick.AddListener(() =>
{
sb_bt_onClick();
});
bk_bt.onClick.AddListener(() =>
{
bk_bt_onClick();
});
fs_bt.onClick.AddListener(() =>
{
fs_bt_onClick();
});
dc_bt.onClick.AddListener(() =>
{
dc_bt_onClick();
});
left_bt.onClick.AddListener(() =>
{
carouselMenu.Btn_Left(left_bt);
});
right_bt.onClick.AddListener(() =>
{
carouselMenu.Btn_Right(right_bt);
});
search_bt.onClick.AddListener(() =>
{
if (string.IsNullOrEmpty(InputField.text))
{
showAll_DragController();
//return;
packagingFiltering();
}
else
{
PatternChoose.Inst.DetectCharacters((x) =>
{
if(!x)
return;
else
{
packagingFiltering();
}
}, InputField);
}
});
}
/// <summary>
/// 封装筛选
/// </summary>
public void packagingFiltering()
{
var itemMenuTexts = carouselMenu.gameObject.GetComponentsInChildren<ItemMenuText>(true).ToList();
//筛选
//List<ItemMenuText> list = new List<ItemMenuText>();
List<ItemMenuText> v = itemMenuTexts.Where(x => x.text.text.Contains(InputField.text)).ToList();
//共有的元素
var commonItems = itemMenuTexts.Intersect(v).ToList();
//独有的元素
var uniqueItems = itemMenuTexts.Where(x => !v.Contains(x)).Union(v.Where(y => !itemMenuTexts.Contains(y))).ToList();
for (int i = 0; i < commonItems.Count; i++)
commonItems[i].gameObject.SetActive(true);
for (int i = 0; i < uniqueItems.Count; i++)
uniqueItems[i].gameObject.SetActive(false);
carouselMenu.Refresh();
}
public void sb_bt_onClick()
{
showAll_DragController();
sb_bt.GetComponent<Image>().sprite = sb_bt.spriteState.selectedSprite;
bk_bt.GetComponent<Image>().sprite = init_img;
gameObjects_cls();
sb_game.SetActive(true);
sb_game.GetComponent<CarouselMenu>().Refresh();
}
public void bk_bt_onClick()
{
showAll_DragController();
sb_bt.GetComponent<Image>().sprite = init_img;
bk_bt.GetComponent<Image>().sprite = bk_bt.spriteState.selectedSprite;
gameObjects_cls();
bk_game.SetActive(true);
bk_game.GetComponent<CarouselMenu>().Refresh();
}
public void fs_bt_onClick()
{
gameObjects_cls();
fs_game.SetActive(true);
}
public void dc_bt_onClick()
{
gameObjects_cls();
dc_game.SetActive(true);
}
// Update is called once per frame
void Update()
{
}
public void gameObjects_cls()
{
for (int i = 0; i < gameObjects.Count; i++)
{
gameObjects[i].SetActive(false);
}
}
public void init()
{
sb_bt.Select();
sb_bt_onClick();
}
public void setCarouselMenu(CarouselMenu menu)
{
carouselMenu = menu;
}
/// <summary>
/// 筛选相同类型
/// </summary>
public void Filter_Type()
{
List<UPosItem> upostItems = new List<UPosItem>();
//DeviceQuery now_DeviceQuery = new DeviceQuery();
if (GameManager.Inst.nowDevice && GameManager.Inst.nowDevice.GetComponent<DeviceQuery>())
{
//now_DeviceQuery = GameManager.Inst.nowDevice.GetComponent<DeviceQuery>();
var UM = GameManager.Inst.nowDevice.transform.Find("U位");
if (UM)
{
upostItems = UM.GetComponentsInChildren<UPosItem>().ToList();
}
else
{
return;
}
}
else
{
return;
}
//for (int i = 0; i < upostItems.Count; i++)
//{
for (int j = 0; j < list.Count; j++)
{
list[j].gameObject.SetActive(false);
for (int i = 0; i < upostItems.Count; i++)
{
GameObject prefab = Resources.Load("古泉站机房模型90个型号/" + list[j].name) as GameObject;
var qd_game = prefab.GetComponent<DeviceQuery>();
var qd_upostItem = upostItems[i];
if (qd_upostItem.conf2.module_type == ModuleType. &&
qd_game.conf2.module_type == ModuleType. &&
qd_upostItem.conf2.type_card == qd_game.conf2.type_card)
{
list[j].gameObject.SetActive(true);
break;
}
}
}
//}
bk_game.GetComponent<CarouselMenu>().Refresh();
}
/// <summary>
/// 恢复所有子菜单显示
/// </summary>
public void showAll_DragController()
{
for (int i = 0; i < itemMenus.Count; i++)
{
itemMenus[i].gameObject.SetActive(true);
}
}
}