Exemplo n.º 1
0
        void AddChildrenType(List <Type> types, TreeViewItem item, IList <TreeViewItem> rows)
        {
            bool isSearching = !string.IsNullOrEmpty(searchString);

            if (item.children == null)
            {
                item.children = new List <TreeViewItem>();
            }
            for (int i = 0; i < types.Count; ++i)
            {
                int prevCount = rows.Count;
                var type      = types[i];
                var childItem = new TypeTreeView(type, uNodeEditorUtility.GetUIDFromString(type.FullName), -1);
                childItem.icon  = childItem.GetIcon() as Texture2D;
                typeTrees[type] = childItem;
                var members = GetSortedMember(type);
                if (members.Count > 0)
                {
                    if (isSearching)
                    {
                        if (searchString.Length > 2)
                        {
                            AddChildrenMember(members, childItem, rows);
                        }
                    }
                    else if (IsExpanded(childItem.id))
                    {
                        AddChildrenMember(members, childItem, rows);
                    }
                    else
                    {
                        childItem.children = CreateChildListForCollapsedParent();
                    }
                }
                if (!isSearching || childItem.children != null && childItem.children.Count > 0 || IsMatchSearch(childItem, searchString))
                {
                    item.AddChild(childItem);
                    rows.Insert(rows.Count - (rows.Count - prevCount), childItem);
                }
            }
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect rect)
        {
            base.OnGUI(rect);
            if (Event.current.type == EventType.MouseEnterWindow || Event.current.type == EventType.MouseLeaveWindow)
            {
                if (tooltipWindow != null)
                {
                    tooltipWindow.Close();
                }
            }
            if (Event.current.type == EventType.Repaint)
            {
                if (hoverItem != null && lastHoverItem != hoverItem)
                {
                    List <GUIContent> contents = new List <GUIContent>();
                    if (hoverItem is TypeTreeView)
                    {
                        if (uNodePreference.GetPreference().showDocumentation&& XmlDoc.hasLoadDoc)
                        {
                            TypeTreeView item = hoverItem as TypeTreeView;

                            Texture icon = uNodeEditorUtility.GetIcon(item.type);
                            contents.Add(new GUIContent(item.displayName, icon));
                            contents.Add(new GUIContent("Target	: " + item.type.MemberType.ToString()));
                            contents.Add(new GUIContent("Type	: "+ item.type.PrettyName(true), uNodeEditorUtility.GetTypeIcon(item.type)));
                            XmlElement documentation = XmlDoc.XMLFromType(item.type);
                            if (documentation != null)
                            {
                                contents.Add(new GUIContent("<b>Documentation</b> ▼ " + documentation["summary"].InnerText.Trim().AddLineInFirst()));
                            }
                        }
                    }
                    else if (hoverItem is MemberTreeView)
                    {
                        var     item = hoverItem as MemberTreeView;
                        Texture icon = uNodeEditorUtility.GetIcon(item.member);
                        contents.Add(new GUIContent(item.displayName, icon));
                        contents.Add(new GUIContent("Target	: " + item.member.MemberType.ToString()));
                        contents.Add(new GUIContent("Static	: " + ReflectionUtils.GetMemberIsStatic(item.member)));
                        if (item.member != null)
                        {
                            var mType = ReflectionUtils.GetMemberType(item.member);
                            contents.Add(new GUIContent("Return	: " + mType.PrettyName(true), uNodeEditorUtility.GetTypeIcon(mType)));
                        }
                        if (uNodePreference.GetPreference().showDocumentation&& XmlDoc.hasLoadDoc)
                        {
                            XmlElement documentation = XmlDoc.XMLFromMember(item.member);
                            if (documentation != null)
                            {
                                contents.Add(new GUIContent("<b>Documentation ▼</b> " + documentation["summary"].InnerText.Trim().AddLineInFirst()));
                            }
                            switch (item.member.MemberType)
                            {
                            case MemberTypes.Method:
                            case MemberTypes.Constructor:
                                var parameters = (item.member as MethodBase).GetParameters();
                                if (parameters.Length > 0)
                                {
                                    for (int x = 0; x < parameters.Length; x++)
                                    {
                                        System.Type PType = parameters[x].ParameterType;
                                        if (PType != null)
                                        {
                                            contents.Add(new GUIContent("<b>" + parameters[x].Name + " : " + PType.PrettyName() + "</b>",
                                                                        uNodeEditorUtility.GetTypeIcon(PType)));
                                            if (documentation != null && documentation["param"] != null)
                                            {
                                                XmlNode paramDoc = null;
                                                XmlNode doc      = documentation["param"];
                                                while (doc.NextSibling != null)
                                                {
                                                    if (doc.Attributes["name"] != null && doc.Attributes["name"].Value.Equals(parameters[x].Name))
                                                    {
                                                        paramDoc = doc;
                                                        break;
                                                    }
                                                    doc = doc.NextSibling;
                                                }
                                                if (paramDoc != null && !string.IsNullOrEmpty(paramDoc.InnerText))
                                                {
                                                    contents.Add(new GUIContent(paramDoc.InnerText.Trim()));
                                                }
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    if (contents.Count > 0)
                    {
                        var position = window.position;
                        if (position.x + position.width + 300 <= Screen.currentResolution.width)
                        {
                            tooltipWindow = TooltipWindow.Show(new Vector2(position.x + position.width, position.y), contents, 300, 600);
                        }
                        else
                        {
                            tooltipWindow = TooltipWindow.Show(new Vector2(position.x - 300, position.y), contents, 300, 600);
                        }
                    }
                    else if (tooltipWindow != null)
                    {
                        tooltipWindow.Close();
                    }
                    lastHoverItem = hoverItem;
                }
            }
        }