Exemple #1
0
        /// <summary>
        ///  Builds the menu items needed for the "Add node" menu.
        ///  Looks for <c>INodeMenuHandler</c>s cached by the editor first,
        ///  which falls back to the <c>NodeInfo</c> attribute on the <c>Node</c> itself,
        ///  which falls back to adding the node type name to the menu root.
        /// </summary>
        /// <param name="menu">The menu to build onto.</param>
        /// <param name="mousePosition">The position of the mouse.</param>
        public void LoadNodeMenu(GenericMenu menu, Vector2 mousePosition)
        {
            Assembly            engineAssembly = Assembly.Load("Assembly-CSharp");
            IEnumerable <Type>  nodeTypes      = engineAssembly.GetTypes().Where(t => typeof(Node).IsAssignableFrom(t));
            List <NodeMenuItem> menuItemsToAdd = new List <NodeMenuItem>();

            foreach (Type type in nodeTypes)
            {
                bool usedMenuHandler = false;
                if (nodeMenuHandlers.ContainsKey(type))
                {
                    INodeMenuHandler handler   = nodeMenuHandlers[type];
                    NodeMenuItem[]   menuItems = handler.AddNodeMenuItems(_model, mousePosition - _offset, this);
                    if (menuItems != null)
                    {
                        menuItemsToAdd.AddRange(menuItems);
                        usedMenuHandler = true;
                    }
                }
                if (!usedMenuHandler)
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    NodeInfoAttribute nodeAttribute = type.GetCustomAttribute <NodeInfoAttribute>();
                    if (nodeAttribute != null)
                    {
                        if (nodeAttribute.visible)
                        {
                            menuItemsToAdd.Add(new NodeMenuItem(nodeAttribute.menuLabel, () => AddNode(type, mousePosition), false, false));
                        }
                    }
                    else
                    {
                        menuItemsToAdd.Add(new NodeMenuItem(type.ToString(), () => AddNode(type, mousePosition), false, false));
                    }
                }
            }

            foreach (NodeMenuItem menuItem in menuItemsToAdd)
            {
                if (menuItem.disabled)
                {
                    menu.AddDisabledItem(new GUIContent(menuItem.label), menuItem.ticked);
                }
                else
                {
                    menu.AddItem(new GUIContent(menuItem.label), menuItem.ticked, menuItem.Function);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a new child in this category.
        /// If category is not null creates a new category child; otherwise creates a new Script child.
        /// <param name="category">The name of the category.</param>
        /// <param name="type">The type of the node.</param>
        /// <param name="NodeInfo">The node info of the script.</param>
        /// </summary>
        public void AddChild(string category, System.Type type, NodeInfoAttribute NodeInfo)
        {
            if (category == null)
            {
                category = string.Empty;
            }

            string[] splitedCategory = category.Split('/');

            // The category is not null or empty?
            if (splitedCategory.Length > 0 && splitedCategory[0] != string.Empty)
            {
                var desiredCategoryChild = GetChild(splitedCategory[0]) as Category;

                // The Category does not exist?
                if (desiredCategoryChild == null)
                {
                    // Create a new category
                    desiredCategoryChild = new Category(this, splitedCategory[0]);
                    m_Children.Add(desiredCategoryChild);
                }

                // Continues searching in the children category
                string removeSubString = category.Contains(splitedCategory[0] + "/") ? splitedCategory[0] + "/" : splitedCategory[0];
                int    index           = category.IndexOf(removeSubString);
                desiredCategoryChild.AddChild(category.Remove(index, removeSubString.Length), type, NodeInfo);
            }
            else
            {
                Item desiredChild = GetChild(type.ToString());
                // The Script does not exist?
                if (desiredChild == null)
                {
                    m_Children.Add(new Script(this, type.Name, type, NodeInfo));
                }
            }
        }
        /// <summary>
        /// Updates the active node data.
        /// <param name="activeNode">The active node.</param>
        /// </summary>
        void UpdateActiveNode(ActionNode activeNode)
        {
            var activeNodeType = activeNode != null?activeNode.GetType() : null;

            // The active node type has changed?
            if (activeNodeType != m_ActiveNodeType)
            {
                if (activeNode == null)
                {
                    m_ActiveNodeType     = null;
                    m_ActiveNodeInfo     = null;
                    m_ActiveNodeIcon     = null;
                    m_ActiveNodeTypeName = string.Empty;
                    return;
                }
                else
                {
                    m_ActiveNodeType     = activeNodeType;
                    m_ActiveNodeInfo     = AttributeUtility.GetAttribute <NodeInfoAttribute>(m_ActiveNodeType, true) ?? new NodeInfoAttribute();
                    m_ActiveNodeIcon     = IconUtility.GetIcon(m_ActiveNodeType);
                    m_ActiveNodeTypeName = " (" + m_ActiveNodeType.Name + ")";
                }
            }
        }