public override void Draw(string id, HtRect rect, HtColor color, string text, bool isEffect, Core.DrawTextEffect effect, HtColor effectColor, int effectAmount, string linkText, object userData) { Console.WriteLine("DrawText: {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", this, id, rect, color, text, isEffect, effect, effectColor, effectAmount, linkText, userData); }
public abstract void Draw(string id, HtRect rect, HtColor color, string text, bool isEffect, Core.DrawTextEffect effect, HtColor effectColor, int effectAmount, string linkText, object userData);
/// <summary> /// Draw method. /// </summary> /// <param name="rect">Where to draw</param> /// <param name="color">Text color</param> /// <param name="text">Text</param> /// <param name="isEffect">Is effect</param> /// <param name="effect">Effect</param> /// <param name="effectColor">Effect color</param> /// <param name="effectAmount">Effect amount</param> /// <param name="linkText">Link text</param> /// <param name="userData">User data</param> public override void Draw(string id, HtRect rect, HtColor color, string text, bool isEffect, Core.DrawTextEffect effect, HtColor effectColor, int effectAmount, string linkText, object userData) { if (isEffect) { return; } var root = userData as Transform; if (root != null) { var go = new GameObject(string.IsNullOrEmpty(id) ? "label" : id, typeof(UILabel)); go.layer = root.gameObject.layer; go.transform.parent = root; go.transform.localPosition = new Vector3(rect.X + rect.Width / 2, -rect.Y - rect.Height / 2, 0f); go.transform.localScale = Vector3.one;//Vector3.zero; //new Vector3(this.style.font.fontSize, this.style.font.fontSize, 1f); var lab = go.GetComponent <UILabel>(); lab.pivot = UIWidget.Pivot.Center; lab.supportEncoding = false; lab.bitmapFont = m_font; lab.fontSize = this.Size; lab.text = text; lab.color = new Color32(color.R, color.G, color.B, color.A); switch (effect) { case Core.DrawTextEffect.Outline: lab.effectStyle = UILabel.Effect.Outline; break; case Core.DrawTextEffect.Shadow: lab.effectStyle = UILabel.Effect.Shadow; break; } if (this.Bold && this.Italic) { lab.fontStyle = FontStyle.BoldAndItalic; } else if (this.Bold) { lab.fontStyle = FontStyle.Bold; } else if (this.Italic) { lab.fontStyle = FontStyle.Italic; } lab.effectColor = new Color32(effectColor.R, effectColor.G, effectColor.B, effectColor.A); lab.effectDistance = new Vector2(effectAmount, effectAmount); lab.MakePixelPerfect(); lab.width = rect.Width + 1; lab.height = rect.Height + 1; // build link. if (!string.IsNullOrEmpty(linkText)) { var collider = go.AddComponent <BoxCollider>(); collider.isTrigger = true; lab.autoResizeBoxCollider = true; lab.ResizeCollider(); var nguiLinkText = go.AddComponent <NGUILinkText>(); nguiLinkText.linkText = linkText; var uiButtonColor = go.AddComponent <UIButtonColor>(); uiButtonColor.tweenTarget = go; uiButtonColor.hover = new Color32( HtEngine.LinkHoverColor.R, HtEngine.LinkHoverColor.G, HtEngine.LinkHoverColor.B, HtEngine.LinkHoverColor.A); uiButtonColor.pressed = new Color( lab.color.r * HtEngine.LinkPressedFactor, lab.color.g * HtEngine.LinkPressedFactor, lab.color.b * HtEngine.LinkPressedFactor, lab.color.a); uiButtonColor.duration = 0f; var uiButtonMessage = go.AddComponent <UIButtonMessage>(); uiButtonMessage.target = root.gameObject; uiButtonMessage.functionName = HtEngine.LinkFunctionName; } } else { HtEngine.Log(HtLogLevel.Error, "Can't draw without root."); } }
/// <summary> /// Draw method. /// </summary> /// <param name="rect">Where to draw</param> /// <param name="color">Text color</param> /// <param name="text">Text</param> /// <param name="isEffect">Is effect</param> /// <param name="effect">Effect</param> /// <param name="effectColor">Effect color</param> /// <param name="effectAmount">Effect amount</param> /// <param name="linkText">Link text</param> /// <param name="userData">User data</param> public override void Draw(string id, HtRect rect, HtColor color, string text, bool isEffect, Core.DrawTextEffect effect, HtColor effectColor, int effectAmount, string linkText, object userData) { // just common implementation using GUIStyle if (string.IsNullOrEmpty(id)) { GUI.SetNextControlName(id); } content.text = text; style.normal.textColor = new Color32(color.R, color.G, color.B, color.A); style.Draw(new Rect(rect.X, rect.Y, rect.Width, rect.Height), content, false, false, false, false); }