Exemplo n.º 1
0
 public void OnReveal(HyperText source, HyperText.LinkInfo linkInfo)
 {
     if (!Popup.IsRevealed)
     {
         // get center of hitboxes involved
         Vector2 hitboxCenter = Vector3.zero;
         source.GetLinkHitboxes(linkInfo.Index, m_Hitboxes);
         for (int i = 0; i < m_Hitboxes.Count; ++i)
         {
             hitboxCenter += m_Hitboxes[i].center;
         }
         hitboxCenter /= m_Hitboxes.Count;
         // set position of popup
         Popup.transform.localPosition = hitboxCenter -
                                         Vector2.up * ((Popup.RectTransform.rect.height + m_Source.FontSizeToUse) * 0.5f + m_Padding);
     }
     // set text of popup
     m_Source.GetLinkKeywordCollections(m_LinkKeywords);
     Popup.SetText(
         (
             m_LinkKeywords.Where(
                 collection => collection.ClassName == linkInfo.ClassName
                 ).First().Collection as KeywordsGlossary
         ).GetEntry(linkInfo.Name).Definition
         );
     // reveal the popup
     Popup.Reveal();
 }
Exemplo n.º 2
0
        public static void CreateNew(MenuCommand menuCommand)
        {
            EditorApplication.ExecuteMenuItem("GameObject/UI/Text");
            UnityEngine.UI.Text text = Selection.activeGameObject.GetComponent <UnityEngine.UI.Text>();
            Color color = text.color;

            GameObject.DestroyImmediate(Selection.activeGameObject.GetComponent <UnityEngine.UI.Shadow>(), true);
            GameObject.DestroyImmediate(text, true);
            Selection.activeGameObject.name = "HyperText";
            HyperText hyperText = Selection.activeGameObject.AddComponent <HyperText>();

            hyperText.color = color;
            hyperText.text  = "New <a name=\"link\">HyperText</a>";
            // BUG: for some reason parenting behavior is not inherited when executing built-in menu command
            GameObject parent = menuCommand.context as GameObject;

            if (parent != null && parent.GetComponentInParent <Canvas>() != null)
            {
#if !UNITY_4_6
                hyperText.gameObject.name =
                    GameObjectUtility.GetUniqueNameForSibling(parent.transform, hyperText.gameObject.name);
#endif
                GameObjectUtility.SetParentAndAlign(hyperText.gameObject, parent);
            }
        }
Exemplo n.º 3
0
		public void OnReveal(HyperText source, HyperText.LinkInfo linkInfo)
		{
			if (!Popup.IsRevealed)
			{
				// get center of hitboxes involved
				Vector2 hitboxCenter = Vector3.zero;
				foreach (Rect hitbox in linkInfo.Hitboxes)
				{
					hitboxCenter += hitbox.center;
				}
				hitboxCenter /= linkInfo.Hitboxes.Length;
				// set position of popup
				Popup.transform.localPosition = hitboxCenter -
					Vector2.up * ((Popup.RectTransform.rect.height + m_Source.FontSizeToUse) * 0.5f + m_Padding);
			}
			// set text of popup
			m_Source.GetLinkKeywordCollections(ref m_LinkKeywords);
			Popup.SetText(
				(
					m_LinkKeywords.Where(
						collection => collection.ClassName == linkInfo.ClassName
					).First().Collection as KeywordsGlossary
				).GetEntry(linkInfo.Id).Definition
			);
			// reveal the popup
			Popup.Reveal();
		}
Exemplo n.º 4
0
    private void BuildLinkOrQuadInfo(string id, string name, HyperText text)
    {
        LinkInfo linkInfo;
        QuadInfo quadInfo;
        bool     isLink = ExecOnBuildLinkOrQuadInfo(id, name, text, out linkInfo, out quadInfo);

        if (null != linkInfo)
        {
            BuildHrefInfo(text, linkInfo.Name, linkInfo.Color, isLink);
        }
        else if (null != quadInfo)
        {
            BuildQuadInfo(text, id, quadInfo.Name, quadInfo.Size, quadInfo.Count, isLink, quadInfo.Sprite, quadInfo.SpriteResource, quadInfo.InstantiatedPrefab, quadInfo.PrefabResource);
        }
        else
        {
            if (id == "#")
            {
                BuildQuadInfo(text, id, name, defaultQuadSize, isLink);
            }
            else
            {
                string color;
                if (!s_LinkColors.TryGetValue(id, out color))
                {
                    color = "blue";
                }
                string bracketName = string.Format("[{0}]", name);
                BuildHrefInfo(text, bracketName, color, isLink);
            }
        }
    }
Exemplo n.º 5
0
 private void OnClickText(HyperText arg0, HyperText.LinkInfo arg1)
 {
     if (this.onClickKeyward != null)
     {
         onClickKeyward.Invoke(DocUtil.UnWarpText(arg1.Name));
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Displays the vertex indices in the scene.
 /// </summary>
 /// <param name="hyperText">Hyper text.</param>
 private void DisplayVertexIndices(HyperText hyperText)
 {
     System.Collections.Generic.List <UIVertex> vertices =
         hyperText.GetFieldValue <System.Collections.Generic.List <UIVertex> >("uiVertices");
     for (int index = 0; index < vertices.Count; ++index)
     {
         Handles.Label(vertices[index].position, index.ToString());
     }
 }
Exemplo n.º 7
0
 private void SetTextItemClickEvent(HyperText text, List <Keyward> keywards)
 {
     if (keywards == null)
     {
         return;
     }
     foreach (var keyward in keywards)
     {
         SetClickAbleText(text, DocUtil.WarpText(keyward.regex), keyward.style);
     }
 }
Exemplo n.º 8
0
        private void SetClickAbleText(HyperText text, string regex, string style)
        {
            var pattern  = string.Format("({0})(?!</a>)", regex);
            var textInfo = Regex.Replace(text.text, pattern, (match) =>
            {
                if (match.Groups.Count > 1)
                {
                    return(string.Format("<a name=\"{0}\" class=\"{1}\">{2}</a>", regex, style, match.Groups[1].Value));
                }
                return(string.Format("<a name=\"{0}\" class=\"{1}\">{2}</a>", regex, style, match.Value));
            }, RegexOptions.Multiline);

            text.text = textInfo;
        }
Exemplo n.º 9
0
    protected override void OnEnable()
    {
        base.OnEnable();
        inputContent      = new GUIContent("Input Text");
        outputContent     = new GUIContent("Output Text");
        hyperColorContent = new GUIContent("Hyper Color");

        _text          = serializedObject.FindProperty("_text");
        m_Text         = serializedObject.FindProperty("m_Text");
        m_FontData     = serializedObject.FindProperty("m_FontData");
        hyperTextColor = serializedObject.FindProperty("hyperTextColor");

        hyperText = target as HyperText;
        _lastText = "";
    }
Exemplo n.º 10
0
        /// <summary>
        /// Un-tracks the supplied <see cref="HyperText"/> object.
        /// </summary>
        /// <param name="hyperText">Hyper text.</param>
        public static void UntrackHyperText(HyperText hyperText)
        {
            if (hyperText.FontToUse == null)
            {
                return;
            }
            HashSet <HyperText> texts;

            s_Tracked.TryGetValue(hyperText.FontToUse, out texts);
            if (texts == null)
            {
                return;
            }
            texts.Remove(hyperText);
        }
Exemplo n.º 11
0
    private bool ExecOnBuildLinkOrQuadInfo(string id, string name, HyperText text, out LinkInfo linkInfo, out QuadInfo quadInfo)
    {
        bool isLink = true;

        if (null != onBuildLinkOrQuadInfo)
        {
            isLink = onBuildLinkOrQuadInfo(id, name, text, out linkInfo, out quadInfo);
        }
        else
        {
            linkInfo = null;
            quadInfo = null;
        }
        return(isLink);
    }
Exemplo n.º 12
0
    private void BuildHrefInfo(HyperText text, string name, string color, bool isLink)
    {
        // 超链接颜色
        m_TextBuilder.AppendFormat("<color={0}>", color);
        var hrefInfo = new HrefInfo {
            startIndex = m_TextBuilder.Length * 4, // 超链接里的文本起始顶点索引
            endIndex   = (m_TextBuilder.Length + name.Length - 1) * 4 + 3,
            text       = text,
            isLink     = isLink
        };

        m_HrefInfos.Add(hrefInfo);

        m_TextBuilder.Append(name);
        m_TextBuilder.Append("</color>");
    }
Exemplo n.º 13
0
    private void BuildLinkOrQuadInfo(string id, string name, HyperText text)
    {
        LinkInfo linkInfo;
        QuadInfo quadInfo;
        bool     isLink = ExecOnBuildLinkOrQuadInfo(id, name, text, out linkInfo, out quadInfo);

        if (null != linkInfo)
        {
            BuildHrefInfo(text, linkInfo.Name, linkInfo.Color, isLink);
        }
        else if (null != quadInfo)
        {
            BuildQuadInfo(text, id, quadInfo.Name, quadInfo.Size, quadInfo.Count, isLink, quadInfo.Sprite, quadInfo.SpriteResource, quadInfo.InstantiatedPrefab, quadInfo.PrefabResource);
        }
        else
        {
            if (id == "#")
            {
                BuildQuadInfo(text, id, name, defaultQuadSize, false);
            }
            else if (id == "@")
            {
                StringBuilder sb = new StringBuilder();
                foreach (var txt in text.Texts)
                {
                    var t = txt as NormalText;
                    if (null != t)
                    {
                        sb.Append(t.Text);
                    }
                }
                BuildHrefInfo(text, sb.ToString(), string.Empty, true);
            }
            else
            {
                string color;
                if (!s_LinkColors.TryGetValue(id, out color))
                {
                    color = "blue";
                }
                string bracketName = string.Format("[{0}]", name);
                BuildHrefInfo(text, bracketName, color, isLink);
            }
        }
    }
Exemplo n.º 14
0
    public void OnClickChatLink(HyperText text, HyperText.LinkInfo link)
    {
        if (string.IsNullOrEmpty(link.Name))
        {
            return;
        }

        //<a name="c:1001:Name" class="player">Name</a>

        //<a name="i:1001:Name" class="item">Name</a>
        if (link.Name.StartsWith("c:"))
        {
            string[]      strs = link.Name.Split(":".ToCharArray());
            UIPopCharMenu menu = UIManager.Instance.Show <UIPopCharMenu>();
            menu.targetId   = int.Parse(strs[1]);
            menu.targetName = strs[2];
        }
    }
Exemplo n.º 15
0
        private HyperText GetTextFromPool()
        {
            HyperText text = null;

            text = textPools.Find(x => x != null && !x.gameObject.activeInHierarchy);
            if (text == null)
            {
                text = Instantiate(m_textPrefab);
                text.transform.SetParent(m_parent, false);
                text.ClickedLink.AddListener(OnClickText);
                SetTextItemClickEvent(text, keywards);
                textPools.Add(text);
            }
            else
            {
                text.transform.SetAsLastSibling();
            }
            text.gameObject.SetActive(true);
            return(text);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Tracks the supplied <see cref="HyperText"/> object.
        /// </summary>
        /// <param name="hyperText">Hyper text.</param>
        public static void TrackHyperText(HyperText hyperText)
        {
            if (hyperText.FontToUse == null)
            {
                return;
            }
            HashSet <HyperText> exists;

            s_Tracked.TryGetValue(hyperText.FontToUse, out exists);
            if (exists == null)
            {
                exists = new HashSet <HyperText>();
                s_Tracked.Add(hyperText.FontToUse, exists);
#if UNITY_4_6
                hyperText.FontToUse.textureRebuildCallback += RebuildForFont(hyperText.FontToUse);
#else
                Font.textureRebuilt += font => RebuildForFont(hyperText.FontToUse);
#endif
            }
            exists.Add(hyperText);
        }
Exemplo n.º 17
0
 private void OnClickHref(HyperText text)
 {
     if (text.Attrs.Count <= 0)
     {
         return;
     }
     if (text.Attrs[0].Key == "@")
     {
         Utility.EventSystem.Publish("[RichText]ClickOnPos", "richtext", text);
     }
     else if (text.Attrs[0].Key == "!")
     {
         Utility.EventSystem.Publish("[RichText]ClickOnItem", "richtext", text.Attrs[0].Value);
     }
     else if (text.Attrs[0].Key == "$")
     {
         Utility.EventSystem.Publish("[RichText]ClickOnPlayer", "richtext", text.Attrs[0].Value);
     }
     else if (text.Attrs[0].Key == "%")
     {
         Utility.EventSystem.Publish("[RichText]ClickOnSerCom", "richtext", text);
     }
 }
Exemplo n.º 18
0
    private void BuildHrefInfo(HyperText text, string name, string color, bool isLink)
    {
        bool includeColor = !string.IsNullOrEmpty(color);

        // 超链接颜色
        if (includeColor)
        {
            m_TextBuilder.AppendFormat("<color=#{0}>", color);
        }
        var hrefInfo = new HrefInfo {
            startIndex = m_TextBuilder.Length * 4, // 超链接里的文本起始顶点索引
            endIndex   = (m_TextBuilder.Length + name.Length - 1) * 4 + 3,
            text       = text,
            isLink     = isLink
        };

        m_HrefInfos.Add(hrefInfo);

        m_TextBuilder.Append(name);
        if (includeColor)
        {
            m_TextBuilder.Append("</color>");
        }
    }
Exemplo n.º 19
0
		public void OnDismiss(HyperText source, HyperText.LinkInfo linkInfo)
		{
			Popup.Dismiss();
		}
Exemplo n.º 20
0
    private void BuildQuadInfo(HyperText text, string id, string name, int size, int count, bool isLink, Sprite sprite, string spriteResource, GameObject instantiatedPrefab, string prefabResource)
    {
        int        firstIndex = m_TextBuilder.Length;
        int        lastIndex  = firstIndex;
        List <int> indexes    = new List <int>();

        for (int i = 0; i < count; ++i)
        {
            lastIndex = m_TextBuilder.Length;
            indexes.Add(lastIndex);
            m_TextBuilder.AppendFormat("<quad name={0} size={1} x=0 y=0 width=1 height=1 />", name, size);
        }

        var spriteInfo = new SpriteInfo();

        spriteInfo.name       = name;
        spriteInfo.firstIndex = firstIndex;
        spriteInfo.lastIndex  = lastIndex;
        spriteInfo.indexes    = indexes;
        spriteInfo.size       = new Vector2(size, size);
        spriteInfo.text       = text;
        spriteInfo.isLink     = isLink;
        m_SpriteInfos.Add(spriteInfo);

        if (null != sprite || !string.IsNullOrEmpty(spriteResource))
        {
            Image img       = null;
            var   resources = new DefaultControls.Resources();
            var   go        = DefaultControls.CreateImage(resources);
            go.layer = gameObject.layer;
            var nrt = go.transform as RectTransform;
            if (null != nrt)
            {
                nrt.SetParent(rectTransform);
                nrt.localPosition = Vector3.zero;
                nrt.localRotation = Quaternion.identity;
                nrt.localScale    = Vector3.one;
                nrt.sizeDelta     = new Vector2(size * count, size);
                nrt.anchorMin     = new Vector2(0.5f, 0.5f);
                nrt.anchorMax     = new Vector2(0.5f, 0.5f);
                nrt.pivot         = new Vector2(0.5f, 0.5f);

                img = go.GetComponent <Image>();
                if (null != sprite)
                {
                    img.sprite = sprite;
                }
                else if (!string.IsNullOrEmpty(spriteResource))
                {
                    img.sprite = Resources.Load <Sprite>(spriteResource);
                }
                img.enabled = true;

                spriteInfo.rectTransform = nrt;
            }
        }
        if (null != instantiatedPrefab || !string.IsNullOrEmpty(prefabResource))
        {
            if (null == instantiatedPrefab)
            {
                var m = Resources.Load <GameObject>(prefabResource);
                instantiatedPrefab = GameObject.Instantiate <GameObject>(m);
            }
            if (null != instantiatedPrefab)
            {
                instantiatedPrefab.layer = gameObject.layer;
                var nrt = instantiatedPrefab.transform as RectTransform;
                if (null != nrt)
                {
                    nrt.SetParent(rectTransform);
                    nrt.localPosition = Vector3.zero;
                    nrt.localRotation = Quaternion.identity;
                    nrt.localScale    = Vector3.one;
                    nrt.sizeDelta     = new Vector2(size * count, size);
                    nrt.anchorMin     = new Vector2(0.5f, 0.5f);
                    nrt.anchorMax     = new Vector2(0.5f, 0.5f);
                    nrt.pivot         = new Vector2(0.5f, 0.5f);

                    spriteInfo.rectTransform = nrt;
                }
            }
        }

        var drawSpriteInfo = new DrawSpriteInfo();

        drawSpriteInfo.id   = id;
        drawSpriteInfo.name = name;
        m_DrawSpriteInfos.Add(drawSpriteInfo);
    }
Exemplo n.º 21
0
 private void BuildQuadInfo(HyperText text, string id, string name, int size, bool isLink)
 {
     BuildQuadInfo(text, id, name, size, 1, isLink, null, string.Empty, null, string.Empty);
 }
Exemplo n.º 22
0
 private void AnalyzeRichText(HyperText txt)
 {
     if (txt.Attrs.Count >= 1)
     {
         string id  = txt.Attrs[0].Key;
         string val = txt.Attrs[0].Value;
         if (s_SystemColors.Contains(id))
         {
             //[{color_name}文本]
             m_TextBuilder.AppendFormat("<color={0}>", id);
             AnalyzeRichTexts(txt.Texts);
             m_TextBuilder.Append("</color>");
         }
         else if (id == "c")
         {
             //[{c}文本]
             m_TextBuilder.AppendFormat("<color=#{0}>", val);
             AnalyzeRichTexts(txt.Texts);
             m_TextBuilder.Append("</color>");
         }
         else if (id == "b")
         {
             //[{b}文本]
             m_TextBuilder.Append("<b>");
             AnalyzeRichTexts(txt.Texts);
             m_TextBuilder.Append("</b>");
         }
         else if (id == "i")
         {
             //[{i}文本]
             m_TextBuilder.Append("<i>");
             AnalyzeRichTexts(txt.Texts);
             m_TextBuilder.Append("</i>");
         }
         else if (id == "s")
         {
             //[{s}文本]
             m_TextBuilder.AppendFormat("<size={0}>", val);
             AnalyzeRichTexts(txt.Texts);
             m_TextBuilder.Append("</size>");
         }
         else if (id == "m")
         {
             //[{m}文本]
             m_TextBuilder.AppendFormat("<material={0}>", val);
             AnalyzeRichTexts(txt.Texts);
             m_TextBuilder.Append("</material>");
         }
         else if (id == "#")
         {
             //[#id]
             BuildLinkOrQuadInfo(id, val, txt);
         }
         else if (id == "@")
         {
             //[@id{pos:x,y}]
             BuildLinkOrQuadInfo(id, val, txt);
         }
         else
         {
             //[!...]等,其中!还可以为$%&*?\^~-+=|:
             BuildLinkOrQuadInfo(id, val, txt);
         }
     }
     else
     {
         AnalyzeRichTexts(txt.Texts);
     }
 }
Exemplo n.º 23
0
    private void BuildLinkOrQuadInfo(string id, string name, HyperText text)
    {
        LinkInfo linkInfo;
        QuadInfo quadInfo;
        bool     isLink = ExecOnBuildLinkOrQuadInfo(id, name, text, out linkInfo, out quadInfo);

        if (null != linkInfo)
        {
            BuildHrefInfo(text, linkInfo.Name, linkInfo.Color, isLink);
        }
        else if (null != quadInfo)
        {
            BuildQuadInfo(text, id, quadInfo.Name, quadInfo.Size, quadInfo.Count, isLink, quadInfo.Sprite, quadInfo.SpriteResource, quadInfo.InstantiatedPrefab, quadInfo.PrefabResource);
        }
        else
        {
            if (id == "#")
            {
                BuildQuadInfo(text, id, name, defaultQuadSize, false);
            }
            else if (id == "@")
            {
                string color = string.Empty;
                foreach (var att in text.Attrs)
                {
                    if (att.Key == "c")
                    {
                        color = att.Value;
                    }
                }
                StringBuilder sb = new StringBuilder();
                foreach (var txt in text.Texts)
                {
                    var t = txt as NormalText;
                    if (null != t)
                    {
                        sb.Append("[" + t.Text + "]");
                    }
                }
                BuildHrefInfo(text, sb.ToString(), color, true);
            }
            else if (id == "!" || id == "$" || id == "%")
            {
                string color = string.Empty;
                foreach (var att in text.Attrs)
                {
                    if (att.Key == "c")
                    {
                        color = att.Value;
                    }
                }
                StringBuilder sb = new StringBuilder();
                foreach (var txt in text.Texts)
                {
                    var t = txt as NormalText;
                    if (null != t)
                    {
                        sb.Append(t.Text);
                    }
                }
                string bracketName = string.Format("[{0}]", sb.ToString());
                BuildHrefInfo(text, bracketName, color, true);
            }


            else if (id == "~")
            {
                QuadInfo iconquadInfo = new RichText.QuadInfo();
                iconquadInfo.Name           = "icon";
                iconquadInfo.SpriteResource = name;
                BuildQuadInfo(text, id, iconquadInfo.Name, iconquadInfo.Size, iconquadInfo.Count, isLink, iconquadInfo.Sprite, iconquadInfo.SpriteResource, iconquadInfo.InstantiatedPrefab, iconquadInfo.PrefabResource);
            }
            else
            {
                string color;
                if (!s_LinkColors.TryGetValue(id, out color))
                {
                    color = "blue";
                }
                StringBuilder sb = new StringBuilder();
                foreach (var txt in text.Texts)
                {
                    var t = txt as NormalText;
                    if (null != t)
                    {
                        sb.Append(t.Text);
                    }
                }
                string bracketName = string.Format("[{0}]", sb.ToString());
                BuildHrefInfo(text, bracketName, color, isLink);
            }
        }
    }
Exemplo n.º 24
0
 public void OnDismiss(HyperText source, HyperText.LinkInfo linkInfo)
 {
     Popup.Dismiss();
 }