예제 #1
0
        private void InitInfoList()
        {
            #region Node
            // 组合节点
            string         compositeName     = string.Format("{0}/{1}", "Add Node", "组合节点");
            Node_Draw_Info compositeDrawInfo = new Node_Draw_Info(compositeName);
            infoList.Add(compositeDrawInfo);

            // 修饰节点
            string         decoratorName     = string.Format("{0}/{1}", "Add Node", "修饰节点");
            Node_Draw_Info decoratorDrawInfo = new Node_Draw_Info(decoratorName);
            infoList.Add(decoratorDrawInfo);

            // 条件节点
            string         conditionName     = string.Format("{0}/{1}", "Add Node", "条件节点");
            Node_Draw_Info conditionDrawInfo = new Node_Draw_Info(conditionName);
            infoList.Add(conditionDrawInfo);

            // 行为节点
            string         actionName     = string.Format("{0}/{1}", "Add Node", "行为节点");
            Node_Draw_Info actionDrawInfo = new Node_Draw_Info(actionName);
            infoList.Add(actionDrawInfo);

            Node_Draw_Info subTreeDrawInfo = new Node_Draw_Info("AddSubTree");
            infoList.Add(subTreeDrawInfo);

            Dictionary <string, ICustomIdentification <AbstractNode> > nodeDic = BehaviorConfigNode.Instance.GetNodeDic();
            foreach (var kv in nodeDic)
            {
                ICustomIdentification <AbstractNode> customIdentification = kv.Value;
                NODE_TYPE nodeType = (NODE_TYPE)customIdentification.NodeType;
                if ((int)nodeType >= (int)NODE_TYPE.SUB_TREE)
                {
                    subTreeDrawInfo.AddNodeType(nodeType, customIdentification.Name, customIdentification.IdentificationName);
                }
                else if ((int)nodeType >= (int)NODE_TYPE.ACTION)
                {
                    actionDrawInfo.AddNodeType(nodeType, customIdentification.Name, customIdentification.IdentificationName);
                }
                else if ((int)nodeType >= (int)NODE_TYPE.CONDITION)
                {
                    conditionDrawInfo.AddNodeType(nodeType, customIdentification.Name, customIdentification.IdentificationName);
                }
                else if ((int)nodeType >= (int)NODE_TYPE.DECORATOR_INVERTER)
                {
                    decoratorDrawInfo.AddNodeType(nodeType, customIdentification.Name, customIdentification.IdentificationName);
                }
                else if ((int)nodeType >= (int)NODE_TYPE.SELECT)
                {
                    compositeDrawInfo.AddNodeType(nodeType, customIdentification.Name, customIdentification.IdentificationName);
                }
            }
            #endregion
        }
예제 #2
0
        private void ShowMenu(NodeValue currentNode, NodeValue nodeValue)
        {
            int menuType = (nodeValue != null) ? 1 : 0;

            GenericMenu menu = new GenericMenu();

            if (menuType == 0)
            {
                GenericMenu.MenuFunction2 CallBack = (object userData) => {
                    DataHandler dataHandler = new DataHandler();
                    dataHandler.AddNode((Node_Draw_Info_Item)userData, mousePosition, BehaviorDataController.Instance.CurrentOpenSubTree);
                };

                List <Node_Draw_Info> nodeList = BehaviorNodeDrawInfoController.GetInstance().InfoList;
                for (int i = 0; i < nodeList.Count; ++i)
                {
                    Node_Draw_Info draw_Info = nodeList[i];
                    for (int j = 0; j < draw_Info._nodeArr.Count; ++j)
                    {
                        KeyValuePair <string, Node_Draw_Info_Item> kv = draw_Info._nodeArr[j];
                        //string itemName = string.Format("Add Node/{0}", kv.Key);
                        string itemName = string.Format("{0}", kv.Key);
                        GenericMenuAddItem(menu, new GUIContent(itemName), CallBack, kv.Value);
                    }
                }
            }
            else
            {
                if (null != currentNode && nodeValue.id == currentNode.id && (NODE_TYPE)nodeValue.NodeType < NODE_TYPE.CONDITION)
                {
                    // 连线子节点
                    GenericMenuAddItem(menu, new GUIContent("Make Transition"), MakeTransition);
                    menu.AddSeparator("");
                }
                // 删除节点
                GenericMenuAddItem(menu, new GUIContent("Delete Node"), DeleteNode);

                if (nodeValue.parentNodeID >= 0)
                {
                    GenericMenuAddItem(menu, new GUIContent("Remove Parent"), RemoveParentNode);
                }
            }

            menu.ShowAsContext();
            Event.current.Use();
        }