void initMessage(MainData.MessageBody message) { GameObject pref_obj = message.type == 1 ? (message.sendId == MainData.instance.user.id ? pref_message_pic_detail_right : pref_message_pic_detail_left) : (message.sendId == MainData.instance.user.id ? pref_message_word_detail_right : pref_message_word_detail_left); GameObject message_obj = NGUITools.AddChild(messageDetailContainer.gameObject, pref_obj); message_obj.name = "message-" + message.id; Transform icon_tran = message_obj.transform.FindChild("icon"); icon_tran.GetComponent <UISprite>().spriteName = message.sendFace; Transform time_tran = message_obj.transform.FindChild("time"); time_tran.gameObject.SetActive(message.showTime == 1); if (message.showTime == 1) { UILabel time_label = time_tran.GetComponent <UILabel>(); System.DateTime dateTime = System.DateTime.Parse(message.time); string showStr = null; //int days = System.DateTime.DaysInMonth(dateTime.Year, dateTime.Month); if (System.DateTime.Now.Year == dateTime.Year && System.DateTime.Now.Month == dateTime.Month && System.DateTime.Now.Day == dateTime.Day) {//同一天 showStr = "今天" + MyUtilTools.numToString(dateTime.Hour) + ":" + MyUtilTools.numToString(dateTime.Minute); } else { showStr = dateTime.Year + "/" + MyUtilTools.numToString(dateTime.Month) + "/" + MyUtilTools.numToString(dateTime.Day) + " " + MyUtilTools.numToString(dateTime.Hour) + ":" + MyUtilTools.numToString(dateTime.Minute); } time_label.text = showStr; messageStarty -= 70; } if (message.type == 0) {//文字类型 Transform content_trans = message_obj.transform.FindChild("content"); float cx = content_trans.localPosition.x; Transform rect_tran = content_trans.FindChild("rect"); UISprite rect_sprite = rect_tran.GetComponent <UISprite>(); UILabel content = rect_tran.FindChild("value").GetComponent <UILabel>(); content.width = 570; content.text = message.content; int row = MyUtilTools.computeRow(content); int height = row * 64; if (row == 1) { int width = (int)MyUtilTools.computeLen(content) + content.fontSize; rect_sprite.width = Mathf.Min(600, width); content.width = rect_sprite.width - content.fontSize; } rect_sprite.height = height; content.height = row * (content.fontSize + content.spacingX); float offx = rect_sprite.width / 2 + 14; int opration = cx > 0 ? -1 : 1; rect_tran.localPosition = new Vector3(opration * offx, content.fontSize - height / 2 - 5, 0); message_obj.transform.localPosition = new Vector3(0, messageStarty, 0); messageStarty -= height + 10; } else //图片 { UITexture pic_texture = message_obj.transform.FindChild("content").FindChild("rect").FindChild("value").GetComponent <UITexture>(); JustRun.Instance.loadPic(message.content, pic_texture); message_obj.transform.localPosition = new Vector3(0, messageStarty, 0); messageStarty -= 590; } }