void Start() { cont = ContentPanel.GetComponent <RectTransform>(); setButtonScale(); Player = new Player(); Player.AddPlayerToScoreBoard(); MenuGoldDisplay.text = Player.Gold.ToString(); RefreshDisplay(); }
public void UpdateMatchUI(bool isUpdateClass = false) {// 显示匹配结果 //StartCoroutine(updataMatchUI(isUpdateClass)); if (isUpdateClass) { for (int i = 0; i < ContentPanel.transform.childCount; ++i) { Destroy(ContentPanel.transform.GetChild(i).gameObject); } } ContentPanel.GetComponent <RectTransform>().sizeDelta = new Vector2(ContentPanel.GetComponent <RectTransform>().sizeDelta.x, 0); var classList = new List <MatchResult>(); var drugList = new List <MatchResult>(); var classExtractList = new List <MatchResult>(); var drugExtracList = new List <MatchResult>(); if (isUpdateClass) { foreach (var r in MainJsonData.MatchResultList) { drugList.Add(r); } } else { foreach (var r in MainJsonData.MatchResultList) { foreach (var i in r.MatchItemList) { if (i.MResultType == MatchResult.Type.Drug) { drugList.Add(r); } } } foreach (var r in MainJsonData.MatchResultList) { foreach (var i in r.MatchItemList) { if (i.MResultType == MatchResult.Type.Class) { classList.Add(r); } } } foreach (var r in MainJsonData.MatchResultList) { foreach (var i in r.MatchItemList) { if (i.MResultType == MatchResult.Type.Extract_Class) { classExtractList.Add(r); } } } foreach (var r in MainJsonData.MatchResultList) { foreach (var i in r.MatchItemList) { if (i.MResultType == MatchResult.Type.Extract_Drug) { drugExtracList.Add(r); } } } } if (classList.Count > 0) { var headerPanel = Instantiate(Resources.Load <GameObject>("headerPanel")); headerPanel.GetComponent <HeaderPanelController>().TitleText.text = "相关药类"; headerPanel.transform.SetParent(ContentPanel.transform); foreach (var r in classList) { var itemPanel = Instantiate(Resources.Load <GameObject>("itemPanel")); itemPanel.GetComponent <ItemPanelController>().TitleText.text = r.Name; itemPanel.GetComponent <ItemPanelController>().RawTitleString = r.Name; itemPanel.GetComponent <ItemPanelController>().TitleText.text = itemPanel.GetComponent <ItemPanelController>().TitleText.text.Replace(InputField.text, "<color=#108AE3FF>" + InputField.text + "</color>"); itemPanel.GetComponent <ItemPanelController>().DrugType = DrugItem.Type.Class; itemPanel.GetComponent <ItemPanelController>().ContentText.text = r.ContentText; itemPanel.transform.SetParent(ContentPanel.transform); } } if (drugList.Count > 0) { var headerPanel = Instantiate(Resources.Load <GameObject>("headerPanel")); headerPanel.GetComponent <HeaderPanelController>().TitleText.text = isUpdateClass ? "包含的药品" : "相关药品"; headerPanel.transform.SetParent(ContentPanel.transform); foreach (var r in drugList) { var itemPanel = Instantiate(Resources.Load <GameObject>("itemPanel")); itemPanel.GetComponent <ItemPanelController>().TitleText.text = r.Name; itemPanel.GetComponent <ItemPanelController>().RawTitleString = r.Name; itemPanel.GetComponent <ItemPanelController>().TitleText.text = itemPanel.GetComponent <ItemPanelController>().TitleText.text.Replace(InputField.text, "<color=#108AE3FF>" + InputField.text + "</color>"); itemPanel.GetComponent <ItemPanelController>().DrugType = DrugItem.Type.Drug; itemPanel.GetComponent <ItemPanelController>().ContentText.text = r.ContentText; itemPanel.transform.SetParent(ContentPanel.transform); } } int max = 70; if (classExtractList.Count > 0) { var headerPanel = Instantiate(Resources.Load <GameObject>("headerPanel")); headerPanel.GetComponent <HeaderPanelController>().TitleText.text = "药类信息快照"; headerPanel.transform.SetParent(ContentPanel.transform); foreach (var r in classExtractList) { var itemPanel = Instantiate(Resources.Load <GameObject>("itemPanel")); itemPanel.GetComponent <ItemPanelController>().TitleText.text = r.Name; itemPanel.GetComponent <ItemPanelController>().RawTitleString = r.Name; itemPanel.GetComponent <ItemPanelController>().DrugType = DrugItem.Type.Class; var contentText = itemPanel.GetComponent <ItemPanelController>().ContentText; contentText.text = r.ContentText; var index = contentText.text.IndexOf(InputField.text); if (index > max / 2) { if (contentText.text.Length > max) { var pre_len = index; if (pre_len > max / 2) { pre_len -= max / 2; } if (contentText.text.Length <= pre_len + max) { contentText.text = "..." + contentText.text.Substring(pre_len, contentText.text.Length - pre_len) + "..."; } else { contentText.text = "..." + contentText.text.Substring(pre_len, max) + "..."; } } } itemPanel.GetComponent <ItemPanelController>().ContentText.text = itemPanel.GetComponent <ItemPanelController>().ContentText.text.Replace(InputField.text, "<color=#108AE3FF>" + InputField.text + "</color>"); itemPanel.transform.SetParent(ContentPanel.transform); } } if (drugExtracList.Count > 0) { var headerPanel = Instantiate(Resources.Load <GameObject>("headerPanel")); headerPanel.GetComponent <HeaderPanelController>().TitleText.text = "药品信息快照"; headerPanel.transform.SetParent(ContentPanel.transform); foreach (var r in drugExtracList) { var itemPanel = Instantiate(Resources.Load <GameObject>("itemPanel")); itemPanel.GetComponent <ItemPanelController>().TitleText.text = r.Name; itemPanel.GetComponent <ItemPanelController>().RawTitleString = r.Name; itemPanel.GetComponent <ItemPanelController>().DrugType = DrugItem.Type.Drug; var contentText = itemPanel.GetComponent <ItemPanelController>().ContentText; contentText.text = r.ContentText; var index = contentText.text.IndexOf(InputField.text); if (index > max / 2) { if (contentText.text.Length > max) { var pre_len = index; if (pre_len > max / 2) { pre_len -= max / 2; } if (contentText.text.Length <= pre_len + max) { contentText.text = "..." + contentText.text.Substring(pre_len, contentText.text.Length - pre_len) + "..."; } else { contentText.text = "..." + contentText.text.Substring(pre_len, max) + "..."; } } } itemPanel.GetComponent <ItemPanelController>().ContentText.text = itemPanel.GetComponent <ItemPanelController>().ContentText.text.Replace(InputField.text, "<color=#108AE3FF>" + InputField.text + "</color>"); itemPanel.transform.SetParent(ContentPanel.transform); } } StartCoroutine(rePosScorllPanel()); if (ContentPanel.transform.childCount == 0) { HelloText.text = "无搜索结果!"; HelloText.gameObject.SetActive(true); } }