예제 #1
0
        private void CompositeNode(NodeValue nodeValue)
        {
            if (nodeValue.NodeType == (int)NODE_TYPE.CONDITION ||
                nodeValue.NodeType == (int)NODE_TYPE.ACTION)
            {
                return;
            }

            EditorGUILayout.BeginHorizontal(/*"box"*/);
            {
                string[]      nameArr  = EnumNames.GetEnumNames <NODE_TYPE>();
                List <string> nameList = new List <string>(nameArr);

                NODE_TYPE[] removeTypeArr = new NODE_TYPE[2] {
                    NODE_TYPE.ACTION, NODE_TYPE.CONDITION
                };
                for (int i = nameList.Count - 1; i >= 0; --i)
                {
                    for (int j = 0; j < removeTypeArr.Length; ++j)
                    {
                        NODE_TYPE type  = removeTypeArr[j];
                        int       value = EnumNames.GetEnumIndex <NODE_TYPE>(type);
                        string    name  = EnumNames.GetEnumName <NODE_TYPE>(value);
                        if (name.CompareTo(nameList[i]) == 0)
                        {
                            nameList.RemoveAt(i);
                            break;
                        }
                    }
                }
                nameArr = nameList.ToArray();
                int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
                if (index > nameArr.Length)
                {
                    index -= 2;//把 条件节点、行为节点,两个节点减掉
                }

                if ((NODE_TYPE)nodeValue.NodeType != NODE_TYPE.SUB_TREE)
                {
                    int result = EditorGUILayout.Popup(new GUIContent("改变节点类型"), index, nameArr);
                    if (result != index)
                    {
                        nodeValue.NodeType = (int)(EnumNames.GetEnum <NODE_TYPE>(result));
                        nodeValue.nodeName = EnumNames.GetEnumName <NODE_TYPE>(result);
                        nodeValue.function = NodeDescript.GetFunction((NODE_TYPE)nodeValue.NodeType);;

                        Debug.LogError(nodeValue.nodeName);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }
예제 #2
0
        // 添加节点
        public void AddNode(Node_Draw_Info_Item info, Vector3 mousePosition, int openSubTreeId)
        {
            NodeValue newNodeValue = new NodeValue();

            newNodeValue.id = GetNewNodeId();

            if (BehaviorDataController.Instance.BehaviorTreeData.rootNodeId < 0)
            {
                BehaviorDataController.Instance.BehaviorTreeData.rootNodeId = newNodeValue.id;
                newNodeValue.isRootNode = true;
            }

            newNodeValue.nodeName           = info._nodeName;
            newNodeValue.identificationName = info._identificationName;
            newNodeValue.NodeType           = (int)info._nodeType;
            newNodeValue.parentNodeID       = -1;
            newNodeValue.function           = NodeDescript.GetFunction((NODE_TYPE)info._nodeType);

            RectT rectT = new RectT();
            Rect  rect  = new Rect(mousePosition.x, mousePosition.y, rectT.width, rectT.height);

            newNodeValue.position = RectTool.RectToRectT(rect);

            newNodeValue.parentSubTreeNodeId = openSubTreeId;

            List <NodeValue> NodeList = BehaviorDataController.Instance.NodeList;

            NodeList.Add(newNodeValue);

            if (openSubTreeId >= 0)
            {
                bool hasEntryNode = false;
                for (int i = 0; i < NodeList.Count; ++i)
                {
                    if (NodeList[i].parentSubTreeNodeId == openSubTreeId &&
                        (NodeList[i].subTreeEntry))
                    {
                        hasEntryNode = true;
                        break;
                    }
                }
                if (!hasEntryNode)
                {
                    ChangeSubTreeEntryNode(newNodeValue.parentSubTreeNodeId, newNodeValue.id);
                }
            }
        }