Exemplo n.º 1
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) => {
                if (null != BehaviorManager.behaviorAddNode)
                {
                    BehaviorManager.behaviorAddNode((Node_Draw_Info_Item)userData, mousePosition, BehaviorManager.Instance.CurrentOpenSubTreeId);
                }
            };

            List <Node_Draw_Info> nodeList = _drawController._behaviorDrawModel.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();
    }