protected override void Common1()
        {
            nodeValue.subTreeValue = EditorGUILayout.LongField("SubTreeValue:", nodeValue.subTreeValue);
            string[] nameArr = EnumNames.GetEnumNames <SUB_TREE_TYPE>();
            int      index   = EnumNames.GetEnumIndex <SUB_TREE_TYPE>((SUB_TREE_TYPE)nodeValue.subTreeType);
            int      result  = EditorGUILayout.Popup(new GUIContent("子树类型"), index, nameArr);

            nodeValue.subTreeType   = (int)(EnumNames.GetEnum <SUB_TREE_TYPE>(result));
            nodeValue.subTreeConfig = EditorGUILayout.TextField(new GUIContent("配置文件"), nodeValue.subTreeConfig);
            GUILayout.Space(5);

            if (nodeValue.subTreeType == (int)SUB_TREE_TYPE.CONFIG)
            {
                DataHandler dataHandler = new DataHandler();
                dataHandler.DeleteSubTreeChild(nodeValue.id);

                if (GUILayout.Button("选择子树配置文件"))
                {
                    ConfigFileSelect configFileSelect = new ConfigFileSelect();
                    nodeValue.subTreeConfig = configFileSelect.Select();
                }
            }
            else
            {
                if (GUILayout.Button("将子树存储为配置文件"))
                {
                    ConfigFileSaveSubTree configFileSaveSubTree = new ConfigFileSaveSubTree();
                    configFileSaveSubTree.SaveSubTree(nodeValue.subTreeConfig, nodeValue.id);
                }
            }
        }
示例#2
0
    public static string GetTitle(NODE_TYPE nodeType)
    {
        int    index = EnumNames.GetEnumIndex <NODE_TYPE>(nodeType);
        string title = EnumNames.GetEnumName <NODE_TYPE>(index);

        return(title);
    }
示例#3
0
    private string GetNodeName(NodeValue nodeValue)
    {
        int    nodeIndex = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
        string name      = EnumNames.GetEnumName <NODE_TYPE>(nodeIndex);

        return(string.Format("{0}_{1}", name, nodeValue.id));
    }
示例#4
0
        protected override void NodeName()
        {
            int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
            string name  = EnumNames.GetEnumName <NODE_TYPE>(index);

            name = string.Format("{0}_{1}", name, nodeValue.id);
            EditorGUILayout.LabelField(name);
            base.NodeName();
        }
示例#5
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();
        }
示例#6
0
        public void Draw(NodeValue nodeValue)
        {
            if (null == nodeValue)
            {
                EditorGUILayout.LabelField("未选择节点");
                return;
            }

            EditorGUILayout.BeginVertical("box");
            {
                if (nodeValue.NodeType == (int)NODE_TYPE.CONDITION ||
                    nodeValue.NodeType == (int)NODE_TYPE.ACTION)
                {
                    int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
                    string name  = EnumNames.GetEnumName <NODE_TYPE>(index);
                    EditorGUILayout.LabelField(name);
                    GUILayout.Space(5);
                }

                string nodeName = nodeValue.nodeName;
                EditorGUILayout.LabelField(nodeName);

                string nodeId = string.Format("节点_{0}", nodeValue.id);
                EditorGUILayout.LabelField(nodeId);

                GUI.enabled          = false;
                nodeValue.isRootNode = EditorGUILayout.Toggle(new GUIContent("根节点"), nodeValue.isRootNode, GUILayout.Width(50));
                GUI.enabled          = true;

                if (nodeValue.parentNodeID >= 0)
                {
                    string parentName = string.Format("父节点_{0}", nodeValue.parentNodeID);
                    EditorGUILayout.LabelField(parentName);
                }

                if (nodeValue.identification > 0)
                {
                    string identificationName = string.Format("类标识_{0}", nodeValue.identification);
                    EditorGUILayout.LabelField(identificationName);

                    CustomIdentification customIdentification = CustomNode.Instance.GetIdentification(nodeValue.identification);
                    string className = customIdentification.ClassType.Name;
                    EditorGUILayout.LabelField(className);
                }

                nodeValue.descript = EditorGUILayout.TextArea(nodeValue.descript, GUILayout.Height(50));
            }
            EditorGUILayout.EndVertical();

            DrawNode(nodeValue, "参数");
        }
示例#7
0
        public void Draw(SkillHsmConfigNodeData nodeValue)
        {
            if (null == nodeValue)
            {
                EditorGUILayout.LabelField("未选择节点");
                return;
            }

            EditorGUILayout.BeginVertical("box");
            {
                //string nodeId = string.Format("节点  ID:{0}", nodeValue.Id);
                //EditorGUILayout.LabelField(nodeId);

                int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
                string name  = EnumNames.GetEnumName <NODE_TYPE>(index);
                name = string.Format("节点类型:{0}", name);
                EditorGUILayout.LabelField(name);

                if (nodeValue.Identification > 0)
                {
                    CustomIdentification customIdentification = CustomNode.Instance.GetIdentification((IDENTIFICATION)nodeValue.Identification);
                    string typeName = string.Format("类     型:{0}", customIdentification.Name);
                    EditorGUILayout.LabelField(typeName);

                    string className = string.Format("类     名:{0}", customIdentification.Type.Name);
                    EditorGUILayout.LabelField(className);

                    //string identificationName = string.Format("类标识  :{0}", nodeValue.Identification);
                    //EditorGUILayout.LabelField(identificationName);
                }
                GUILayout.Space(5);

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("节点名:", GUILayout.Width(50));
                    nodeValue.NodeName = EditorGUILayout.TextField(nodeValue.NodeName, GUILayout.ExpandWidth(true));
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.LabelField("节点描述:");
                nodeValue.Descript = EditorGUILayout.TextArea(nodeValue.Descript, GUILayout.Height(30));
                GUILayout.Space(5);
            }
            EditorGUILayout.EndVertical();

            DrawNode(nodeValue);
        }
        public void Reset(BehaviorTreeData behaviorTreeData)
        {
            behaviorTreeData.nodeDic.Clear();
            for (int i = 0; i < behaviorTreeData.nodeList.Count; ++i)
            {
                NodeValue nodeValue = behaviorTreeData.nodeList[i];
                int       index     = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
                nodeValue.nodeName = EnumNames.GetEnumName <NODE_TYPE>(index);
                behaviorTreeData.nodeDic.Add(nodeValue.id, nodeValue);
            }

            BehaviorAnalysis.GetInstance().SetLoadConfigEvent(LoadConfig);
            _behaviorTreeEntity = new BehaviorTreeEntity(long.MaxValue, behaviorTreeData);
            BehaviorTreeEntity.CurrentDebugEntityId = _behaviorTreeEntity.EntityId;
            SetRunTimeDrawNode(_behaviorTreeEntity);
            NodeNotify.Clear();
        }
示例#9
0
        // 绘制节点
        private void DrawNodeWindows()
        {
            Action CallBack = () =>
            {
                for (int i = 0; i < _nodeList.Count; i++)
                {
                    SkillHsmConfigNodeData nodeValue = _nodeList[i];
                    int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
                    string name  = EnumNames.GetEnumName <NODE_TYPE>(index);
                    name = string.Format("{0}_{1}", name, nodeValue.Id);
                    Rect rect = GUI.Window(i, RectTExtension.RectTToRect(nodeValue.Position), DrawNodeWindow, name);
                    nodeValue.Position = RectTExtension.RectToRectT(rect);
                    DrawToChildCurve(nodeValue);
                }
            };

            _treeNodeWindow.DrawWindow(CallBack);
        }
示例#10
0
    private static void CheckNode(List <NodeValue> nodeValueList)
    {
        int       rootNodeCount    = 0;
        NodeValue invalidNodeValue = null;

        // 开始绘制节点
        // 注意:必须在  BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示
        for (int i = 0; i < nodeValueList.Count; i++)
        {
            NodeValue nodeValue = nodeValueList[i];
            if (nodeValue.isRootNode)
            {
                ++rootNodeCount;
            }

            if (((NODE_TYPE)nodeValue.NodeType >= NODE_TYPE.CONDITION) && nodeValue.childNodeList.Count > 0)
            {
                invalidNodeValue = nodeValue;  // 叶节点 不能有子节点
            }
        }

        string meg = string.Empty;

        if (rootNodeCount > 1)
        {
            meg = "只能有一个根节点";
        }
        else if (rootNodeCount == 0)
        {
            meg = "必须有一个根节点";
        }

        if (null != invalidNodeValue)
        {
            int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)invalidNodeValue.NodeType);
            string name  = EnumNames.GetEnumName <NODE_TYPE>(index);
            meg = string.Format("节点:{0} {1} 不能有子节点", invalidNodeValue.id, name);
        }

        if (TreeNodeWindow.window != null && !string.IsNullOrEmpty(meg))
        {
            TreeNodeWindow.window.ShowNotification(meg);
        }
    }
示例#11
0
        private void SubTreeNode(NodeValue nodeValue)
        {
            nodeValue.subTreeValue = EditorGUILayout.LongField("SubTreeValue:", nodeValue.subTreeValue);
            string[] nameArr = EnumNames.GetEnumNames <SUB_TREE_TYPE>();
            int      index   = EnumNames.GetEnumIndex <SUB_TREE_TYPE>((SUB_TREE_TYPE)nodeValue.subTreeType);
            int      result  = EditorGUILayout.Popup(new GUIContent("子树类型"), index, nameArr);

            nodeValue.subTreeType = (int)(EnumNames.GetEnum <SUB_TREE_TYPE>(result));

            GUILayout.Space(8);
            nodeValue.subTreeConfig = EditorGUILayout.TextField(new GUIContent("配置文件"), nodeValue.subTreeConfig);
            GUILayout.Space(5);

            if (nodeValue.subTreeType == (int)SUB_TREE_TYPE.CONFIG)
            {
                if (null != BehaviorManager.behaviorDeleteSubTreeChild)
                {
                    BehaviorManager.behaviorDeleteSubTreeChild(nodeValue.id);
                }

                if (GUILayout.Button("选择子树配置文件"))
                {
                    if (null != BehaviorManager.behaviorSelectFile)
                    {
                        nodeValue.subTreeConfig = BehaviorManager.behaviorSelectFile();
                    }
                }
            }
            else
            {
                if (GUILayout.Button("将子树存储为配置文件"))
                {
                    if (null != BehaviorManager.behaviorSaveSubTree)
                    {
                        BehaviorManager.behaviorSaveSubTree(nodeValue.subTreeConfig, nodeValue.id);
                    }
                }
            }
        }
示例#12
0
    public void GetTypeName()
    {
        int index = EnumNames.GetEnumIndex <NODE_TYPE>(_nodeType);

        _nodeName = EnumNames.GetEnumName <NODE_TYPE>(index);
    }
        protected override void Common1()
        {
            HashSet <int> childHash = new HashSet <int>();

            if (nodeValue.childNodeList.Count > 3)
            {
                if (null != TreeNodeWindow.window)
                {
                    string msg = string.Format("判断节点 {0} 最多只能有三个节点", nodeValue.id);
                    TreeNodeWindow.window.ShowNotification(msg);
                }

                while (nodeValue.childNodeList.Count > 3)
                {
                    nodeValue.childNodeList.RemoveAt(nodeValue.childNodeList.Count - 1);
                }

                while (nodeValue.ifJudgeDataList.Count > 3)
                {
                    nodeValue.ifJudgeDataList.RemoveAt(nodeValue.ifJudgeDataList.Count - 1);
                }
            }

            EditorGUILayout.BeginVertical("box");
            {
                for (int i = 0; i < nodeValue.childNodeList.Count; ++i)
                {
                    int childId = nodeValue.childNodeList[i];
                    childHash.Add(childId);
                    IfJudgeData judgeData = nodeValue.ifJudgeDataList.Find((a) => { return(a.nodeId == childId); });
                    if (null == judgeData)
                    {
                        judgeData        = new IfJudgeData();
                        judgeData.nodeId = childId;
                        nodeValue.ifJudgeDataList.Add(judgeData);
                    }
                    judgeData.ifJudegType = ((i == 0) ? (int)NodeIfJudgeEnum.IF : (int)NodeIfJudgeEnum.ACTION);

                    EditorGUILayout.BeginVertical("box");
                    {
                        GUI.enabled = false;
                        EditorGUILayout.IntField("nodeId:", judgeData.nodeId);
                        {
                            string[] nameArr = EnumNames.GetEnumNames <NodeIfJudgeEnum>();
                            int      index   = EnumNames.GetEnumIndex <NodeIfJudgeEnum>((NodeIfJudgeEnum)judgeData.ifJudegType);
                            int      result  = EditorGUILayout.Popup(new GUIContent("节点类型"), index, nameArr);
                            judgeData.ifJudegType = (int)(EnumNames.GetEnum <NodeIfJudgeEnum>(result));
                        }
                        GUI.enabled = true;

                        if (judgeData.ifJudegType == (int)NodeIfJudgeEnum.ACTION)
                        {
                            string[] nameArr  = new string[] { "Fail", "Success" };
                            int      oldValue = judgeData.ifResult;
                            int      result   = EditorGUILayout.Popup(new GUIContent("执行条件"), judgeData.ifResult, nameArr);
                            if (oldValue != result)
                            {
                                JudgeNodeChangeChildCondition(nodeValue, judgeData.nodeId, (ResultType)result);
                            }
                        }
                    }
                    EditorGUILayout.EndVertical();
                }

                EditorGUILayout.BeginVertical("box");
                {
                    EditorGUILayout.LabelField("没有 if判断节点 返回结果对应类型的 执行节点");
                    string[] nameArr = new string[] { "Fail", "Success", "Running" };
                    nodeValue.defaultResult = EditorGUILayout.Popup(new GUIContent("默认返回结果"), nodeValue.defaultResult, nameArr);
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();

            for (int i = nodeValue.ifJudgeDataList.Count - 1; i >= 0; --i)
            {
                IfJudgeData data = nodeValue.ifJudgeDataList[i];
                if (!childHash.Contains(data.nodeId))
                {
                    nodeValue.ifJudgeDataList.RemoveAt(i);
                }
            }

            nodeValue.ifJudgeDataList.Sort((a, b) =>
            {
                return(a.ifJudegType - b.ifJudegType);
            });
        }
示例#14
0
        public static NodeParameter Draw(NodeParameter behaviorParameter, DrawParameterType drawParameterType, Action DelCallBack)
        {
            if (null == behaviorParameter)
            {
                return(behaviorParameter);
            }

            EditorGUILayout.BeginHorizontal();
            {
                string[]      parameterNameArr      = EnumNames.GetEnumNames <ParameterType>();
                int           index                 = EnumNames.GetEnumIndex <ParameterType>((ParameterType)(behaviorParameter.parameterType));
                ParameterType behaviorParameterType = EnumNames.GetEnum <ParameterType>(index);

                GUI.enabled = false;
                if (drawParameterType == DrawParameterType.NODE_PARAMETER)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        behaviorParameter.index = EditorGUILayout.IntField(behaviorParameter.index, GUILayout.Width(30));
                    }
                    EditorGUILayout.EndHorizontal();
                }

                bool enableChangeType = (drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER_ADD);
                GUI.enabled = enableChangeType && !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                {
                    index = EditorGUILayout.Popup(index, parameterNameArr);
                    behaviorParameter.parameterType = (int)EnumNames.GetEnum <ParameterType>(index);
                    GUILayout.Space(5);
                }
                GUI.enabled = true;

                if (drawParameterType == DrawParameterType.NODE_PARAMETER)
                {
                    GUI.enabled = false;
                    EditorGUILayout.BeginHorizontal();
                    {
                        behaviorParameter.parameterName = EditorGUILayout.TextField(behaviorParameter.parameterName);
                    }
                    EditorGUILayout.EndHorizontal();
                    GUI.enabled = true;
                }

                if (drawParameterType == DrawParameterType.NODE_PARAMETER || drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER)
                {
                    GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                    if (GUILayout.Button("Del"))
                    {
                        if (null != DelCallBack)
                        {
                            DelCallBack();
                        }
                    }
                    GUI.enabled = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                if (drawParameterType == DrawParameterType.NODE_PARAMETER)
                {
                    List <NodeParameter> parameterList = BehaviorDataController.Instance.BehaviorTreeData.parameterList;
                    string[]             parameterArr  = new string[parameterList.Count];
                    int index = -1;
                    for (int i = 0; i < parameterList.Count; ++i)
                    {
                        NodeParameter p = parameterList[i];
                        parameterArr[i] = p.CNName;
                        if (behaviorParameter.parameterName.CompareTo(p.parameterName) == 0)
                        {
                            index = i;
                        }
                    }

                    GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                    int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true));
                    GUI.enabled = true;
                    if (result != index)
                    {
                        behaviorParameter.parameterName = parameterList[result].parameterName;
                    }
                }
                else if (drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER ||
                         drawParameterType == DrawParameterType.RUNTIME_PARAMETER)
                {
                    GUI.enabled = false;
                    behaviorParameter.parameterName = EditorGUILayout.TextField(behaviorParameter.parameterName);
                    GUI.enabled = true;
                    string cnName = EditorGUILayout.TextField(behaviorParameter.CNName);
                    if (cnName.CompareTo(behaviorParameter.CNName) != 0)
                    {
                        TreeNodeWindow.window.ShowNotification("此处字段名只支持查看,不能修改");
                    }
                }
                else if (drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER_ADD)
                {
                    EditorGUILayout.BeginVertical();
                    {
                        string oldName = behaviorParameter.parameterName;
                        behaviorParameter.parameterName = EditorGUILayout.TextField("英文:", behaviorParameter.parameterName);
                        if (oldName.CompareTo(behaviorParameter.parameterName) != 0)
                        {
                            bool isNumOrAlp = IsNumOrAlp(behaviorParameter.parameterName);
                            if (!isNumOrAlp)
                            {
                                string msg = string.Format("参数名只能包含:数字、字母、下划线,且数字不能放在第一个字符位置");
                                TreeNodeWindow.window.ShowNotification(msg);
                                behaviorParameter.parameterName = oldName;
                            }
                        }

                        behaviorParameter.CNName = EditorGUILayout.TextField("中文", behaviorParameter.CNName);
                    }
                    EditorGUILayout.EndVertical();
                }

                ParameterCompare[] compareEnumArr = new ParameterCompare[] { };
                if (behaviorParameter.parameterType == (int)ParameterType.Int)
                {
                    compareEnumArr = new ParameterCompare[] { ParameterCompare.GREATER, ParameterCompare.GREATER_EQUALS, ParameterCompare.LESS_EQUAL, ParameterCompare.LESS, ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL };
                }
                if (behaviorParameter.parameterType == (int)ParameterType.Long)
                {
                    compareEnumArr = new ParameterCompare[] { ParameterCompare.GREATER, ParameterCompare.GREATER_EQUALS, ParameterCompare.LESS_EQUAL, ParameterCompare.LESS, ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL };
                }
                if (behaviorParameter.parameterType == (int)ParameterType.Float)
                {
                    compareEnumArr = new ParameterCompare[] { ParameterCompare.GREATER, ParameterCompare.LESS };
                }
                if (behaviorParameter.parameterType == (int)ParameterType.Bool)
                {
                    compareEnumArr = new ParameterCompare[] { ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL };
                }

                if (behaviorParameter.parameterType == (int)ParameterType.String)
                {
                    compareEnumArr = new ParameterCompare[] { ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL };
                }

                string[] compareArr = new string[compareEnumArr.Length];
                int      compare    = behaviorParameter.compare;
                bool     found      = false;
                for (int i = 0; i < compareEnumArr.Length; ++i)
                {
                    string name = System.Enum.GetName(typeof(ParameterCompare), compareEnumArr[i]);
                    compareArr[i] = name;
                    if ((ParameterCompare)behaviorParameter.compare == compareEnumArr[i])
                    {
                        compare = i;
                        found   = true;
                    }
                }

                if (!found)
                {
                    compare = 0;
                }

                GUI.enabled = (drawParameterType != DrawParameterType.BEHAVIOR_PARAMETER) && (drawParameterType != DrawParameterType.RUNTIME_PARAMETER) && !BehaviorDataController.Instance.CurrentOpenConfigSubTree();;
                bool value    = (drawParameterType != DrawParameterType.BEHAVIOR_PARAMETER) && (drawParameterType != DrawParameterType.RUNTIME_PARAMETER) && (drawParameterType != DrawParameterType.BEHAVIOR_PARAMETER_ADD);
                bool boolType = (behaviorParameter.parameterType == (int)ParameterType.Bool);
                if (value && !boolType)
                {
                    compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65));
                    behaviorParameter.compare = (int)(compareEnumArr[compare]);
                }
                GUI.enabled = true;

                if (boolType)
                {
                    behaviorParameter.compare = (int)ParameterCompare.EQUALS;
                }

                GUI.enabled = true && !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                {
                    if (behaviorParameter.parameterType == (int)ParameterType.Int)
                    {
                        behaviorParameter.intValue = EditorGUILayout.IntField(behaviorParameter.intValue, GUILayout.Width(60));
                    }

                    if (behaviorParameter.parameterType == (int)ParameterType.Long)
                    {
                        behaviorParameter.longValue = EditorGUILayout.LongField(behaviorParameter.longValue, GUILayout.Width(60));
                    }

                    if (behaviorParameter.parameterType == (int)ParameterType.Float)
                    {
                        behaviorParameter.floatValue = EditorGUILayout.FloatField(behaviorParameter.floatValue, GUILayout.Width(60));
                    }

                    if (behaviorParameter.parameterType == (int)ParameterType.Bool)
                    {
                        behaviorParameter.boolValue = EditorGUILayout.Toggle(behaviorParameter.boolValue, GUILayout.Width(60));
                    }

                    if (behaviorParameter.parameterType == (int)ParameterType.String)
                    {
                        behaviorParameter.stringValue = EditorGUILayout.TextField(behaviorParameter.stringValue, GUILayout.Width(60));
                    }
                }
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5);

            return(behaviorParameter);
        }
示例#15
0
        public static SkillHsmConfigHSMParameter Draw(SkillHsmConfigHSMParameter hSMParameter, HSMDrawParameterType drawParameterType, Action DelCallBack)
        {
            if (null == hSMParameter)
            {
                return(hSMParameter);
            }

            EditorGUILayout.BeginHorizontal();
            {
                string[]         parameterNameArr = EnumNames.GetEnumNames <HSMParameterType>();
                int              index            = EnumNames.GetEnumIndex <HSMParameterType>((HSMParameterType)(hSMParameter.ParameterType));
                HSMParameterType HSMParameterType = EnumNames.GetEnum <HSMParameterType>(index);

                bool enableChangeType = (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD);
                GUI.enabled = enableChangeType;
                {
                    GUI.enabled = false;
                    if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            hSMParameter.Index = EditorGUILayout.IntField(hSMParameter.Index, GUILayout.Width(30));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    GUI.enabled = enableChangeType;

                    index = EditorGUILayout.Popup(index, parameterNameArr, GUILayout.ExpandWidth(true));
                    hSMParameter.ParameterType = (int)EnumNames.GetEnum <HSMParameterType>(index);
                    GUILayout.Space(5);
                }
                GUI.enabled = true;

                if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER || drawParameterType == HSMDrawParameterType.HSM_PARAMETER)
                {
                    if (GUILayout.Button("删除", GUILayout.Width(45)))
                    {
                        if (null != DelCallBack)
                        {
                            DelCallBack();
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER)
                {
                    List <SkillHsmConfigHSMParameter> parameterList = HSMManager.Instance.HSMTreeData.ParameterList;
                    string[] parameterArr = new string[parameterList.Count];
                    int      index        = -1;
                    for (int i = 0; i < parameterList.Count; ++i)
                    {
                        SkillHsmConfigHSMParameter p = parameterList[i];
                        parameterArr[i] = p.CNName; //p.ParameterName;
                        if (hSMParameter.ParameterName.CompareTo(p.ParameterName) == 0)
                        {
                            index = i;
                        }
                    }

                    int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true));
                    if (result != index)
                    {
                        hSMParameter.ParameterName = parameterList[result].ParameterName; //parameterArr[result];
                    }
                }
                else if (drawParameterType == HSMDrawParameterType.HSM_PARAMETER ||
                         drawParameterType == HSMDrawParameterType.RUNTIME_PARAMETER)
                {
                    GUI.enabled = (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD);
                    hSMParameter.ParameterName = EditorGUILayout.TextField(hSMParameter.ParameterName);
                    hSMParameter.CNName        = EditorGUILayout.TextField(hSMParameter.CNName);
                    GUI.enabled = true;
                }
                else if (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD)
                {
                    EditorGUILayout.BeginVertical();
                    {
                        string oldName = hSMParameter.ParameterName;
                        hSMParameter.ParameterName = EditorGUILayout.TextField("英文:", hSMParameter.ParameterName);
                        if (oldName.CompareTo(hSMParameter.ParameterName) != 0)
                        {
                            bool isNumOrAlp = IsNumOrAlp(hSMParameter.ParameterName);
                            if (!isNumOrAlp)
                            {
                                string msg = string.Format("参数名只能包含:数字、字母、下划线,且数字不能放在第一个字符位置");
                                HSMNodeWindow.window.ShowNotification(msg);
                                hSMParameter.ParameterName = oldName;
                            }
                        }

                        hSMParameter.CNName = EditorGUILayout.TextField("中文", hSMParameter.CNName);
                    }
                    EditorGUILayout.EndVertical();
                }
                HSMCompare[] compareEnumArr = new HSMCompare[] { };
                if (hSMParameter.ParameterType == (int)HSMParameterType.Int)
                {
                    compareEnumArr = new HSMCompare[] { HSMCompare.GREATER, HSMCompare.GREATER_EQUALS, HSMCompare.LESS_EQUAL, HSMCompare.LESS, HSMCompare.EQUALS, HSMCompare.NOT_EQUAL };
                }
                if (hSMParameter.ParameterType == (int)HSMParameterType.Float)
                {
                    compareEnumArr = new HSMCompare[] { HSMCompare.GREATER, HSMCompare.LESS };
                }
                if (hSMParameter.ParameterType == (int)HSMParameterType.Bool)
                {
                    compareEnumArr = new HSMCompare[] { HSMCompare.EQUALS, HSMCompare.NOT_EQUAL };
                }
                string[] compareArr = new string[compareEnumArr.Length];
                int      compare    = hSMParameter.Compare;
                bool     found      = false;
                for (int i = 0; i < compareEnumArr.Length; ++i)
                {
                    int    index    = EnumNames.GetEnumIndex <HSMCompare>(compareEnumArr[i]);
                    string typeName = EnumNames.GetEnumName <HSMCompare>(index);
                    compareArr[i] = typeName;
                    if ((HSMCompare)hSMParameter.Compare == compareEnumArr[i])
                    {
                        compare = i;
                        found   = true;
                    }
                }

                if (!found)
                {
                    compare = 0;
                }

                bool value    = (drawParameterType != HSMDrawParameterType.HSM_PARAMETER) && (drawParameterType != HSMDrawParameterType.RUNTIME_PARAMETER) && (drawParameterType != HSMDrawParameterType.HSM_PARAMETER_ADD);
                bool boolType = (hSMParameter.ParameterType == (int)HSMParameterType.Bool);
                if (boolType)
                {
                    hSMParameter.Compare = (int)HSMCompare.EQUALS;
                }
                else if (value)
                {
                    compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65));
                    hSMParameter.Compare = (int)(compareEnumArr[compare]);
                }

                {
                    if (hSMParameter.ParameterType == (int)HSMParameterType.Int)
                    {
                        hSMParameter.IntValue = EditorGUILayout.IntField(hSMParameter.IntValue, GUILayout.Width(50));
                    }

                    if (hSMParameter.ParameterType == (int)HSMParameterType.Float)
                    {
                        hSMParameter.FloatValue = EditorGUILayout.FloatField(hSMParameter.FloatValue, GUILayout.Width(50));
                    }

                    if (hSMParameter.ParameterType == (int)HSMParameterType.Bool)
                    {
                        hSMParameter.BoolValue = EditorGUILayout.Toggle(hSMParameter.BoolValue, GUILayout.Width(50));
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(hSMParameter);
        }
示例#16
0
        public void Draw(NodeValue nodeValue)
        {
            if (null == nodeValue)
            {
                EditorGUILayout.LabelField("未选择节点");
                return;
            }

            GUI.enabled = !BehaviorManager.Instance.CurrentOpenConfigSubTree();

            EditorGUILayout.BeginVertical("box");
            {
                if (nodeValue.NodeType == (int)NODE_TYPE.CONDITION ||
                    nodeValue.NodeType == (int)NODE_TYPE.ACTION)
                {
                    int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType);
                    string name  = EnumNames.GetEnumName <NODE_TYPE>(index);
                    name = string.Format("{0}_{1}", name, nodeValue.id);
                    EditorGUILayout.LabelField(name);
                    GUILayout.Space(5);
                }

                string nodeName = nodeValue.nodeName;
                string msg      = string.Format("{0}_{1}", nodeName, nodeValue.id);
                EditorGUILayout.LabelField(msg);

                if (nodeValue.NodeType == (int)NODE_TYPE.SUB_TREE)
                {
                    SubTreeNode(nodeValue);
                }

                if (nodeValue.NodeType != (int)NODE_TYPE.CONDITION &&
                    nodeValue.NodeType != (int)NODE_TYPE.ACTION)
                {
                    CompositeNode(nodeValue);
                }

                EntryNode(nodeValue);

                if (nodeValue.NodeType == (int)NODE_TYPE.DECORATOR_REPEAT)
                {
                    nodeValue.repeatTimes = EditorGUILayout.IntField("重复执行次数", nodeValue.repeatTimes);
                }

                if (nodeValue.NodeType == (int)NODE_TYPE.IF_JUDEG)
                {
                    IfJudge(nodeValue);
                }

                if (nodeValue.childNodeList.Count > 0)
                {
                    if (nodeValue.NodeType != (int)NODE_TYPE.SUB_TREE)
                    {
                        nodeValue.moveWithChild = EditorGUILayout.Toggle(new GUIContent("同步移动子节点"), nodeValue.moveWithChild);
                    }
                    else
                    {
                        nodeValue.moveWithChild = false;
                    }
                }

                if (nodeValue.parentNodeID >= 0)
                {
                    string parentName = string.Format("父节点_{0}", nodeValue.parentNodeID);
                    EditorGUILayout.LabelField(parentName);
                }

                if (nodeValue.childNodeList.Count > 0 && nodeValue.NodeType == (int)NODE_TYPE.RANDOM_PRIORITY)
                {
                    EditorGUILayout.BeginVertical("box");
                    {
                        for (int i = 0; i < nodeValue.childNodeList.Count; ++i)
                        {
                            NodeValue childNode = BehaviorManager.Instance.GetNode(nodeValue.childNodeList[i]);
                            string    nodeMsg   = string.Format("子节点:{0} 权值:", childNode.id);
                            childNode.priority = EditorGUILayout.IntField(nodeMsg, childNode.priority);
                            childNode.priority = Mathf.Max(1, childNode.priority);
                        }
                    }
                    EditorGUILayout.EndVertical();
                }

                if (!string.IsNullOrEmpty(nodeValue.identificationName))
                {
                    string identificationName = string.Format("类标识_{0}", nodeValue.identificationName);
                    EditorGUILayout.LabelField(identificationName);

                    ICustomIdentification <NodeLeaf> customIdentification = CustomNode.Instance.GetIdentification(nodeValue.identificationName);
                    string className = customIdentification.IdentificationName;
                    EditorGUILayout.LabelField(className);
                }

                EditorGUILayout.LabelField("备注");
                nodeValue.descript = EditorGUILayout.TextArea(nodeValue.descript, GUILayout.Width(250));

                if ((nodeValue.NodeType != (int)NODE_TYPE.CONDITION && nodeValue.NodeType != (int)NODE_TYPE.ACTION))
                {
                    GUILayout.Space(20);
                    EditorGUILayout.LabelField("组合节点功能描述");
                    nodeValue.function = EditorGUILayout.TextArea(nodeValue.function, GUILayout.Height(150), GUILayout.Width(300));
                }
            }
            EditorGUILayout.EndVertical();

            GUI.enabled = true;
            DrawNode(nodeValue, "参数");
            GUI.enabled = true;

            ParentInfo();
        }
        public static void CheckNode(List <NodeValue> nodeValueList)
        {
            int       rootNodeCount    = 0;
            NodeValue invalidNodeValue = null;

            rootNodeArr = new int[nodeValueList.Count];

            bool rootNodeHasParent = false;

            // 开始绘制节点
            // 注意:必须在  BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示
            for (int i = 0; i < nodeValueList.Count; i++)
            {
                NodeValue nodeValue = nodeValueList[i];
                if (nodeValue.isRootNode)
                {
                    rootNodeArr[rootNodeCount] = nodeValue.id;
                    ++rootNodeCount;
                    if (nodeValue.parentNodeID >= 0)
                    {
                        rootNodeHasParent = true;
                    }
                }

                if (((NODE_TYPE)nodeValue.NodeType == NODE_TYPE.CONDITION || (NODE_TYPE)nodeValue.NodeType == NODE_TYPE.ACTION) && nodeValue.childNodeList.Count > 0)
                {
                    invalidNodeValue = nodeValue;  // 叶节点 不能有子节点
                }
            }

            string meg = string.Empty;

            if (rootNodeCount > 1)
            {
                meg = string.Format("有多个根节点:");
                for (int i = 0; i < rootNodeCount; ++i)
                {
                    meg += string.Format("_{0} ", rootNodeArr[i]);
                }
            }
            else if (rootNodeCount == 0)
            {
                meg = "必须有一个根节点";
            }
            else if (rootNodeHasParent)
            {
                meg = string.Format("跟节点_{0} 不能有父节点", rootNodeArr[0]);
            }

            if (null != invalidNodeValue)
            {
                int    index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)invalidNodeValue.NodeType);
                string name  = EnumNames.GetEnumName <NODE_TYPE>(index);
                meg = string.Format("节点:{0} {1} 不能有子节点", invalidNodeValue.id, name);
            }

            if (TreeNodeWindow.window != null && !string.IsNullOrEmpty(meg))
            {
                TreeNodeWindow.window.ShowNotification(meg);
            }
        }
示例#18
0
        public static BehaviorParameter Draw(BehaviorParameter behaviorParameter, DrawParameterType drawParameterType, Action DelCallBack)
        {
            if (null == behaviorParameter)
            {
                return(behaviorParameter);
            }

            {
                string[] parameterNameArr = EnumNames.GetEnumNames <BehaviorParameterType>();
                int      index            = EnumNames.GetEnumIndex <BehaviorParameterType>((BehaviorParameterType)(behaviorParameter.parameterType));
                BehaviorParameterType behaviorParameterType = EnumNames.GetEnum <BehaviorParameterType>(index);

                bool enableChangeType = (drawParameterType == DrawParameterType.GLOBAL_PARAMETER_ADD);
                GUI.enabled = enableChangeType;
                {
                    index = EditorGUILayout.Popup(index, parameterNameArr);
                    behaviorParameter.parameterType = (int)EnumNames.GetEnum <BehaviorParameterType>(index);
                    GUILayout.Space(5);
                }
                GUI.enabled = true;
            }

            EditorGUILayout.BeginHorizontal();
            {
                if (drawParameterType == DrawParameterType.NODE_PARAMETER)
                {
                    List <BehaviorParameter> parameterList = BehaviorManager.Instance.GlobalParameter.parameterList;
                    string[] parameterArr = new string[parameterList.Count];
                    int      index        = -1;
                    for (int i = 0; i < parameterList.Count; ++i)
                    {
                        BehaviorParameter p = parameterList[i];
                        parameterArr[i] = p.parameterName;
                        if (behaviorParameter.parameterName.CompareTo(p.parameterName) == 0)
                        {
                            index = i;
                        }
                    }

                    int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true));
                    if (result != index)
                    {
                        behaviorParameter.parameterName = parameterArr[result];
                    }
                }
                else if (drawParameterType == DrawParameterType.GLOBAL_PARAMETER ||
                         (drawParameterType == DrawParameterType.GLOBAL_PARAMETER_ADD) ||
                         drawParameterType == DrawParameterType.RUNTIME_PARAMETER)
                {
                    GUI.enabled = (drawParameterType == DrawParameterType.GLOBAL_PARAMETER_ADD);
                    behaviorParameter.parameterName = EditorGUILayout.TextField(behaviorParameter.parameterName);
                    GUI.enabled = true;
                }

                BehaviorCompare[] compareEnumArr = new BehaviorCompare[] { };
                if (behaviorParameter.parameterType == (int)BehaviorParameterType.Int)
                {
                    compareEnumArr = new BehaviorCompare[] { BehaviorCompare.GREATER, BehaviorCompare.GREATER_EQUALS, BehaviorCompare.LESS_EQUAL, BehaviorCompare.LESS, BehaviorCompare.EQUALS, BehaviorCompare.NOT_EQUAL };
                }
                if (behaviorParameter.parameterType == (int)BehaviorParameterType.Float)
                {
                    compareEnumArr = new BehaviorCompare[] { BehaviorCompare.GREATER, BehaviorCompare.LESS };
                }
                if (behaviorParameter.parameterType == (int)BehaviorParameterType.Bool)
                {
                    compareEnumArr = new BehaviorCompare[] { BehaviorCompare.EQUALS, BehaviorCompare.NOT_EQUAL };
                }
                string[] compareArr = new string[compareEnumArr.Length];
                int      compare    = behaviorParameter.compare;
                bool     found      = false;
                for (int i = 0; i < compareEnumArr.Length; ++i)
                {
                    string name = System.Enum.GetName(typeof(BehaviorCompare), compareEnumArr[i]);
                    compareArr[i] = name;
                    if ((BehaviorCompare)behaviorParameter.compare == compareEnumArr[i])
                    {
                        compare = i;
                        found   = true;
                    }
                }

                if (!found)
                {
                    compare = 0;
                }

                GUI.enabled = (drawParameterType != DrawParameterType.GLOBAL_PARAMETER) && (drawParameterType != DrawParameterType.RUNTIME_PARAMETER);
                {
                    compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65));
                    behaviorParameter.compare = (int)(compareEnumArr[compare]);
                }
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5);

            EditorGUILayout.BeginHorizontal();
            {
                GUI.enabled = (drawParameterType != DrawParameterType.GLOBAL_PARAMETER);
                {
                    if (behaviorParameter.parameterType == (int)BehaviorParameterType.Int)
                    {
                        behaviorParameter.intValue = EditorGUILayout.IntField("DefaultIntValue", behaviorParameter.intValue);
                    }

                    if (behaviorParameter.parameterType == (int)BehaviorParameterType.Float)
                    {
                        behaviorParameter.floatValue = EditorGUILayout.FloatField("DefaultFloatValue", behaviorParameter.floatValue);
                    }

                    if (behaviorParameter.parameterType == (int)BehaviorParameterType.Bool)
                    {
                        behaviorParameter.boolValue = EditorGUILayout.Toggle("DefaultBoolValue", behaviorParameter.boolValue);
                    }
                }
                GUI.enabled = true;

                if (drawParameterType == DrawParameterType.NODE_PARAMETER || drawParameterType == DrawParameterType.GLOBAL_PARAMETER)
                {
                    if (GUILayout.Button("Del"))
                    {
                        if (null != DelCallBack)
                        {
                            DelCallBack();
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(behaviorParameter);
        }