コード例 #1
0
ファイル: DocItem.cs プロジェクト: zhongshuiyuan/JSDocNet
        void Parse()
        {
            string BlockText;
            string sName, S, S2;
            bool   IsNameTypeTag;
            int    Index;



            // parse name tags (they are all multi-line)
            foreach (string NameTag in Tags.NameTags)
            {
                BlockText = GetMultiLineTagValue(NameTag);
                if (!string.IsNullOrWhiteSpace(BlockText))
                {
                    sName = string.Empty;
                    if (NameTag == Tags.Constructor)
                    {
                        sName = BlockText.Trim();
                        if (!string.IsNullOrWhiteSpace(sName))
                        {
                            // member of + description
                            Index = sName.IndexOfAny(new char[] { '\r', '\n', ' ' });
                            if (Index == -1)
                            {
                                MemberOf = sName;
                            }
                            else
                            {
                                MemberOf = sName.Substring(0, Index);
                                S        = sName.Remove(0, MemberOf.Length).Trim();

                                if (!string.IsNullOrWhiteSpace(S))
                                {
                                    Description = S.TrimStart(new char[] { ' ', '-' });
                                }
                            }
                        }

                        break;
                    }



                    IsNameTypeTag = Tags.IsNameTypeTag(NameTag);

                    // type
                    if (IsNameTypeTag)
                    {
                        // @tag {Type} [MemberOf]Name [Description]

                        S  = string.Empty;
                        S2 = Sys.ExtractBracketedString(BlockText, out S);

                        IsNameTypeTag = !string.IsNullOrWhiteSpace(S);

                        if (IsNameTypeTag)
                        {
                            if (!string.IsNullOrWhiteSpace(S))
                            {
                                Type = S;
                            }

                            if (!string.IsNullOrWhiteSpace(S2))
                            {
                                sName = S2.Trim();
                            }
                        }
                    }


                    if (!IsNameTypeTag)
                    {
                        // @tag [MemberOf]Name [Description]
                        sName = BlockText.Trim();
                    }



                    // name + description
                    Index = sName.IndexOfAny(new char[] { '\r', '\n', ' ' });
                    if (Index == -1)
                    {
                        Name = sName;
                    }
                    else
                    {
                        Name = sName.Substring(0, Index);
                        S    = sName.Remove(0, Name.Length).Trim();

                        //S = sName.Substring(Index);
                        if (!string.IsNullOrWhiteSpace(S))
                        {
                            Description = S.TrimStart(new char[] { ' ', '-' });
                        }
                    }

                    break;
                }
            }



            // description
            if (string.IsNullOrWhiteSpace(Description))
            {
                Description = GetMultiLineTagValue(Tags.Description);
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                string[]      Parts = Description.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                StringBuilder SB    = new StringBuilder();
                foreach (string s in Parts)
                {
                    SB.AppendLine(s.TrimStart(new char[] { ' ', '*' }));
                }
                Description = SB.ToString();
            }

            // name
            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = GetSingleLineTagValue(Tags.Name);
            }

            // name + memberof
            if (!string.IsNullOrWhiteSpace(Name))
            {
                Index = Name.LastIndexOf('.');
                if (Index != -1)
                {
                    S        = Name;
                    Name     = S.Substring(Index + 1);
                    MemberOf = S.Substring(0, Index);
                }
            }

            // memberof
            if (string.IsNullOrWhiteSpace(MemberOf))
            {
                MemberOf = GetSingleLineTagValue(Tags.MemberOf);
            }

            // type
            if (string.IsNullOrWhiteSpace(Type))
            {
                Type = GetSingleLineTagValue(Tags.Type);
            }

            // ensure memberof
            if (string.IsNullOrWhiteSpace(MemberOf))
            {
                if (ItemType == DocItemType.Namespace || ItemType == DocItemType.Callback || ItemType == DocItemType.Interface)
                {
                    MemberOf = "global";
                }
                else
                {
                    MemberOf = Parser.Global.ContextName;
                }
            }

            // default
            Default = GetSingleLineTagValue(Tags.Default);


            if (ItemType == DocItemType.Class || ItemType == DocItemType.Enum)
            {
                // extends
                foreach (string NameTag in Tags.ExtendsTags)
                {
                    if (string.IsNullOrWhiteSpace(Extends))
                    {
                        Extends = GetSingleLineTagValue(NameTag);
                    }
                }

                // events
                Events = GetEvents();

                // implements
                Implements = GetImplements();
            }

            // category
            if (ItemType == DocItemType.Class || this.ItemType == DocItemType.Function)
            {
                Category = GetSingleLineTagValue(Tags.Category);
            }

            // access
            S = GetSingleLineTagValue(Tags.Access);
            if (!string.IsNullOrWhiteSpace(S))
            {
                if (S.IsSameText("private"))
                {
                    Access = Access.Private;
                }
                else if (S.IsSameText("protected"))
                {
                    Access = Access.Protected;
                }
                else if (S.IsSameText("public"))
                {
                    Access = Access.Public;
                }
            }

            // flags
            IsReadOnly   = DocLet.Find(Tags.ReadOnly) != null;
            IsStatic     = DocLet.Find(Tags.Static) != null;
            IsDeprecated = DocLet.Find(Tags.Deprecated) != null;
            IsBitField   = DocLet.Find(Tags.BitField) != null;
            IsFunction   = DocLet.Find(Tags.Function) != null; // when is namespace or enum and has a callable function with the same name
            IsEventArgs  = DocLet.Find(Tags.EventArgs) != null;

            // is function
            IsFunction = (ItemType == DocItemType.Function || ItemType == DocItemType.Constructor || ItemType == DocItemType.Callback) ||
                         ((ItemType == DocItemType.Namespace || ItemType == DocItemType.Enum) && (DocLet.Find(Tags.Function) != null));

            // Params + Return
            if (IsFunction)
            {
                Params = GetParams();
                if (ItemType != DocItemType.Constructor)
                {
                    Return = GetReturn();
                }
            }

            // Throws
            if (IsFunction || ItemType == DocItemType.Property)
            {
                Throws = GetThrows();
            }


            ParseExamples();
            ParseTutorials();
            ParseSee();
        }
コード例 #2
0
    private IEnumerator ShowTextShadow(string text)
    {
        text = text.Trim();
        text = text.Substring(1, text.Length - 2);
        text = "『" + text + "』";
        //i为当前显示字符长度
        int    i           = 0;
        int    strLength   = text.Length;
        string colHeadStr  = "";
        bool   isStringCol = false;
        bool   isChangeRow = false;

        while (i < strLength)
        {
            //识别并不显示颜色代码
            if (text[i].ToString() == "<" && text[i + 1].ToString() != "/")
            {
                isStringCol = true;
                int j = 1;
                while (text[i + j].ToString() != ">")
                {
                    j++;
                }
                colHeadStr = text.Substring(i, j + 1);
                i         += j + 1;
            }
            else if (text[i].ToString() == "<" && text[i + 1].ToString() == "/")
            {
                i          += 8;
                isStringCol = false;
            }
            //向显示字符中添加新字符
            if (isStringCol)
            {
                //showStr += colHeadStr + text[i].ToString() + "</color>";
            }
            else if (text[i] == '\\')
            {
                //忽略转行
                //showStr += '\n';
                i++;
                isChangeRow = true;
            }
            else
            {
                //showStr += text[i].ToString();

                GameObject blockTextPrefab = Resources.Load <GameObject>("Prefabs/BlockText");
                Transform  parent          = BlockText.blockTextList[0].gameObject.transform.parent;

                if (i == 0)
                {
                    GameObject blockTextObj2 = Instantiate(blockTextPrefab, parent);
                    blockTextObj2.GetComponent <BlockText>().SetText(text[i + 1].ToString());
                    i++;
                }
                else
                {
                    GameObject blockTextObj = Instantiate(blockTextPrefab, parent);
                    if (isChangeRow)
                    {
                        blockTextObj.GetComponent <BlockText>().ChangeRow();
                        isChangeRow = false;
                    }
                    blockTextObj.GetComponent <BlockText>().SetText(text[i].ToString());
                }
            }

            i++;
            yield return(new WaitForSeconds(textSpeed));
        }
        StopCoroutine("ShowTextShadow");
        Debug.Log("结束");
        BlockText blockText0 = BlockText.blockTextList[0];
        int       index      = 0;

        foreach (BlockText item in BlockText.blockTextList)
        {
            if (index != 0)
            {
                Destroy(item.gameObject);
            }
            index++;
        }
        BlockText.blockTextList.Clear();
        BlockText.blockTextList.Add(blockText0);
    }