using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.XR.PXR;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using YiLiao.JingLuoXueWei;
using ZXKFramework;
public class SouSuoPanel : UIBase
{
public override string GroupName => typeof(SouSuoPanel).Name;
public override string Name => typeof(SouSuoPanel).Name;
///
/// 当前显示的搜索按钮队列
///
Queue souSuoBtn_Que;
Button exit_Btn;
InputField souSuo_InputField;
List allJingLuoSmall;
List allSouSuoBtn;
public override void Init(IUIManager uictrl)
{
base.Init(uictrl);
souSuoBtn_Que = new Queue();
exit_Btn = transform.FindFirst("Exit_Btn");
exit_Btn.onClick.AddListener(() =>
{
uiManager.CloseUI();
});
allJingLuoSmall = MVC.GetModel().excelData.allJingLuoSmall;
souSuo_InputField = transform.FindFirst("souSuo_Input");
souSuo_InputField.onValueChanged.AddListener(InputValueChanged);
souSuo_InputField.onSubmit.AddListener(InputSubmit);
}
private void InputSubmit(string arg0)
{
if (souSuoBtn_Que.Count > 0)
{
int num = souSuoBtn_Que.Count;
for (int i = 0; i < num; i++)
{
GameObject g = souSuoBtn_Que.Dequeue();
g.SetActive(false);
GameObject_Pool.Instance.PutInGame("souSuoBtn", g);
}
}
this.Warn($"当前输入的文字是:{arg0}");
if (string.IsNullOrEmpty(arg0)) return;
for (int i = 0; i < allJingLuoSmall.Count; i++)
{
if (allJingLuoSmall[i].XueWeiName_NoPinYin.Contains(arg0))
{
int id = i;
Debug.Log($"应该创建搜索按钮:{allJingLuoSmall[i].XueWeiName_NoPinYin}");
souSuo_InputField.text = $"{arg0}";
//GameObject go = Resources.Load("souSuoBtn");
//GameObject obj = GameObject.Instantiate(go, transform.FindFirst("souSuoBtnContent").transform);
//obj.GetComponentInChildren().text = allJingLuoSmall[i].XueWeiName_NoPinYin;
//Button btn = obj.GetComponent();
//allSouSuoBtn.Add(btn);
GameObject go = GameObject_Pool.Instance.TakeOutGame("souSuoBtn", transform.FindFirst("souSuoBtnContent").transform);
go.SetActive(true);
go.GetComponent().OnExitBtn();
go.GetComponentInChildren().text = allJingLuoSmall[i].XueWeiName_NoPinYin;
souSuoBtn_Que.Enqueue(go);
go.GetComponent().onClick.AddListener(() =>
{
GameObject[] arr = souSuoBtn_Que.ToArray();
for (int i = 0; i < arr.Length; i++)
{
arr[i].GetComponent().OnExitBtn();
}
go.GetComponent().OnEnterBtn();
uiManager.GetUI().EnterBigBtnCallBack(allJingLuoSmall[id].name);
uiManager.GetUI().EnterSmallBtnCallBack(allJingLuoSmall[id].XueWeiName_NoPinYin);
});
}
}
//LayoutRebuilder.ForceRebuildLayoutImmediate(transform.FindFirst("souSuoBtnContent").GetComponent());
}
public override void Show()
{
base.Show();
//InputSubmit("风");
#region 测试代码
//InputSubmit("俞");
//Game.Instance.IEnumeratorManager.Run(7.0f, () =>
//{
// InputSubmit("阴");
//});
//Game.Instance.IEnumeratorManager.Run(15.0f, () =>
//{
// InputSubmit("俞");
//});
//Game.Instance.IEnumeratorManager.Run(22.0f, () =>
//{
// InputSubmit("乳");
//});
//Game.Instance.IEnumeratorManager.Run(30.0f, () =>
//{
// InputSubmit("俞");
//});
//Game.Instance.IEnumeratorManager.Run(37.0f, () =>
//{
// InputSubmit("阳");
//});
//Game.Instance.IEnumeratorManager.Run(45.0f, () =>
//{
// InputSubmit("俞");
//});
//Game.Instance.IEnumeratorManager.Run(52.0f, () =>
//{
// InputSubmit("气");
//});
//Game.Instance.IEnumeratorManager.Run(60.0f, () =>
//{
// InputSubmit("俞");
//});
//Game.Instance.IEnumeratorManager.Run(66.0f, () =>
//{
// InputSubmit("三");
//});
//Game.Instance.IEnumeratorManager.Run(72.0f, () =>
//{
// InputSubmit("太");
//});
//Game.Instance.IEnumeratorManager.Run(78.0f, () =>
//{
// InputSubmit("渊");
//});
//Game.Instance.IEnumeratorManager.Run(85.0f, () =>
//{
// InputSubmit("俞");
//});
#endregion
}
private void InputValueChanged(string arg0)
{
transform.FindFirst("Placeholder").SetActive(false);
}
//void Update()
//{
// // 获取EventSystem实例(场景中需先添加EventSystem组件)
// EventSystem eventSystem = EventSystem.current;
// if (eventSystem == null)
// {
// souSuo_InputField.text = "场景中未找到EventSystem,请先添加!";
// return;
// }
// // 获取当前聚焦的游戏对象
// GameObject focusedObj = eventSystem.currentSelectedGameObject;
// if (focusedObj == null)
// {
// souSuo_InputField.text = "当前无UI元素聚焦";
// return;
// }
// // 判断聚焦对象的类型
// InputField inputField = focusedObj.GetComponent();
// if (inputField != null)
// {
// // 若聚焦对象是InputField,可进一步判断是否真的处于输入焦点
// if (inputField.isFocused)
// {
// //Debug.Log($"焦点:{inputField.name}");
// souSuo_InputField.text = $"焦点:{inputField.name}";
// }
// return;
// }
// Button button = focusedObj.GetComponent();
// if (button != null)
// {
// //Debug.Log($"焦点:{button.name}");
// souSuo_InputField.text = $"焦点:{button.name}";
// return;
// }
// // 其他可交互组件(如Slider、Toggle等)可类似判断
// Selectable selectable = focusedObj.GetComponent();
// if (selectable != null)
// {
// //Debug.Log($"焦点:{selectable.name}");
// souSuo_InputField.text = $"焦点:{selectable.name}";
// }
//}
}