public static Color GetColorByLinkType(RichContent richcontent) { LinkType linkType = richcontent.linktype; Color color = Color.white; switch (linkType) { case LinkType.REQUEST: break; case LinkType.NAME: break; case LinkType.PROP: break; case LinkType.AUDIO: break; } return(color); }
/// <summary> /// 添加内容 /// </summary> /// <param name="content"></param> private void AddContent(RichContent content) { RichEnum richenum = content.richtype; switch (richenum) { case RichEnum.TEXT: AddTextContent(content); break; case RichEnum.ICON: AddIconContent(content); break; case RichEnum.HREF: AddHrefContent(content); break; case RichEnum.BTN: AddBtnContent(content); break; case RichEnum.VOICE: AddVoiceContent(content); break; } mreaderIndex++; if (mreaderIndex < mRichData.richContentList.Count) { AddContent(mRichData.richContentList[mreaderIndex]); } }
/// <summary> /// 添加语音 /// </summary> private void AddVoiceContent(RichContent content) { GameObject icongo = NGUITools.AddChild(mWidget.gameObject, mIcon.gameObject); icongo.SetActive(true); UISprite sprite = icongo.GetComponent <UISprite>(); sprite.spriteName = content.content; sprite.MakePixelPerfect(); int width = sprite.width; int height = sprite.height; icongo.name = "voiceobj"; BoxCollider boxcollider = UtilTools.SafeAddComponent <BoxCollider>(icongo); boxcollider.size = new Vector3(sprite.width, sprite.height, 0); boxcollider.center = new Vector3(sprite.width * 0.5f, -sprite.height * 0.5f, 0); //UISpriteAnimation anim = UtilTools.SafeAddComponent<UISpriteAnimation>(icongo); //anim.namePrefix = content.anim_namePrefix; //anim.loop = true; //anim.framesPerSecond = 30; UILinkText linkText = UtilTools.SafeAddComponent <UILinkText>(icongo); linkText.args = content.args; linkText.linktype = content.linktype; linkText.voiceObject = icongo; voice_args = content.args; UIDragScrollView dragScrollview = UtilTools.SafeAddComponent <UIDragScrollView>(icongo); float dy = height - cellHeight; float surplus = maxWidth - mPositionX; //一行剩余空间 if (surplus >= width) { icongo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); if (dy > 0) { m_dy = m_dy > dy ? m_dy : dy; } } else { mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = dy > 0 ? dy : 0; //iswrap = true; icongo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); } float iconwidth = width; mPositionX += iconwidth; SetCurrWidth(mPositionX); }
/// <summary> /// Adds a message that replaces the <see cref="Message.Body" /> for channels that support /// rich content (all channels except <see cref="Channel.SMS" />, <see cref="Channel.Voice" /> /// and <see cref="Channel.Push" /> at this moment) /// </summary> /// <param name="richMessage"></param> /// <returns></returns> public MessageBuilder WithRichMessage(IRichMessage richMessage) { if (this._richContent == null) { this._richContent = new RichContent(); } this._richContent.AddConversionPart(richMessage); return(this); }
/// <summary> /// Adds suggestions to the message. It is dependent on the channel that is used which /// suggestions are supported. /// </summary> /// <param name="suggestions"></param> /// <returns></returns> public MessageBuilder WithSuggestions(params SuggestionBase[] suggestions) { if (this._richContent == null) { this._richContent = new RichContent(); } this._richContent.Suggestions = suggestions; return(this); }
/// <summary> /// Adds a ApplePay request . /// </summary> /// <param name="appePayRequest"></param> /// <returns></returns> public MessageBuilder WithApplePay(ApplePayRequest applePayRequest) { if (this._richContent == null) { this._richContent = new RichContent(); } this._richContent.AddConversationPart(applePayRequest); return(this); }
/// <summary> /// Adds a WhatsApp template message that replaces the <see cref="Message.Body" /> for WhatsApp /// please note that you need to have approved wa templates. /// </summary> /// <param name="template"></param> /// <returns></returns> public MessageBuilder WithTemplate(TemplateMessage template) { if (this._richContent == null) { this._richContent = new RichContent(); } this._richContent.AddConversationPart(template); return(this); }
/// <summary> /// Adds a WhatsApp interactive message that replaces the <see cref="Message.Body" /> for WhatsApp /// </summary> /// <param name="interactive"></param> /// <returns></returns> public MessageBuilder WithInteractive(WhatsAppInteractiveMessage interactive) { if (this._richContent == null) { this._richContent = new RichContent(); } this._richContent.AddConversationPart(interactive); return(this); }
public static RichContent CreateRichContent(string content, RichEnum richEnum = RichEnum.TEXT, LinkType linkType = LinkType.NONE, params object[] args) { RichContent rc = new RichContent(); rc.content = content; rc.richtype = richEnum; rc.linktype = linkType; rc.args = args; return(rc); }
/// <summary> /// 添加纯文本 /// </summary> private void AddTextContent(RichContent content) { string value = content.content; //if (content.linktype != LinkType.NAME && mRichData.ownerType != OwnerType.SYSTEM) // value = XMLManager.filterLoader.FromatDirtyLanguage(value); if (string.IsNullOrEmpty(value)) { return; } ParseWrapText(value, content); }
/// <summary> /// 添加超链接文本 /// </summary> private void AddHrefContent(RichContent content) { string value = content.content; //if(mRichData.ownerType != OwnerType.SYSTEM) // value = XMLManager.filterLoader.FromatDirtyLanguage(value); if (string.IsNullOrEmpty(value)) { return; } if (content.linktype == LinkType.NAME) { value = "" + value + ":"; } else { value = "[" + content.content + "]"; } ParseWrapHref(value, content); }
/// <summary> /// 添加图片 /// </summary> private void AddIconContent(RichContent content) { GameObject icongo = NGUITools.AddChild(mWidget.gameObject, mIcon.gameObject); icongo.SetActive(true); UISprite sprite = icongo.GetComponent <UISprite>(); sprite.spriteName = content.content; sprite.MakePixelPerfect(); int width = sprite.width; int height = sprite.height; float dy = height - cellHeight; float surplus = maxWidth - mPositionX; //一行剩余空间 if (surplus >= width) { icongo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); if (dy > 0) { m_dy = m_dy > dy ? m_dy : dy; } } else { mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = dy > 0 ? dy : 0; icongo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); //iswrap = true; } float iconwidth = width; mPositionX += iconwidth; SetCurrWidth(mPositionX); }
private void ParseWrapHref(string value, RichContent content) { mLabel.gameObject.SetActive(true); value = value.Replace("\n", ""); NGUIText.fontSize = mLabel.fontSize; NGUIText.finalSize = mLabel.fontSize; NGUIText.dynamicFont = mLabel.trueTypeFont; NGUIText.rectWidth = (int)(maxWidth - mPositionX); NGUIText.maxLines = 10000; NGUIText.rectHeight = 10000; string sbstr = ""; NGUIText.WrapText(value, out sbstr); if (string.IsNullOrEmpty(sbstr)) { SetCurrWidth(mPositionX); mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = 0; //iswrap = true; ParseWrapHref(value, content); return; } GameObject labelgo = NGUITools.AddChild(mWidget.gameObject, mLabel.gameObject); labelgo.SetActive(true); UILabel label = labelgo.GetComponent <UILabel>(); labelgo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); UIDragScrollView dragScrollview = UtilTools.SafeAddComponent <UIDragScrollView>(labelgo); UIButtonColor btnColor = UtilTools.SafeAddComponent <UIButtonColor>(labelgo); btnColor.duration = 0.1f; btnColor.defaultColor = UtilTools.GetColorByLinkType(content); UILinkText linkText = UtilTools.SafeAddComponent <UILinkText>(labelgo); linkText.args = content.args; linkText.linktype = content.linktype; if (content.linktype == LinkType.AUDIO) { label.color = textColor; } else { label.color = UtilTools.GetColorByLinkType(content); } int index = sbstr.IndexOf("\n"); string str = ""; if (index > -1) { str = sbstr.Substring(0, index); label.text = str; BoxCollider boxcollider = UtilTools.SafeAddComponent <BoxCollider>(labelgo); boxcollider.size = new Vector3(label.width, label.height, 0); boxcollider.center = new Vector3(label.width * 0.5f, -label.height * 0.5f, 0); SetCurrWidth(mPositionX + label.width); mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = 0; //iswrap = true; sbstr = sbstr.Remove(0, str.Length); ParseWrapHref(sbstr, content); } else { str = sbstr; label.text = str; BoxCollider boxcollider = UtilTools.SafeAddComponent <BoxCollider>(labelgo); boxcollider.size = new Vector3(label.width, label.height, 0); boxcollider.center = new Vector3(label.width * 0.5f, -label.height * 0.5f, 0); int lastLabelwidth = label.width; mPositionX += lastLabelwidth; SetCurrWidth(mPositionX); } }
private void ParseWrapText(string value, RichContent richcontent) { mLabel.gameObject.SetActive(true); value = value.Replace("\n", ""); NGUIText.fontSize = mLabel.fontSize; NGUIText.finalSize = mLabel.fontSize; NGUIText.dynamicFont = mLabel.trueTypeFont; NGUIText.rectWidth = (int)(maxWidth - mPositionX); NGUIText.maxLines = 10000; NGUIText.rectHeight = 10000; string sbstr = ""; NGUIText.WrapText(value, out sbstr); if (string.IsNullOrEmpty(sbstr)) { SetCurrWidth(mPositionX); mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = 0; //iswrap = true; ParseWrapText(value, richcontent); return; } GameObject labelgo = NGUITools.AddChild(mWidget.gameObject, mLabel.gameObject); labelgo.SetActive(true); UILabel label = labelgo.GetComponent <UILabel>(); labelgo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); label.color = textColor; int index = sbstr.IndexOf("\n"); string str = ""; if (index > -1) { str = sbstr.Substring(0, index); if (!string.IsNullOrEmpty(richcontent.color)) { label.text = richcontent.color + str + "[-]"; } else { label.text = str; } //iswrap = true; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; SetCurrWidth(mPositionX + label.width); mPositionX = mLabeltemp_x; m_dy = 0; sbstr = sbstr.Remove(0, str.Length); ParseWrapText(sbstr, richcontent); } else { str = sbstr; if (!string.IsNullOrEmpty(richcontent.color)) { label.text = richcontent.color + str + "[-]"; } else { label.text = str; } int lastLabelwidth = label.width; mPositionX += lastLabelwidth; SetCurrWidth(mPositionX); } }