Exemple #1
0
 private void OnDisable()
 {
     if (tooltipWindow != null)
     {
         tooltipWindow.Close();
     }
 }
Exemple #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;
                }
            }
        }