176 lines
4.5 KiB
C#
176 lines
4.5 KiB
C#
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SearchName1 : MonoBehaviour
|
|
{
|
|
public GameObject TZ;
|
|
public GameObject scrollView;
|
|
public Transform scrollViewContent;
|
|
public TMP_InputField inputField;
|
|
public TextMeshProUGUI searchText;
|
|
/// <summary>
|
|
/// 搜索文本框预制体
|
|
/// </summary>
|
|
public Button prefabsText;
|
|
/// <summary>
|
|
/// 搜索按钮
|
|
/// </summary>
|
|
public Button serarchBtn;
|
|
public DragController dragController;
|
|
[Header("加入需要搜索的设备名称")]
|
|
public List<GameObject> objs = new List<GameObject>();
|
|
public List<GameObject> SearchObjects = new List<GameObject>();
|
|
|
|
public SearchData searchData;
|
|
|
|
public List<DeviceData> devices = new List<DeviceData>();
|
|
|
|
public float initialHeight;
|
|
public RectTransform rectTransform;
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
rectTransform = scrollView.GetComponent<RectTransform>();
|
|
initialHeight = rectTransform.sizeDelta.y;
|
|
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, 0);
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
//Debug.Log("版本号 1.1.1");
|
|
//scrollView.SetActive(false);
|
|
InputFieldEvent();
|
|
dragController.gameObject.SetActive(false);
|
|
OnClickSearchBtn();
|
|
//Debug.Log("版本号 1.1.1");
|
|
}
|
|
|
|
void InputFieldEvent()
|
|
{
|
|
inputField.onValueChanged.AddListener(a =>
|
|
{
|
|
if (a != "")
|
|
{
|
|
//scrollView.SetActive(true);
|
|
Serach(a);
|
|
}
|
|
//else scrollView.SetActive(false);
|
|
|
|
});
|
|
}
|
|
|
|
void Serach(string strName)
|
|
{
|
|
SearchObjects.Clear();
|
|
devices.Clear();
|
|
devices = searchData.FuzzySearch(strName);
|
|
for (int i = 0; i < scrollViewContent.childCount; i++)
|
|
{
|
|
Destroy(scrollViewContent.GetChild(i).gameObject);
|
|
}
|
|
|
|
|
|
for (int i = 0; i < devices.Count; i++)
|
|
{
|
|
for (int j = 0; j < objs.Count; j++)
|
|
{
|
|
if (devices[i].ID.Equals(objs[j].name))
|
|
{
|
|
SearchObjects.Add(objs[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < devices.Count; i++)
|
|
{
|
|
int index = i;
|
|
Button tmp = Instantiate(prefabsText, scrollViewContent, false);
|
|
TextMeshProUGUI text = tmp.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
|
text.text = devices[index].ID + devices[index].deviceType + devices[index].deviceNum;
|
|
tmp.onClick.AddListener(() =>
|
|
{
|
|
dragController.oriObjectPrefab = SearchObjects[index].GetComponent<DragTest1>();
|
|
dragController.gameObject.SetActive(true);
|
|
dragController._icon.sprite = SearchObjects[index].GetComponent<DragTest1>().selfIcon;
|
|
dragController._icon.SetNativeSize();
|
|
});
|
|
}
|
|
}
|
|
//TODO:有问题
|
|
void OnClickSearchBtn()
|
|
{
|
|
serarchBtn.onClick.AddListener(() =>
|
|
{
|
|
PatternChoose.Inst.DetectCharacters((x) =>
|
|
{
|
|
if (x)
|
|
show_menu();
|
|
else
|
|
return;
|
|
}, inputField);
|
|
|
|
return;
|
|
if (searchText.text != "")
|
|
{
|
|
scrollView.SetActive(true);
|
|
Serach(searchText.text.Trim());
|
|
}
|
|
});
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏搜索菜单
|
|
/// </summary>
|
|
public void hide_menu()
|
|
{
|
|
//if (rectTransform.sizeDelta.y >= 0)
|
|
{
|
|
DOTween.Kill(rectTransform, false);
|
|
|
|
TZ.SetActive(false);
|
|
|
|
float targetHeight = 0;
|
|
float duration = 1f;
|
|
|
|
rectTransform.DOSizeDelta(new Vector2(rectTransform.sizeDelta.x, targetHeight), duration).OnComplete(() =>
|
|
{
|
|
scrollView.SetActive(false);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示搜索菜单
|
|
/// </summary>
|
|
public void show_menu()
|
|
{
|
|
//if (rectTransform.sizeDelta.y != initialHeight)
|
|
{
|
|
DOTween.Kill(rectTransform, false);
|
|
|
|
scrollView.SetActive(true);
|
|
|
|
float targetHeight = initialHeight;
|
|
float duration = 1f;
|
|
|
|
rectTransform.DOSizeDelta(new Vector2(rectTransform.sizeDelta.x, targetHeight), duration).OnComplete(() =>
|
|
{
|
|
TZ.SetActive(true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|