Beispiel #1
0
        protected override void RowGUI(RowGUIArgs args)
        {
            Event evt = Event.current;

            if (evt.type == EventType.Repaint)
            {
#if !UNITY_2019_3_OR_NEWER
                if (!args.selected)
                {
                    GUIStyle style = (args.row % 2 != 0) ? uNodeGUIUtility.Styles.itemBackground2 : uNodeGUIUtility.Styles.itemBackground;
                    style.Draw(args.rowRect, GUIContent.none, false, false, false, false);
                }
#endif
                if (args.item is MemberTreeView && !(args.item is TypeTreeView))
                {
                    MemberTreeView member    = args.item as MemberTreeView;
                    Rect           labelRect = args.rowRect;
                    labelRect.x += GetContentIndent(args.item) + 16;
                    Texture icon = uNodeEditorUtility.GetTypeIcon(ReflectionUtils.GetMemberType(member.member));
                    if (icon != null)
                    {
                        GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, 16, 16), icon);
                        labelRect.x     += 16;
                        labelRect.width -= 16;
                    }
                    if (ReflectionUtils.GetMemberIsStatic(member.member))
                    {
                        uNodeGUIUtility.Styles.itemStatic.Draw(labelRect, new GUIContent(args.label), false, false, false, false);
                    }
                    else
                    {
                        uNodeGUIUtility.Styles.itemNormal.Draw(labelRect, new GUIContent(args.label), false, false, false, false);
                    }
                    args.label = "";
                }
            }
            //if(args.rowRect.Contains(evt.mousePosition)) {
            //	hoverItem = args.item;
            //	if(hoverItem != lastHoverItem) {
            //		window.Repaint();
            //	}
            //}
            //extraSpaceBeforeIconAndLabel = 18f;

            //toggleRect.width = 16f;

            //// Ensure row is selected before using the toggle (usability)
            //if(evt.type == EventType.MouseDown && toggleRect.Contains(evt.mousePosition))
            //	SelectionClick(args.item, false);
            var labelStyle = ((GUIStyle)"TV Line");
            labelStyle.richText = true;
            base.RowGUI(args);
            labelStyle.richText = false;
        }
Beispiel #2
0
        void AddChildrenMember(List <MemberInfo> members, TreeViewItem item, IList <TreeViewItem> rows)
        {
            bool isSearching = !string.IsNullOrEmpty(searchString);

            if (item.children == null)
            {
                item.children = new List <TreeViewItem>();
            }
            for (int i = 0; i < members.Count; ++i)
            {
                var member = members[i];
                if (member.MemberType == MemberTypes.Method &&
                    (member.Name.StartsWith("get_") ||
                     member.Name.StartsWith("set_") ||
                     member.Name.StartsWith("op_") ||
                     member.Name.StartsWith("add_") ||
                     member.Name.StartsWith("remove_")))
                {
                    continue;
                }
                if (member.MemberType == MemberTypes.Constructor && member.DeclaringType.IsCastableTo(typeof(Component)))
                {
                    continue;
                }
                //string name = member.DeclaringType.FullName + "+" + member.Name;
                //switch(member.MemberType) {
                //	case MemberTypes.Constructor:
                //	case MemberTypes.Method:
                //		name += "=" + (member as MethodBase).GetParameters().Length;
                //		break;
                //}
                //var hashed = MD5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(name));
                if (!isSearching || IsMatchSearch(member, searchString))
                {
                    var childItem = new MemberTreeView(member, /*BitConverter.ToInt32(hashed, 0)*/ member.GetHashCode(), -1);
                    childItem.icon      = childItem.GetIcon() as Texture2D;
                    memberTrees[member] = childItem;
                    item.AddChild(childItem);
                    rows.Add(childItem);
                }
            }
        }
        void Setup()
        {
            if (reflectionValue == null)
            {
                reflectionValue = MemberData.none;
            }
            if (filter == null)
            {
                filter = new FilterAttribute()
                {
                    UnityReference = false, OnlyGetType = onlyGetType
                };
            }
            if (onlyGetType)
            {
                filter = new FilterAttribute(filter)
                {
                    OnlyGetType = onlyGetType
                }
            }
            ;
            if (filter.OnlyGetType)
            {
                filter.ValidTargetType = MemberData.TargetType.Type | MemberData.TargetType.Null;
            }
            if (targetObject)
            {
                uNodeRoot UNR = null;
                if (targetObject is uNodeRoot)
                {
                    UNR = targetObject as uNodeRoot;
                }
                else if (targetObject is RootObject)
                {
                    UNR = (targetObject as RootObject).owner;
                }
                else if (targetObject is NodeComponent)
                {
                    UNR = (targetObject as NodeComponent).owner;
                }
                else if (targetObject is TransitionEvent)
                {
                    UNR = (targetObject as TransitionEvent).owner;
                }
                if (UNR)
                {
                    uNodeData data = UNR.GetComponent <uNodeData>();
                    if (data)
                    {
                        //Clear the default namespace
                        usingNamespaces.Clear();
                        //Add graph namespaces
                        foreach (var n in data.GetNamespaces())
                        {
                            usingNamespaces.Add(n);
                        }
                    }
                    if (UNR is IIndependentGraph graph)
                    {
                        if (data == null)
                        {
                            //Clear the default namespace
                            usingNamespaces.Clear();
                        }
                        foreach (var n in graph.UsingNamespaces)
                        {
                            usingNamespaces.Add(n);
                        }
                    }
                }
            }
            editorData.manager        = new Manager(new TreeViewState());
            editorData.manager.window = this;
            editorData.searchField    = new SearchField();
            editorData.searchField.downOrUpArrowKeyPressed  += editorData.manager.SetFocusAndEnsureSelectedItem;
            editorData.searchField.autoSetFocusOnFindCommand = true;
            window = this;
            uNodeThreadUtility.Queue(DoSetup);
        }

        void DoSetup()
        {
            editorData.setup.Setup((progress) => {
                if (progress == 1)
                {
                    uNodeThreadUtility.Queue(() => {
                        var categories = new List <TreeViewItem>();
                        if (displayDefaultItem)
                        {
                            var categoryTree = new SelectorCategoryTreeView("#", "", uNodeEditorUtility.GetUIDFromString("[CATEG]#"), -1);
                            categories.Add(categoryTree);
                            var recentTree = new SelectorCategoryTreeView("Recently", "", uNodeEditorUtility.GetUIDFromString("[CATEG]#Recently"), -1);
                            categories.Add(recentTree);
                            if (displayNoneOption && filter.IsValidTarget(MemberData.TargetType.None))
                            {
                                categoryTree.AddChild(new SelectorMemberTreeView(MemberData.none, "None", uNodeEditorUtility.GetUIDFromString("#None"))
                                {
                                    icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.NullTypeIcon)) as Texture2D
                                });
                            }
                            if (!filter.SetMember)
                            {
                                if (!filter.IsValueTypes() && filter.IsValidTarget(MemberData.TargetType.Null) && !filter.OnlyGetType)
                                {
                                    categoryTree.AddChild(new SelectorMemberTreeView(MemberData.Null, "Null", uNodeEditorUtility.GetUIDFromString("#Null"))
                                    {
                                        icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.NullTypeIcon)) as Texture2D
                                    });
                                }
                                //if(!filter.OnlyGetType && filter.IsValidTarget(MemberData.TargetType.Values) &&
                                //	(filter.Types == null || filter.Types.Count != 1 || filter.Types[0] != typeof(Type))) {
                                //	categoryTree.AddChild(new SelectorCallbackTreeView((cRect) => {
                                //		var screenRect = cRect.ToScreenRect();
                                //		FilterAttribute F = new FilterAttribute(filter);
                                //		F.OnlyGetType = true;
                                //		ItemSelector w = null;
                                //		Action<MemberData> action = delegate (MemberData m) {
                                //			if(w != null) {
                                //				w.Close();
                                //				//EditorGUIUtility.ExitGUI();
                                //			}
                                //			if(filter.CanManipulateArray()) {
                                //				if(Event.current.button == 0) {
                                //					TypeSelectorWindow.ShowAsNew(Rect.zero, F, delegate (MemberData[] members) {
                                //						Type t = members[0].Get<Type>();
                                //						SelectValues(t);
                                //					}, m).ChangePosition(screenRect);
                                //				} else {
                                //					CommandWindow.CreateWindow(screenRect, (items) => {
                                //						var member = CompletionEvaluator.CompletionsToMemberData(items);
                                //						if(member != null) {
                                //							Type t = member.Get<Type>();
                                //							SelectValues(t);
                                //							return true;
                                //						}
                                //						return false;
                                //					}, new CompletionEvaluator.CompletionSetting() {
                                //						validCompletionKind = CompletionKind.Type | CompletionKind.Namespace | CompletionKind.Keyword,
                                //					});
                                //				}
                                //			} else {
                                //				Type t = m.Get<Type>();
                                //				SelectValues(t);
                                //			}
                                //		};
                                //		w = ShowAsNew(targetObject, F, action, true).ChangePosition(screenRect);
                                //	}, "Values", uNodeEditorUtility.GetUIDFromString("#Values"), -1) {
                                //		icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.ValueIcon)) as Texture2D
                                //	});
                                //}
                            }
                            if (displayRecentItem)
                            {
                                var listRecentItems = new List <TreeViewItem>();
                                if (uNodeEditor.SavedData.recentItems != null)
                                {
                                    foreach (var recent in uNodeEditor.SavedData.recentItems)
                                    {
                                        if (recent != null && recent.info != null)
                                        {
                                            if (recent.info is Type)
                                            {
                                                listRecentItems.Add(new TypeTreeView(recent.info as Type, recent.GetHashCode(), -1));
                                            }
                                            else if (!filter.OnlyGetType && (recent.isStatic || filter.DisplayInstanceOnStatic))
                                            {
                                                listRecentItems.Add(new MemberTreeView(recent.info, recent.GetHashCode(), -1));
                                            }
                                        }
                                    }
                                }
                                while (listRecentItems.Count > 10)
                                {
                                    listRecentItems.RemoveAt(listRecentItems.Count - 1);
                                }
                                if (listRecentItems.Count > 0)
                                {
                                    foreach (var item in listRecentItems)
                                    {
                                        if (item is MemberTreeView)
                                        {
                                            var tree = item as MemberTreeView;
                                            if (!(tree.member is Type))
                                            {
                                                tree.displayName = tree.member.DeclaringType.Name + "." + tree.displayName;
                                            }
                                        }
                                        recentTree.AddChild(item);
                                    }
                                    recentTree.expanded = false;
                                }
                            }
                            if (!filter.OnlyGetType && filter.UnityReference)
                            {
                                if (reflectionValue != null && reflectionValue.GetInstance() != null && !(reflectionValue.GetInstance() is IGraphSystem) && !(reflectionValue.GetInstance() is INode))
                                {
                                    categories.Add(TreeFunction.CreateTargetItem(reflectionValue.GetInstance(), "Target Reference", filter));
                                }
                                categories.AddRange(TreeFunction.CreateGraphItem(targetObject, reflectionValue, filter));
                            }
                            if (filter.UnityReference)
                            {
                                categories.AddRange(TreeFunction.CreateRootItem(targetObject, filter));
                            }
                            categories.AddRange(TreeFunction.CreateCustomItem(customItems));
                            if (filter.DisplayDefaultStaticType)
                            {
                                categoryTree.AddChild(new SelectorGroupedTreeView(() => {
                                    var result = new List <TreeViewItem>();
                                    result.Add(new SelectorSearchTreeView((prog) => {
                                        var treeResult = new List <TreeViewItem>();
                                        var sp         = new SearchProgress();
                                        prog?.Invoke(sp);
                                        var allTypes = GetAllTypes((currProgress) => {
                                            prog?.Invoke(currProgress);
                                        }, true, true);
                                        sp.info = "Setup Items";
                                        for (int i = 0; i < allTypes.Count; i++)
                                        {
                                            var pair   = allTypes[i];
                                            var nsTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[CATEG-SEARCH]" + pair.Key), -1);
                                            foreach (var type in pair.Value)
                                            {
                                                nsTree.AddChild(new TypeTreeView(type, type.GetHashCode(), -1));
                                            }
                                            treeResult.Add(nsTree);
                                            sp.progress = (float)i / (float)allTypes.Count;
                                            prog?.Invoke(sp);
                                        }
                                        return(treeResult);
                                    }, "Search All Types", uNodeEditorUtility.GetUIDFromString("[SAT]"), -1));
                                    var nestedNS = new HashSet <string>();
                                    //var excludedNs = uNodePreference.GetExcludedNamespace();
                                    var namespaces = new List <string>(EditorReflectionUtility.GetNamespaces());
                                    namespaces.Sort();
                                    namespaces.RemoveAll(i => /*excludedNs.Contains(i) ||*/ i == null || i.Contains("."));
                                    foreach (var ns in namespaces)
                                    {
                                        result.Add(new NamespaceTreeView(ns, uNodeEditorUtility.GetUIDFromString("[N]" + ns), -1));
                                    }
                                    //var nsTypes = GetNamespaceTypes(namespaces);
                                    //foreach(var pair in nsTypes) {
                                    //	var nsTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[Nested-NS]" + pair.Key), -1);
                                    //	foreach(var ns in nestedNS) {
                                    //		if(ns.StartsWith(pair.Key)) {
                                    //			nsTree.AddChild(new NamespaceTreeView(ns, uNodeEditorUtility.GetUIDFromString("[N]" + ns), -1));
                                    //		}
                                    //	}
                                    //	foreach(var type in pair.Value) {
                                    //		nsTree.AddChild(new TypeTreeView(type, type.GetHashCode(), -1));
                                    //	}
                                    //	//nsTree.children.Sort((x, y) => string.Compare(x.displayName, y.displayName));
                                    //	nsTree.expanded = false;
                                    //	result.Add(nsTree);
                                    //}
                                    return(result);
                                }, "All Namespaces", uNodeEditorUtility.GetUIDFromString("[ALL-NS]"), -1)
                                {
                                    icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.NamespaceIcon)) as Texture2D
                                });
                                categoryTree.AddChild(new SelectorGroupedTreeView(() => {
                                    var result    = new List <TreeViewItem>();
                                    var favorites = uNodeEditor.SavedData.favoriteItems;
                                    if (favorites != null)                                     //Favorite Type and Members
                                    {
                                        var typeTrees   = new List <TypeTreeView>();
                                        var memberTrees = new List <MemberTreeView>();
                                        foreach (var fav in favorites)
                                        {
                                            if (fav.info != null && window.filter.IsValidMember(fav.info))
                                            {
                                                if (fav.info is Type type)
                                                {
                                                    typeTrees.Add(new TypeTreeView(type));
                                                }
                                                else
                                                {
                                                    var tree         = new MemberTreeView(fav.info);
                                                    tree.displayName = tree.member.DeclaringType.Name + "." + tree.displayName;
                                                    memberTrees.Add(tree);
                                                }
                                            }
                                        }
                                        typeTrees.Sort((x, y) => string.Compare(x.displayName, y.displayName));
                                        memberTrees.Sort((x, y) => string.Compare(x.displayName, y.displayName));
                                        var typeCategory = new SelectorCategoryTreeView("Types", "", uNodeEditorUtility.GetUIDFromString("[TYPES]"), -1);
                                        foreach (var tree in typeTrees)
                                        {
                                            typeCategory.AddChild(tree);
                                        }
                                        var memberCategory = new SelectorCategoryTreeView("Members", "", uNodeEditorUtility.GetUIDFromString("[MEMBERS]"), -1);
                                        foreach (var tree in memberTrees)
                                        {
                                            memberCategory.AddChild(tree);
                                        }
                                        if (typeCategory.hasChildren)
                                        {
                                            result.Add(typeCategory);
                                        }
                                        if (memberCategory.hasChildren)
                                        {
                                            result.Add(memberCategory);
                                        }
                                    }
                                    {                                    //Favorite Namespaces
                                        var nsTrees = new List <NamespaceTreeView>();
                                        foreach (var fav in uNodeEditor.SavedData.favoriteNamespaces)
                                        {
                                            nsTrees.Add(new NamespaceTreeView(fav, uNodeEditorUtility.GetUIDFromString("[NS-FAV]" + fav), -1));
                                        }
                                        nsTrees.Sort((x, y) => string.Compare(x.displayName, y.displayName));
                                        var nsCategory = new SelectorCategoryTreeView("Namespaces", "", uNodeEditorUtility.GetUIDFromString("[NS]"), -1);
                                        foreach (var tree in nsTrees)
                                        {
                                            nsCategory.AddChild(tree);
                                        }
                                        if (nsCategory.hasChildren)
                                        {
                                            result.Add(nsCategory);
                                        }
                                    }
                                    return(result);
                                }, "Favorites", uNodeEditorUtility.GetUIDFromString("[fav]"), -1)
                                {
                                    icon = uNodeGUIUtility.Styles.favoriteIconOn
                                });
                                var namespaceTrees = new SelectorCategoryTreeView("Types", "", uNodeEditorUtility.GetUIDFromString("[NS]"), -1);
                                if (displayGeneralType)
                                {
                                    var categTree = new SelectorCategoryTreeView("General", "", uNodeEditorUtility.GetUIDFromString("[GENERAL]"), -1);
                                    var items     = TreeFunction.GetGeneralTrees();
                                    items.ForEach(tree => categTree.AddChild(tree));
                                    namespaceTrees.AddChild(categTree);
                                }
                                if (filter.DisplayRuntimeType)
                                {
                                    var runtimeItems = TreeFunction.GetRuntimeItems();
                                    var runtimeTypes = new Dictionary <string, List <TypeTreeView> >();
                                    foreach (var item in runtimeItems)
                                    {
                                        var ns = item.type.Namespace;
                                        if (string.IsNullOrEmpty(ns) || ns == RuntimeType.RuntimeNamespace)
                                        {
                                            ns = "Generated Type";
                                        }
                                        List <TypeTreeView> list;
                                        if (!runtimeTypes.TryGetValue(ns, out list))
                                        {
                                            list             = new List <TypeTreeView>();
                                            runtimeTypes[ns] = list;
                                        }
                                        list.Add(item);
                                    }
                                    foreach (var pair in runtimeTypes)
                                    {
                                        var categTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[RT]" + pair.Key), -1);
                                        var items     = pair.Value;
                                        items.ForEach(tree => categTree.AddChild(tree));
                                        namespaceTrees.AddChild(categTree);
                                    }
                                }
                                var typeList = editorData.setup.typeList;
                                foreach (var pair in typeList)
                                {
                                    var nsTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[CATEG]" + pair.Key), -1);
                                    foreach (var type in pair.Value)
                                    {
                                        nsTree.AddChild(new TypeTreeView(type, type.GetHashCode(), -1));
                                    }
                                    namespaceTrees.AddChild(nsTree);
                                }
                                categories.Add(namespaceTrees);
                            }
                        }