protected override void OnShow(object data) { base.OnShow(data); if (data is RunLightInfo) { RunLightInfo info = (RunLightInfo)data; if (info.pos == RunLightInfo.Pos.Bottom) { m_bottomQueue.Enqueue(info.msg); if (m_trans_Bottom.gameObject.activeSelf) { return; } if (m_bottomXmlText == null) { GameObject go = GameObject.Instantiate(m_lableObj) as GameObject; go.transform.parent = m_trans_Bottom; go.transform.transform.localScale = Vector3.one; m_bottomXmlText = go.GetComponent <UIXmlRichText>(); } m_trans_Bottom.gameObject.SetActive(true); AddBottomText(); } else { m_topQueue.Enqueue(info); if (m_currTopRunLightInfo == null) { AddTopTextFromQueue(); } } } }
void AddTopTextFromQueue() { if (m_topQueue.Count > 0) { m_currTopRunLightInfo = m_topQueue.Dequeue(); AddNewTopText(m_currTopRunLightInfo); } else { CheckToHide(); } }
void Update() { if (m_updateXmlText.Count <= 0) { m_trans_TOP.gameObject.SetActive(false); CheckToHide(); return; } List <UIXmlRichText> todelete = new List <UIXmlRichText>(); for (int i = 0; i < m_updateXmlText.Count; i++) { UIXmlRichText text = m_updateXmlText[i]; Vector3 pos = text.mtrans.localPosition; pos.x -= moveSpeed * Time.deltaTime; text.mtrans.localPosition = pos; if (-pos.x >= m_panelTop.width + text.m_layout.x + 5) { todelete.Add(text); } } if (todelete.Count > 0) { for (int i = 0; i < todelete.Count; i++) { m_updateXmlText.Remove(todelete[i]); GameObject.Destroy(todelete[i].gameObject); if (todelete[i].extObj != null) { RunLightInfo info = (RunLightInfo)todelete[i].extObj; if (--info.showTime > 0) { AddNewTopText(info); } else { m_currTopRunLightInfo = null; AddTopTextFromQueue(); } } } } todelete.Clear(); }
private void AddNewTopText(RunLightInfo info) { GameObject go = GameObject.Instantiate(m_lableObj) as GameObject; go.transform.parent = m_trans_root; go.transform.transform.localScale = Vector3.one; if (m_updateXmlText.Count > 0) { UIXmlRichText text = m_updateXmlText[m_updateXmlText.Count - 1]; //localPosition.x 为负数 text.m_layout.x m_trans_root的x点在右边300 float width = text.mtrans.localPosition.x + text.m_layout.x; if (width <= 0)// 小于0 则全部在panel中了。 { go.transform.transform.localPosition = Vector3.zero; } else { go.transform.transform.localPosition = new Vector3(text.mtrans.localPosition.x + text.m_layout.x + 15, 0, 0); } } else { go.transform.transform.localPosition = Vector3.zero; } UIXmlRichText xmltext = go.GetComponent <UIXmlRichText>(); xmltext.extObj = info; xmltext.UrlClicked += OnClickUrl; xmltext.AddXml(info.msg); xmltext.host.width = Mathf.CeilToInt(xmltext.m_layout.x); m_updateXmlText.Add(xmltext); if (m_trans_TOP.gameObject.activeSelf == false) { m_trans_TOP.gameObject.SetActive(true); } }