Ejemplo n.º 1
0
    public static string GetTitle(NODE_TYPE nodeType)
    {
        int    index = EnumNames.GetEnumIndex <NODE_TYPE>(nodeType);
        string title = EnumNames.GetEnumName <NODE_TYPE>(index);

        return(title);
    }
Ejemplo n.º 2
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));
    }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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, "参数");
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
    }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
    public void GetTypeName()
    {
        int index = EnumNames.GetEnumIndex <NODE_TYPE>(_nodeType);

        _nodeName = EnumNames.GetEnumName <NODE_TYPE>(index);
    }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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();
        }