예제 #1
0
        private ConditionGroup DrawConditionGroup(NodeValue nodeValue)
        {
            ConditionGroup conditionGroup = null;

            if (nodeValue.NodeType != (int)NODE_TYPE.CONDITION)
            {
                return(conditionGroup);
            }

            EditorGUILayout.BeginVertical("box");
            {
                conditionGroup = BehaviorConditionGroup.DrawTransitionGroup(nodeValue);

                GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                if (GUILayout.Button("添加组"))
                {
                    DataNodeHandler dataNodeHandler = new DataNodeHandler();
                    dataNodeHandler.NodeAddConditionGroup(nodeValue.id);
                }

                GUI.enabled = true;
            }
            EditorGUILayout.EndVertical();

            return(conditionGroup);
        }
예제 #2
0
        private void NodeMakeTransition(NodeValue currentNode, List <NodeValue> nodeList)
        {
            Event _event = Event.current;

            mousePosition = _event.mousePosition;

            if (_event.type == EventType.MouseDown)
            {
                if (_event.button == 0)  // 鼠标左键
                {
                    if (makeTransitionMode)
                    {
                        NodeValue nodeValue = GetMouseInNode(nodeList);
                        // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点
                        if (null != nodeValue && currentNode.id != nodeValue.id)
                        {
                            DataNodeHandler dataNodeHandler = new DataNodeHandler();
                            dataNodeHandler.NodeAddChild(currentNode.id, nodeValue.id);
                        }

                        // 取消连线状态
                        makeTransitionMode = false;
                    }
                    else
                    {
                        NodeValue nodeValue = GetMouseInNode(nodeList);
                        ClickNode(nodeValue);
                    }
                }

                if (_event.button == 1)  // 鼠标右键
                {
                    if ((!makeTransitionMode))
                    {
                        NodeValue nodeValue = GetMouseInNode(nodeList);
                        ShowMenu(currentNode, nodeValue);
                    }
                }
            }

            if (makeTransitionMode && currentNode != null)
            {
                RectT mouseRect = new RectT(mousePosition.x, mousePosition.y, 10, 10);
                DrawNodeCurve(currentNode.position, mouseRect);
            }
        }
예제 #3
0
        public void ChangeSubTreeEntryNode(int subTreeNodeId, int nodeId)
        {
            NodeValue nodeValue = BehaviorDataController.Instance.GetNode(nodeId);

            if (null == nodeValue)
            {
                return;
            }

            NodeValue subTreeNode = BehaviorDataController.Instance.GetNode(subTreeNodeId);

            if (null == subTreeNode)
            {
                return;
            }

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

            for (int i = 0; i < nodeList.Count; ++i)
            {
                if (nodeList[i].parentSubTreeNodeId == nodeValue.parentSubTreeNodeId)
                {
                    if (nodeList[i].subTreeEntry)
                    {
                        RemoveParentNode(nodeList[i].id);
                    }

                    nodeList[i].subTreeEntry = (nodeList[i].id == nodeId);
                    if (nodeList[i].subTreeEntry)
                    {
                        subTreeNode.childNodeList.Clear();
                        subTreeNode.childNodeList.Add(nodeId);
                    }
                }
            }

            DataNodeHandler dataNodeHandler = new DataNodeHandler();

            dataNodeHandler.NodeAddChild(subTreeNodeId, nodeValue.id);
        }
예제 #4
0
        private void DrawAddParameter(NodeValue nodeValue)
        {
            GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
            if (GUILayout.Button("添加条件"))
            {
                if (BehaviorDataController.Instance.BehaviorTreeData.parameterList.Count <= 0)
                {
                    string msg = "没有参数可添加,请先添加参数";

                    if (TreeNodeWindow.window != null)
                    {
                        TreeNodeWindow.window.ShowNotification(msg);
                    }
                }
                else
                {
                    NodeParameter   behaviorParameter = BehaviorDataController.Instance.BehaviorTreeData.parameterList[0];
                    DataNodeHandler dataNodeHandler   = new DataNodeHandler();
                    dataNodeHandler.NodeAddParameter(nodeValue.id, behaviorParameter);
                }
            }
            GUI.enabled = true;
        }
        private static ConditionGroup DrawGroup(NodeValue nodeValue, ConditionGroup group)
        {
            Rect area   = GUILayoutUtility.GetRect(0f, 1, GUILayout.ExpandWidth(true));
            bool select = (selectIndex == group.index);

            GUI.enabled = true;
            EditorGUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true));
            {
                if (selectIndex < 0 || nodeId < 0 || nodeId != nodeValue.id)
                {
                    nodeId      = nodeValue.id;
                    selectIndex = group.index;
                }

                Rect rect = new Rect(area.x, area.y, area.width, 30);
                GUI.backgroundColor = select ? new Color(0, 1, 0, 1) : Color.white;//
                GUI.Box(rect, string.Empty);
                GUI.backgroundColor = Color.white;

                if (GUILayout.Button("选择", GUILayout.Width(50)))
                {
                    selectIndex = group.index;
                }

                for (int i = group.parameterList.Count - 1; i >= 0; --i)
                {
                    string        parameter         = group.parameterList[i];
                    NodeParameter behaviorParameter = nodeValue.parameterList.Find(a => (a.parameterName.CompareTo(parameter) == 0));
                    if (null == behaviorParameter)
                    {
                        group.parameterList.RemoveAt(i);
                    }
                }

                GUI.enabled = select && !BehaviorDataController.Instance.CurrentOpenConfigSubTree();

                for (int i = 0; i < nodeValue.parameterList.Count; ++i)
                {
                    NodeParameter parameter = nodeValue.parameterList[i];
                    string        name      = group.parameterList.Find(a => (a.CompareTo(parameter.parameterName) == 0));

                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(i.ToString(), GUILayout.Width(10));
                        bool value    = !string.IsNullOrEmpty(name);
                        bool oldValue = value;
                        value = EditorGUILayout.Toggle(value, GUILayout.Width(10));
                        if (value)
                        {
                            if (!oldValue)
                            {
                                group.parameterList.Add(parameter.parameterName);
                                break;
                            }
                        }
                        else
                        {
                            if (oldValue)
                            {
                                group.parameterList.Remove(parameter.parameterName);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(10);
                }
                GUI.enabled = true;

                GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                if (GUILayout.Button("删除"))
                {
                    DataNodeHandler dataNodeHandler = new DataNodeHandler();
                    dataNodeHandler.NodeDelConditionGroup(nodeValue.id, group.index);
                }
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();

            if (select)
            {
                return(group);
            }
            return(null);
        }
예제 #6
0
        private void DrawNode(NodeValue nodeValue, string title)
        {
            ConditionGroup conditionGroup = DrawConditionGroup(nodeValue);

            for (int i = 0; i < nodeValue.parameterList.Count; ++i)
            {
                nodeValue.parameterList[i].index = i;
            }

            GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
            EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true));
            {
                EditorGUILayout.LabelField(title);

                int height = (nodeValue.parameterList.Count * 58);
                height    = height <= 300 ? height : 300;
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(height));
                {
                    GUI.backgroundColor = new Color(0.85f, 0.85f, 0.85f, 1f);
                    for (int i = 0; i < nodeValue.parameterList.Count; ++i)
                    {
                        NodeParameter behaviorParameter = nodeValue.parameterList[i];

                        Action DelCallBack = () =>
                        {
                            DataNodeHandler dataNodeHandler = new DataNodeHandler();
                            dataNodeHandler.NodeDelParameter(nodeValue.id, behaviorParameter);
                        };

                        Color color = Color.white;
                        if (null != conditionGroup)
                        {
                            string name = conditionGroup.parameterList.Find(a => (a.CompareTo(behaviorParameter.parameterName) == 0));
                            if (!string.IsNullOrEmpty(name))
                            {
                                color = colorArr[0];
                            }
                        }

                        GUI.backgroundColor = color; // new Color(0.85f, 0.85f, 0.85f, 1f);

                        EditorGUILayout.BeginVertical("box");
                        {
                            string parameterName = behaviorParameter.parameterName;

                            NodeParameter tempParameter = behaviorParameter.Clone();
                            tempParameter = DrawParameter.Draw(behaviorParameter, DrawParameterType.NODE_PARAMETER, DelCallBack);
                            if (parameterName.CompareTo(behaviorParameter.parameterName) != 0)
                            {
                                DataNodeHandler dataNodeHandler = new DataNodeHandler();
                                dataNodeHandler.NodeParameterChange(nodeValue.id, parameterName, behaviorParameter.parameterName);
                            }
                            else
                            {
                                behaviorParameter.CloneFrom(tempParameter);
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    GUI.backgroundColor = Color.white;
                }
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();
            GUI.enabled = true;

            GUILayout.Space(10);
            EditorGUILayout.BeginVertical("box");
            {
                DrawAddParameter(nodeValue);
            }
            EditorGUILayout.EndVertical();
        }