using DG.Tweening;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
/// 搜索框
///
public class SearchName : MonoBehaviour
{
public GameObject scrollView;
public Transform scrollViewContent;
public TMP_InputField inputField;
public GameObject prefabsText;
///
/// 搜索按钮
///
public Button serarchBtn;
[Header("加入需要搜索的设备名称")]
public List objs = new List();
public List objs_str = new List();
//展示的名字
private List SearchObjects = new List();
public List button_objects = new List();
public SearchType searchType;
///
/// 线缆组中不包含线缆的线缆组名
///
public Dictionary dic_notContain = new Dictionary();
public float initialHeight;
public RectTransform rectTransform;
public GameObject biaoTou;
public Image bg;
private void Awake()
{
rectTransform = scrollView.GetComponent();
initialHeight = rectTransform.sizeDelta.y;
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, 0);
gameObject.SetActive(false);
biaoTou.SetActive(false);
}
void Start()
{
//searchType = SearchType.None;
//scrollView.SetActive(false);
InputFieldEvent();
OnClickSearchBtn();
}
private void OnClickSearchBtn()
{
serarchBtn.onClick.AddListener(() =>
{
//PatternChoose.Inst.DetectCharacters((x) =>
//{
// if (x)
// {
// PatternChoose.Inst.sb_ck_page.SetActive(false);
// show_menu();
// }
// else
// return;
//}, inputField);
if (searchType == SearchType.None)
return;
if (!string.IsNullOrEmpty(inputField.text))
{
Serach(inputField.text);
}
else
{
Serach(null);
}
PatternChoose.Inst.sb_ck_page.SetActive(false);
show_menu();
});
}
void InputFieldEvent()
{
inputField.onValueChanged.AddListener(a =>
{
if (searchType == SearchType.None)
return;
if (a != "")
{
Serach(a);
}
else
{
Serach(null);
}
});
}
public void Serach(string strName = null)
{
if (string.IsNullOrEmpty(strName))
{
for (int i = 0; i < scrollViewContent.childCount; i++)
{
scrollViewContent.GetChild(i).gameObject.SetActive(true);
}
return;
}
//SearchObjects.Clear();
for (int i = 0; i < scrollViewContent.childCount; i++)
{
//Destroy(scrollViewContent.GetChild(i).gameObject);
scrollViewContent.GetChild(i).gameObject.SetActive(false);
}
int index = 0;
foreach (var go in objs_str)
{
if (!string.IsNullOrEmpty(strName))
{
if (go.Contains(strName))
{
//SearchObjects.Add(go);
scrollViewContent.GetChild(index).gameObject.SetActive(true);
}
}
//else
//{
// SearchObjects.Add(go);
//}
index++;
}
//if (string.IsNullOrEmpty(strName))
//{
// for (int i = 0; i < scrollViewContent.childCount; i++)
// {
// //Destroy(scrollViewContent.GetChild(i).gameObject);
// scrollViewContent.GetChild(i).gameObject.SetActive(true);
// }
//}
for (int i = 0; i < SearchObjects.Count; i++)
{
//GameObject tmp = Instantiate(prefabsText, scrollViewContent, false);
//TextMeshProUGUI text = tmp.GetComponentInChildren();
TextMeshProUGUI text = scrollViewContent.GetChild(i).GetComponentInChildren();
text.text = SearchObjects[i];
}
addonClick();
}
///
/// 机柜列表
///
public void LoadCabinet(SearchType type)
{
inputField.text = string.Empty;
searchType = type;
if (!gameObject.activeSelf)
gameObject.SetActive(true);
init();
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
objs.Add(GameManager.Inst.Cabinets_go[i]);
string s = GameManager.Inst.Cabinets_go[i].GetComponent().deviceList.deviceName;
objs_str.Add(s);
SearchObjects.Add(s);
}
for (int i = 0; i < SearchObjects.Count; i++)
{
GameObject tmp = Instantiate(prefabsText, scrollViewContent, false);
TextMeshProUGUI text = tmp.GetComponentInChildren();
text.text = SearchObjects[i];
button_objects.Add(tmp);
}
addonClick();
}
public int _co = -1;
public RoomInspection roomInspection = new RoomInspection();
///
/// 添加列表点击方法
///
public void addonClick()
{
int childCount = SearchObjects.Count;
for (int i = 0; i < childCount; i++)
{
var co = i;
int eventCount = scrollViewContent.GetChild(i).GetComponent().onClick.GetPersistentEventCount();
if (eventCount > 0)
scrollViewContent.GetChild(i).GetComponent().onClick.RemoveAllListeners();
//FindGo(objs, i, (go) =>
//{
//var jigui = GameManager.Inst.FindParent(scrollViewContent.GetChild(i).gameObject, GameManager.Inst.IsDesiredParent);
switch (searchType)
{
case SearchType.None:
break;
case SearchType.机柜:
{
scrollViewContent.GetChild(co).GetComponent().onClick.AddListener(() =>
{
//Debug.Log(co);
_co = co;
objs[co].GetComponent().Change_hide(objs[co], true, true);
//if (jigui)
//{
// jigui.GetComponent().Zoomin();
//}
});
}
break;
case SearchType.线缆组_展示:
{
scrollViewContent.GetChild(co).GetComponent().onClick.AddListener(() =>
{
//List t = new List();
//TransparentGlowManage.Inst.transparencyALL(t.ToArray());
//CreateLine createLine = PatternChoose.Inst.huaXian;
//var lines = createLine.xianLan.Find(objs[i].GetComponent().portList.remark).GetComponent().lines;
//var A = GameManager.Inst.FindParent(objs[co].gameObject, GameManager.Inst.IsDesiredParent);
////var B = GameManager.Inst.FindParent(lines[1].gameObject, GameManager.Inst.IsDesiredParent);
//var B_ = Array.Find(GameManager.Inst.TmsPorts_go.ToArray(), (item) =>
// {
// try
// {
// return (item.GetComponent().portList.conPort == objs[co].GetComponent().portList.port &&
// item.GetComponent().portList.remark == objs[co].GetComponent().portList.remark);
// }
// catch
// {
// return false;
// }
// });
//var B = GameManager.Inst.FindParent(B_, GameManager.Inst.IsDesiredParent);
//List transparentGlows = new List();
//transparentGlows.Add(A.GetComponent());
//transparentGlows.Add(B.GetComponent());
#region 没封装
//List transparentGlows = new List();
//var s = PatternChoose.Inst.xianlan.gameObject.GetComponentsInChildren(true);
//Array.ForEach(s, (item) =>
//{
// if (item.cableGroupName == objs_str[co])
// {
// if (ExtendedFlycam.Room.配电室 != ExtendedFlycam.Inst.room)
// {
// for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
// {
// GameManager.Inst.Cabinets_go[i].GetComponent().F1();
// }
// ;
// GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
// GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
// transparentGlows.Add(go1.GetComponent());
// transparentGlows.Add(go2.GetComponent());
// item.gameObject.SetActive(true);
// }
// else
// {
// PatternChoose.Inst.quanJing_fuc();
// for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
// {
// GameManager.Inst.Cabinets_go[i].GetComponent().F1();
// }
// GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
// GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
// transparentGlows.Add(go1.GetComponent());
// transparentGlows.Add(go2.GetComponent());
// item.gameObject.SetActive(true);
// }
// }
// else if (dic_notContain.ContainsKey(objs_str[co]))
// {
// //弹出提示——该线缆组不包含线缆
// SecondConfirmPanel.DeleteConform(null, "该线缆组不包含线缆");
// //关闭多余线缆机柜
// item.gameObject.SetActive(false);
// }
// else
// {
// item.gameObject.SetActive(false);
// }
//});
//for (int i = 0; i < PatternChoose.Inst.xianlan.transform.childCount; i++)
//{
// if (PatternChoose.Inst.xianlan.transform.GetChild(i).name == objs_str[co])
// {
// var _CAB = PatternChoose.Inst.xianlan.transform.GetChild(i).GetComponentsInChildren(true);
// foreach (var item in _CAB)
// {
// GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
// GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
// transparentGlows.Add(go1.GetComponent());
// transparentGlows.Add(go2.GetComponent());
// }
// PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject.SetActive(true);
// }
// else if (dic_notContain.ContainsKey(objs_str[co]))
// {
// //弹出提示——该线缆组不包含线缆
// SecondConfirmPanel.DeleteConform(null, "该线缆组不包含线缆");
// //关闭多余线缆机柜
// PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject.SetActive(false);
// }
// else
// {
// PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject.SetActive(false);
// }
//}
//TransparentGlowManage.Inst.renewALL(transparentGlows.ToArray());
#endregion
_co = co;
showXianLan(_co);
});
}
break;
default:
break;
}
//});
}
}
///
/// 展示线缆组
///
///
public void showXianLan(int co)
{
bool isFind = false;
List transparentGlows = new List();
var s = PatternChoose.Inst.xianlan.gameObject.GetComponentsInChildren(true);
Array.ForEach(s, (item) =>
{
if (item.cableGroupName == objs_str[co])
{
isFind = true;
if (ExtendedFlycam.Room.配电室 != ExtendedFlycam.Inst.room)
{
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
GameManager.Inst.Cabinets_go[i].GetComponent().F1();
}
;
GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
transparentGlows.Add(go1.GetComponent());
transparentGlows.Add(go2.GetComponent());
item.gameObject.SetActive(true);
item.transform.parent.gameObject.SetActive(true);
}
else
{
PatternChoose.Inst.quanJing_fuc();
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
GameManager.Inst.Cabinets_go[i].GetComponent().F1();
}
GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
transparentGlows.Add(go1.GetComponent());
transparentGlows.Add(go2.GetComponent());
item.gameObject.SetActive(true);
item.transform.parent.gameObject.SetActive(true);
}
}
//else if (dic_notContain.ContainsKey(objs_str[co]))
//{
// //弹出提示——该线缆组不包含线缆
// SecondConfirmPanel.DeleteConform(null, "该线缆组不包含线缆");
// //关闭多余线缆机柜
// item.gameObject.SetActive(false);
//}
else
{
item.gameObject.SetActive(false);
}
});
if (!isFind)
{
//弹出提示——该线缆组不包含线缆
SecondConfirmPanel.DeleteConform(null, "该线缆组不包含线缆");
//关闭多余线缆机柜
//item.gameObject.SetActive(false);
}
//for (int i = 0; i < PatternChoose.Inst.xianlan.transform.childCount; i++)
//{
// if (PatternChoose.Inst.xianlan.transform.GetChild(i).name == objs_str[co])
// {
// var _CAB = PatternChoose.Inst.xianlan.transform.GetChild(i).GetComponentsInChildren(true);
// foreach (var item in _CAB)
// {
// GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
// GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
// transparentGlows.Add(go1.GetComponent());
// transparentGlows.Add(go2.GetComponent());
// }
// PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject.SetActive(true);
// }
// else if (dic_notContain.ContainsKey(objs_str[co]))
// {
// //弹出提示——该线缆组不包含线缆
// SecondConfirmPanel.DeleteConform(null, "该线缆组不包含线缆");
// //关闭多余线缆机柜
// PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject.SetActive(false);
// }
// else
// {
// PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject.SetActive(false);
// }
//}
TransparentGlowManage.Inst.renewALL(transparentGlows.ToArray());
}
///
/// 展示线缆组
///
public void showXianLan(string co)
{
bool isFind = false;
List transparentGlows = new List();
var s = PatternChoose.Inst.xianlan.gameObject.GetComponentsInChildren(true);
Array.ForEach(s, (item) =>
{
if (item.cableName == co)
{
isFind = true;
if (ExtendedFlycam.Room.配电室 != ExtendedFlycam.Inst.room)
{
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
GameManager.Inst.Cabinets_go[i].GetComponent().F1();
}
;
GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
transparentGlows.Add(go1.GetComponent());
transparentGlows.Add(go2.GetComponent());
item.gameObject.SetActive(true);
item.transform.parent.gameObject.SetActive(true);
}
else
{
PatternChoose.Inst.quanJing_fuc();
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
GameManager.Inst.Cabinets_go[i].GetComponent().F1();
}
GameObject go1 = GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
GameObject go2 = GameManager.Inst.FindParent(item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
transparentGlows.Add(go1.GetComponent());
transparentGlows.Add(go2.GetComponent());
item.gameObject.SetActive(true);
item.transform.parent.gameObject.SetActive(true);
}
}
else
{
item.gameObject.SetActive(false);
}
});
if (!isFind)
{
//弹出提示——该线缆组不包含线缆
SecondConfirmPanel.DeleteConform(null, "该线缆组不包含线缆");
//关闭多余线缆机柜
//item.gameObject.SetActive(false);
}
TransparentGlowManage.Inst.renewALL(transparentGlows.ToArray());
}
Predicate findCabinet = (Transform go) =>
{
//端口-设备 go.parent
//端口-板卡-设备 go.parent.parent
var p = go.parent;
if (p.parent.parent.parent.parent.GetComponent())
{
if (p.parent.parent.parent.parent.GetComponent().deviceList.type == "1")
{
return true;
}
else if (p.parent.parent.parent.GetComponent())
{
if (p.parent.parent.parent.GetComponent().deviceList.type == "1")
{
return true;
}
}
}
else if (p.parent.parent.parent.GetComponent())
{
if (p.parent.parent.parent.GetComponent().deviceList.type == "1")
{
return true;
}
}
return false;
};
private bool Isitive(Transform obj)
{
throw new NotImplementedException();
}
// 寻找机柜
void FindGo(List objs, int index, Action callback)
{
GameObject go = null;
try
{
go = objs[index].transform.Find(objs[index].name).gameObject;
}
catch
{
go = objs[index];
}
callback?.Invoke(go);
}
public void LoadXianLan(SearchType type)
{
inputField.text = string.Empty;
searchType = type;
if (!gameObject.activeSelf)
gameObject.SetActive(true);
init();
Dictionary dic = new Dictionary();
CreateLine createLine = PatternChoose.Inst.huaXian;
for (int i = 0; i < createLine.list7.Count; i++)
{
if (i != 0 && i % 2 != 0)
{
objs.Add(createLine.list7[i].gameObject);
string s = createLine.list7[i].GetComponent().portList.cableGroupName;
if (string.IsNullOrEmpty(s) || dic.ContainsKey(s))
continue;
dic.Add(s, "");
objs_str.Add(s);
SearchObjects.Add(s);
}
}
dic_notContain.Clear();
foreach (var item in LineQuery.Inst.keyValues.Keys)
{
if (!dic.ContainsKey(item))
{
objs_str.Add(item);
SearchObjects.Add(item);
dic_notContain.Add(item, "");
}
}
for (int i = 0; i < SearchObjects.Count; i++)
{
GameObject tmp = Instantiate(prefabsText, scrollViewContent, false);
TextMeshProUGUI text = tmp.GetComponentInChildren();
text.text = SearchObjects[i];
}
var cabinets = CabinetUIManager.Instance.transform.Find("机柜");
TransparentGlowManage.Inst.renewALL(cabinets.GetComponentsInChildren(true));
addonClick();
}
void init()
{
var count = scrollViewContent.childCount;
for (int i = count - 1; i >= 0; i--)
{
DestroyImmediate(scrollViewContent.GetChild(i).gameObject);
}
objs.Clear();
objs_str.Clear();
SearchObjects.Clear();
button_objects.Clear();
inputField.transform.Find("Text Area/Placeholder").GetComponent().text = "请输入要搜索的" + searchType.ToString().Split('_')[0];
scrollView.transform.Find("表头/Text (TMP)").GetComponent().text = searchType.ToString().Split('_')[0] + "名称";
}
private void Update()
{
if (!EventSystem.current.IsPointerOverGameObject() && !inputField.isFocused && biaoTou.activeSelf)
{
hide_menu();
}
bg.raycastTarget = scrollView.activeSelf;
}
///
/// 隐藏搜索菜单
///
public void hide_menu()
{
{
DOTween.Kill(rectTransform, false);
biaoTou.SetActive(false);
float targetHeight = 0;
float duration = 1f;
rectTransform.DOSizeDelta(new Vector2(rectTransform.sizeDelta.x, targetHeight), duration).OnComplete(() =>
{
scrollView.SetActive(false);
});
}
}
///
/// 显示搜索菜单
///
public void show_menu()
{
{
DOTween.Kill(rectTransform, false);
scrollView.SetActive(true);
biaoTou.SetActive(true);
float targetHeight = initialHeight;
float duration = 1f;
rectTransform.DOSizeDelta(new Vector2(rectTransform.sizeDelta.x, targetHeight), duration);
}
}
///
/// 搜索框类型
///
public enum SearchType
{
None,
机柜,
线缆组_展示
}
}