Ejemplo n.º 1
0
        /// <summary>
        /// Callback to add a new node.
        /// </summary>
        private void OnAddNode(ReorderableList list)
        {
            // Get all node scripts
            var nodeTypes = new List <System.Type>();

            foreach (System.Type type in BehaviourTreeUtility.GetNodeTypes())
            {
                if (!type.IsSubclassOf(typeof(BranchNode)))
                {
                    nodeTypes.Add(type);
                }
            }

            // Create the menu
            var menu = new UnityEditor.GenericMenu();

            // Add node types to the menu
            for (int i = 0; i < nodeTypes.Count; i++)
            {
                var nodeType = nodeTypes[i];
                var nodeInfo = AttributeUtility.GetAttribute <NodeInfoAttribute>(nodeType, false) ?? new NodeInfoAttribute();
                menu.AddItem(new GUIContent(nodeInfo.category + nodeType.Name), false, delegate() { ActionStateUtility.AddNode(m_ActionState, nodeType); RegisterEditorOnGUI(); });
            }

            // Show the context menu
            menu.ShowAsContext();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Refresh items.
        /// </summary>
        void Refresh()
        {
            m_Root            = new Category(null, string.Empty);
            m_CurrentCategory = m_Root;

            // Stores all scripts that inherites from ActionNode as child of m_Root
            foreach (var type in BehaviourTreeUtility.GetNodeTypes())
            {
                var nodeInfo = AttributeUtility.GetAttribute <NodeInfoAttribute>(type, false) ?? new NodeInfoAttribute();
                m_Root.AddChild(nodeInfo.category, type, nodeInfo);
            }
        }