Exemplo n.º 1
0
    // 点击超链接
    public void OnClickHy(NodeBase node)
    {
        Debug.LogFormat("type:{0}", node.GetType().Name);
#if UNITY_EDITOR
        if (node is HyperlinkNode)
        {
            HyperlinkNode hn = (HyperlinkNode)node;
            EditorUtility.DisplayDialog("超链接", string.Format("点击了超链接:{0}", hn.d_text), "OK");
        }
#endif
    }
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            this.document  = (RichTextDocument)navigationContext.Parameters[HyperlinkDialogParameters.DocumentKey];
            this.selection = (Selection)navigationContext.Parameters[HyperlinkDialogParameters.SelectionKey];

            HyperlinkNode[] hyperlinksInSpan = document.GetHyperlinks(this.selection.DocumentSpan).ToArray();

            if (hyperlinksInSpan.Length > 0)
            {
                this.hyperlinkBeingEdited = hyperlinksInSpan[0];

                this.TextToDisplay = this.hyperlinkBeingEdited.GetText();
                this.Address       = this.hyperlinkBeingEdited.Uri;
                this.ToolTipText   = this.hyperlinkBeingEdited.Tooltip;

                this.dialogMode = HyperlinkDialogMode.EditingHyperlink;
            }
            else
            {
                if (selection.Length > 0)
                {
                    this.dialogMode    = HyperlinkDialogMode.MakingHyperlink;
                    this.TextToDisplay = this.selection.Text;
                }
                else
                {
                    if (this.SelectionIsWithinWord())
                    {
                        selection.SelectCurrentWord();
                    }

                    string textInSelection = document.GetTextInSpan(selection.DocumentSpan);
                    if (textInSelection.Trim().Length < 1)
                    {
                        this.dialogMode = HyperlinkDialogMode.InsertingHyperlink;
                        selection.Collapse(SelectionCollapseDirection.Start);
                    }
                    else
                    {
                        this.dialogMode    = HyperlinkDialogMode.MakingHyperlink;
                        this.TextToDisplay = selection.Text;
                    }
                }
            }
        }