Beispiel #1
0
        static void ShowAnimationNodeTypesMenu()
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            if (DashEditorCore.EditorConfig.editingGraph != null)
            {
                Type[] nodeTypes = ReflectionUtils.GetAllTypes(typeof(NodeBase)).ToArray();
                foreach (Type type in nodeTypes)
                {
                    CategoryAttribute attribute = type.GetCustomAttribute <CategoryAttribute>();
                    if (attribute == null || attribute.type != NodeCategoryType.ANIMATION)
                    {
                        continue;
                    }

                    TooltipAttribute tooltipAttribute = type.GetCustomAttribute <TooltipAttribute>();
                    string           tooltip          = tooltipAttribute != null ? tooltipAttribute.help : "";

                    string node = type.ToString().Substring(type.ToString().IndexOf(".") + 1);
                    node = node.Substring(0, node.Length - 4);

                    menu.AddItem(new GUIContent(node, tooltip), false, CreateAnimationNodesFromSelection, type);
                }
            }

            GenericMenuPopup.Show(menu, "", Event.current.mousePosition, 240, 300, false);
        }
Beispiel #2
0
        static public RuntimeGenericMenu Get()
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            if (DashEditorCore.EditorConfig.editingGraph != null)
            {
                Type[] nodeTypes = ReflectionUtils.GetAllTypes(typeof(NodeBase)).ToArray();
                Array.Sort(nodeTypes, CategorySort);
                foreach (Type type in nodeTypes)
                {
                    if (IsObsolete(type) && !DashEditorCore.EditorConfig.showObsolete)
                    {
                        continue;
                    }

                    if (IsExperimental(type) && !DashEditorCore.EditorConfig.showExperimental)
                    {
                        continue;
                    }

                    if (IsHidden(type))
                    {
                        continue;
                    }

                    if (CheckMultiple(type))
                    {
                        continue;
                    }

                    TooltipAttribute tooltipAttribute = type.GetCustomAttribute <TooltipAttribute>();
                    string           tooltip          = tooltipAttribute != null ? tooltipAttribute.help : "";

                    CategoryAttribute attribute      = type.GetCustomAttribute <CategoryAttribute>();
                    NodeCategoryType  category       = attribute == null ? NodeCategoryType.OTHER : attribute.type;
                    string            categoryString = category.ToString();
                    categoryString = categoryString.Substring(0, 1) + categoryString.Substring(1).ToLower();

                    string node = type.ToString().Substring(type.ToString().IndexOf(".") + 1);
                    node = node.Substring(0, node.Length - 4);

                    if (category == NodeCategoryType.GRAPH)
                    {
                        menu.AddItem(new GUIContent(node, tooltip), false, CreateNode, type);
                    }
                    else
                    {
                        menu.AddItem(new GUIContent(categoryString + "/" + node, tooltip), false, CreateNode,
                                     type);
                    }
                }

                if (SelectionManager.HasCopiedNodes())
                {
                    menu.AddItem(new GUIContent("Paste Nodes"), false, PasteNodes);
                }

                menu.AddSeparator("");
                Transform[] selectedTransforms = SelectionUtils.GetTransformsFromSelection();
                if (selectedTransforms.Length > 0)
                {
                    foreach (Type type in nodeTypes)
                    {
                        CategoryAttribute attribute = type.GetCustomAttribute <CategoryAttribute>();
                        if (attribute == null || attribute.type != NodeCategoryType.ANIMATION)
                        {
                            continue;
                        }

                        TooltipAttribute tooltipAttribute = type.GetCustomAttribute <TooltipAttribute>();
                        string           tooltip          = tooltipAttribute != null ? tooltipAttribute.help : "";

                        string node = type.ToString().Substring(type.ToString().IndexOf(".") + 1);
                        node = node.Substring(0, node.Length - 4);

                        menu.AddItem(new GUIContent("Create For Selected/" + node, tooltip), false, CreateAnimationNodesFromSelection, type);
                    }
                }
            }

            return(menu);
        }