示例#1
0
        /// <summary>
        /// 添加文字记录
        /// </summary>
        /// <param name="blt">文本记录块</param>
        public void AddHistory(BacklogText blt)
        {
            Queue <BacklogText> history = tempData.backLog;

            if (history.Count > 100)
            {
                history.Dequeue();
            }
            history.Enqueue(blt);
        }
        /// <summary>
        /// 加入文字履历
        /// </summary>
        /// <param name="bt"></param>
        public void AddToTable(BacklogText bt)
        {
            //获取系统数据储存的数目
            Queue <BacklogText> history = DataManager.GetInstance().GetHistory();

            if (history.Count == 0)
            {
                ClearHistoryObject();
            }
            //添加U最新一行界面
            GameObject go = Resources.Load("Prefab/Backlog") as GameObject;

            go = Instantiate(go);
            go.transform.SetParent(table.transform);
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = Vector3.zero;

            //table.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();

            float w = table.GetComponent <RectTransform>().sizeDelta.x;

            table.GetComponent <RectTransform>().sizeDelta = new Vector2(w, table.transform.childCount * 200);

            //绑定数据
            go.transform.Find("Name_Label").GetComponent <Text>().text    = bt.charaName;
            go.transform.Find("Content_Label").GetComponent <Text>().text = bt.mainContent;
            if (!string.IsNullOrEmpty(bt.avatarFile))
            {
                GameObject ai = go.transform.Find("Avatar_Image").gameObject;
                ai.SetActive(true);
                ai.GetComponent <Image>().sprite = Resources.Load(bt.avatarFile) as Sprite;
            }
            if (!string.IsNullOrEmpty(bt.voicePath))
            {
                GameObject vb = go.transform.Find("Voice_Button").gameObject;
                vb.SetActive(true);
                vb.GetComponent <BacklogVoiceButton>().path = bt.voicePath;
            }
            if (table.transform.childCount > 100)
            {
                //删除第一个
                Destroy(table.transform.GetChild(0).gameObject);
            }
            DataManager.GetInstance().AddHistory(bt);
        }