示例#1
0
        private void ClickNode(SkillHsmConfigNodeData nodeValue)
        {
            if (null == nodeValue)
            {
                return;
            }
            int nodeId = (null != nodeValue) ? nodeValue.Id : -1;

            if (HSMManager.hSMChangeSelectId != null)
            {
                HSMManager.hSMChangeSelectId(nodeId);
            }

            if (nodeValue.NodeType == (int)NODE_TYPE.SUB_STATE_MACHINE)
            {
                int currentTime = (int)(Time.realtimeSinceStartup * 1000);
                if (currentTime - lastClickNodeTime <= 200)
                {
                    if (null != HSMManager.hsmOpenSubMachine)
                    {
                        HSMManager.hsmOpenSubMachine(nodeId);
                    }
                }
                lastClickNodeTime = (int)(Time.realtimeSinceStartup * 1000);
            }
        }
示例#2
0
        private void SelectTransition()
        {
            Event   _event   = Event.current;
            Vector3 mousePos = _event.mousePosition;

            if (_event.type != EventType.MouseDown || (_event.button != 0)) // 鼠标左键
            {
                return;
            }

            for (int i = 0; i < _nodeList.Count; i++)
            {
                SkillHsmConfigNodeData nodeValue = _nodeList[i];

                for (int j = 0; j < nodeValue.TransitionList.Count; ++j)
                {
                    SkillHsmConfigTransition transition = nodeValue.TransitionList[j];
                    int toId = transition.ToStateId;
                    SkillHsmConfigNodeData toNode = HSMManager.Instance.GetNode(toId);
                    if (null == toNode)
                    {
                        continue;
                    }

                    int     transitionId = nodeValue.Id * 1000 + transition.TransitionId;
                    Vector3 startPos     = Vector3.zero;
                    Vector3 endPos       = Vector3.zero;
                    CalculateTranstion(nodeValue.Position, toNode.Position, ref startPos, ref endPos);

                    Vector3 AB       = endPos - startPos;
                    Vector3 AP       = mousePos - startPos;
                    Vector3 BP       = mousePos - endPos;
                    float   dotAP_AB = Vector3.Dot(AP, AB.normalized);
                    float   dotBP_BA = Vector3.Dot(BP, (AB * -1).normalized);
                    if (dotAP_AB < 0 || dotBP_BA < 0)
                    {
                        continue;
                    }

                    float distance = Vector3.Cross(AB, AP).magnitude / AB.magnitude;

                    bool value = (distance < 10) && (Mathf.Abs(dotAP_AB) < AB.magnitude);
                    if (value)
                    {
                        if (null != HSMManager.hSMChangeSelectTransitionId)
                        {
                            int id = nodeValue.Id * 1000 + transition.TransitionId;
                            HSMManager.hSMChangeSelectTransitionId(id);
                        }

                        if (null != HSMManager.hSMChangeSelectId)
                        {
                            HSMManager.hSMChangeSelectId(nodeValue.Id);
                        }
                    }
                    //float distance = Vector3.Cross(AB, AP).magnitude / AB.magnitude;
                    //return distance <= (sRadius + cRadius);
                }
            }
        }
示例#3
0
 public static void CreateSaveFile(string fileName)
 {
     if (null != HSMManager.hSMSaveFile)
     {
         HSMManager.hSMSaveFile(fileName);
     }
 }
示例#4
0
 public static void DeleteFile(string fileName)
 {
     if (null != HSMManager.hSMDeleteFile)
     {
         HSMManager.hSMDeleteFile(fileName);
     }
 }
示例#5
0
        private void DrawTransitionAddParameter(SkillHsmConfigNodeData nodeValue, int transitionId)
        {
            GUI.enabled = (transitionId >= 0);

            if (GUILayout.Button("添加条件"))
            {
                if (HSMManager.Instance.HSMTreeData.ParameterList.Count <= 0)
                {
                    string msg = "没有参数可添加,请先添加参数";

                    if (HSMNodeWindow.window != null)
                    {
                        HSMNodeWindow.window.ShowNotification(msg);
                    }
                }
                else
                {
                    if (null != HSMManager.hSMNodeAddDelParameter)
                    {
                        SkillHsmConfigHSMParameter hSMParameter = HSMManager.Instance.HSMTreeData.ParameterList[0];
                        HSMManager.hSMNodeAddDelParameter(nodeValue.Id, transitionId, hSMParameter, true);
                    }
                }
            }

            GUI.enabled = true;
        }
示例#6
0
        private void DrawNodeParameter(SkillHsmConfigNodeData nodeData, string title)
        {
            EditorGUILayout.LabelField(title);
            List <SkillHsmConfigHSMParameter> parametersList = nodeData.ParameterList;

            Action <SkillHsmConfigHSMParameter> DelCallBack = (hSMParameter) =>
            {
                if (null != HSMManager.hSMNodeAddDelParameter)
                {
                    HSMManager.hSMNodeAddDelParameter(nodeData.Id, -1, hSMParameter, false);
                }
            };

            Action <string> ChangeParameter = (parameterName) =>
            {
                if (null != HSMManager.hSMNodeChangeParameter)
                {
                    HSMManager.hSMNodeChangeParameter(nodeData.Id, -1, parameterName);
                }
            };

            DrawParameter(nodeData, parametersList, DelCallBack, ChangeParameter, null);

            GUILayout.Space(10);
            EditorGUILayout.BeginVertical("box");
            {
                DrawNodeAddParameter(nodeData);
            }
            EditorGUILayout.EndVertical();
        }
示例#7
0
        private void NodeMakeTransition(SkillHsmConfigNodeData currentNode)
        {
            Event _event = Event.current;

            mousePosition = _event.mousePosition;

            if (_event.type == EventType.MouseDown)
            {
                if (_event.button == 0)  // 鼠标左键
                {
                    if (makeTransitionMode)
                    {
                        SkillHsmConfigNodeData nodeValue = GetMouseInNode(_nodeList);
                        // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点
                        bool nodeTypeValid = CheckTranshtion(currentNode, nodeValue);
                        if (null != nodeValue && currentNode.Id != nodeValue.Id && nodeTypeValid)
                        {
                            if (null != HSMManager.hSMNodeChangeTransition)
                            {
                                HSMManager.hSMNodeChangeTransition(currentNode.Id, nodeValue.Id, true);
                            }
                        }

                        // 取消连线状态
                        makeTransitionMode = false;
                    }
                    else
                    {
                        SkillHsmConfigNodeData nodeValue = GetMouseInNode(_nodeList);
                        if ((null != nodeValue))
                        {
                            ClickNode(nodeValue);
                        }
                    }
                }

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

            if (makeTransitionMode && currentNode != null)
            {
                SkillHsmConfigRectT mouseRect = new SkillHsmConfigRectT();
                mouseRect.X      = mousePosition.x;
                mouseRect.Y      = mousePosition.y;
                mouseRect.Width  = 10;
                mouseRect.Height = 10;

                DrawNodeCurve(currentNode.Position, mouseRect, Color.black);
            }
        }
示例#8
0
        private void ShowMenu(SkillHsmConfigNodeData currentNode, SkillHsmConfigNodeData nodeValue)
        {
            int menuType = (nodeValue != null) ? 1 : 0;

            GenericMenu menu = new GenericMenu();

            if (menuType == 0)
            {
                GenericMenu.MenuFunction2 CallBack = (object userData) => {
                    if (null != HSMManager.hSMAddState)
                    {
                        int subMachineId = -1;
                        if (HSMManager.Instance.CurrentOpenSubMachineId >= 0)
                        {
                            subMachineId = HSMManager.Instance.CurrentOpenSubMachineId;
                        }
                        HSMManager.hSMAddState((Node_Draw_Info_Item)userData, mousePosition, subMachineId);
                    }
                };

                List <Node_Draw_Info> nodeList = _drawController._HSMDrawModel.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("{0}", kv.Key);
                        menu.AddItem(new GUIContent(itemName), false, CallBack, kv.Value);
                    }
                }
            }
            else
            {
                if (null != currentNode && nodeValue.Id == currentNode.Id && nodeValue.NodeType != (int)NODE_TYPE.EXIT)
                {
                    // 连线子节点
                    menu.AddItem(new GUIContent("Make Transition"), false, MakeTransition);
                    menu.AddSeparator("");
                }

                if (null != currentNode && (currentNode.NodeType != (int)NODE_TYPE.ENTRY && (currentNode.NodeType != (int)NODE_TYPE.EXIT)))
                {
                    // 删除节点
                    menu.AddItem(new GUIContent("Delete State"), false, DeleteNode);
                }

                if (nodeValue.NodeType != (int)NODE_TYPE.ENTRY && nodeValue.NodeType != (int)NODE_TYPE.EXIT)
                {
                    // 设置默认节点
                    menu.AddItem(new GUIContent("Set Default State"), false, SetDefaultState);
                }
            }

            menu.ShowAsContext();
            Event.current.Use();
        }
示例#9
0
        private void DrawTransitionParameter(SkillHsmConfigNodeData nodeData, SkillHsmConfigTransition transition, string title)
        {
            EditorGUILayout.BeginVertical("box");
            {
                if (null != transition)
                {
                    SkillHsmConfigNodeData toNode = HSMManager.Instance.GetNode(transition.ToStateId);
                    string toNodeDescript         = (null != toNode) ? toNode.Descript : string.Empty;
                    string msg = string.Format("节点{0} -> 节点{1}", nodeData.Id, transition.ToStateId);
                    EditorGUILayout.LabelField(msg);
                }
            }
            EditorGUILayout.EndVertical();

            int transitionId = (null != transition) ? transition.TransitionId : -1;
            List <SkillHsmConfigHSMParameter> parametersList = (null != transition) ? transition.ParameterList : new List <SkillHsmConfigHSMParameter>();

            Action <SkillHsmConfigHSMParameter> DelCallBack = (hSMParameter) =>
            {
                if (null != HSMManager.hSMNodeAddDelParameter)
                {
                    HSMManager.hSMNodeAddDelParameter(nodeData.Id, transitionId, hSMParameter, false);
                }
            };

            Action <string> ChangeParameter = (parameterName) =>
            {
                if (null != HSMManager.hSMNodeChangeParameter)
                {
                    HSMManager.hSMNodeChangeParameter(nodeData.Id, transitionId, parameterName);
                }
            };

            SkillHsmConfigTransitionGroup group = null;

            EditorGUILayout.BeginVertical("box");
            {
                group = HSMTransitionGroup.DrawTransitionGroup(nodeData, transition);
                DrawTransitionAddGroup(nodeData, transitionId);
            }
            EditorGUILayout.EndVertical();

            for (int i = 0; i < parametersList.Count; ++i)
            {
                parametersList[i].Index = i;
            }
            DrawParameter(nodeData, parametersList, DelCallBack, ChangeParameter, group);

            GUILayout.Space(10);
            EditorGUILayout.BeginVertical("box");
            {
                DrawTransitionAddParameter(nodeData, transitionId);
            }
            EditorGUILayout.EndVertical();
        }
示例#10
0
        // 删除节点
        private void DeleteNode()
        {
            SkillHsmConfigNodeData nodeValue = GetMouseInNode(_nodeList);

            if (!EditorUtility.DisplayDialog("提示", "确定要删除节点吗", "Yes", "No"))
            {
                return;
            }

            if (null != HSMManager.hSMDeleteNode)
            {
                HSMManager.hSMDeleteNode(nodeValue.Id);
            }
        }
示例#11
0
        private void SetDefaultState()
        {
            SkillHsmConfigNodeData nodeValue = GetMouseInNode(_nodeList);

            if (null == nodeValue)
            {
                return;
            }

            if (null != HSMManager.hSMSetDefaultState)
            {
                HSMManager.hSMSetDefaultState(nodeValue.Id);
            }
        }
示例#12
0
        public void Draw(List <SkillHsmConfigHSMParameter> parameterList)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("全部变量");
                GUILayout.Space(50);
                if (GUILayout.Button("导入变量"))
                {
                    HSMFileHandle.ImportParameter();
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true));
            {
                EditorGUILayout.LabelField("条件参数");
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandHeight(true));
                {
                    GUI.backgroundColor = new Color(0.85f, 0.85f, 0.85f, 1f);
                    for (int i = 0; i < parameterList.Count; ++i)
                    {
                        SkillHsmConfigHSMParameter hsmParameter = parameterList[i];

                        Action DelCallBack = () =>
                        {
                            if (null != HSMManager.hSMNodeAddDelParameter)
                            {
                                HSMManager.parameterChange(hsmParameter, false);
                            }
                        };

                        EditorGUILayout.BeginVertical("box");
                        {
                            hsmParameter = HSMDrawParameter.Draw(hsmParameter, HSMDrawParameterType.HSM_PARAMETER, DelCallBack);
                        }
                        EditorGUILayout.EndVertical();
                    }
                    GUI.backgroundColor = Color.white;
                }
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();

            GUILayout.Space(10);
            EditorGUILayout.BeginVertical("box");
            {
                DrawAddParameter();
            }
            EditorGUILayout.EndVertical();
        }
示例#13
0
        private void DrawTransitionAddGroup(SkillHsmConfigNodeData nodeValue, int transitionId)
        {
            if (transitionId < 0)
            {
                return;
            }

            if (GUILayout.Button("添加组"))
            {
                if (null != HSMManager.hSMNodeTransitionAddDelGroup)
                {
                    HSMManager.hSMNodeTransitionAddDelGroup(nodeValue.Id, transitionId, -1, true);
                }
            }
        }
示例#14
0
 public void Draw()
 {
     EditorGUILayout.BeginHorizontal("box");
     {
         int index = option;
         option = GUILayout.Toolbar(option, optionArr, EditorStyles.toolbarButton);
         if (index != option)
         {
             if (null != HSMManager.hSMRuntimePlay)
             {
                 HSMManager.hSMRuntimePlay((HSMPlayType)option);
             }
         }
     }
     EditorGUILayout.EndHorizontal();
 }
示例#15
0
        private void DrawTitle()
        {
            int        selectIndex = 0;
            List <int> idList      = new List <int>();

            string[] optionArr = _drawModel.GetOptionArr(ref selectIndex, ref idList);
            int      option    = selectIndex;

            option = GUILayout.Toolbar(option, optionArr, EditorStyles.toolbarButton, GUILayout.Width(optionArr.Length * 200));
            if (option != selectIndex)
            {
                if (null != HSMManager.hsmOpenSubMachine)
                {
                    int nodeId = idList[option];
                    HSMManager.hsmOpenSubMachine(nodeId);
                }
            }
        }
示例#16
0
        private void DrawAddParameter()
        {
            if (null == newAddParameter)
            {
                newAddParameter = new SkillHsmConfigHSMParameter();
            }

            EditorGUILayout.BeginVertical("box");
            {
                newAddParameter = HSMDrawParameter.Draw(newAddParameter, HSMDrawParameterType.HSM_PARAMETER_ADD, null);
            }
            EditorGUILayout.EndVertical();
            GUILayout.Space(5);

            if (GUILayout.Button("添加条件"))
            {
                if (null != HSMManager.hSMNodeAddDelParameter)
                {
                    HSMManager.parameterChange(newAddParameter, true);
                }
            }
        }
示例#17
0
        public static void SelectFile(string path)
        {
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            GUILayout.Space(8);

            string filePath = EditorUtility.OpenFilePanel("选择技能ID文件", path, "txt");

            if (!string.IsNullOrEmpty(filePath))
            {
                string fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);
                if (!string.IsNullOrEmpty(fileName))
                {
                    if (null != HSMManager.hSMLoadFile)
                    {
                        HSMManager.hSMLoadFile(fileName);
                    }
                }
            }
        }
示例#18
0
        private void DrawNode(SkillHsmConfigNodeData nodeData)
        {
            string selectTitle = string.Empty;

            int  selectTransitionId = -1;
            bool selectTransition   = SelectTransition(nodeData, ref selectTransitionId);

            selectNodeParameter = !selectTransition;
            GUI.backgroundColor = selectNodeParameter ? new Color(0, 1, 0, 1) : Color.white;//
            EditorGUILayout.BeginVertical("box");
            {
                bool oldValue = selectNodeParameter;
                selectNodeParameter = EditorGUILayout.Toggle(new GUIContent("节点参数"), selectNodeParameter);
                if ((!oldValue && selectNodeParameter) && HSMManager.Instance.CurrentTransitionId >= 0 && null != HSMManager.hSMChangeSelectTransitionId)
                {
                    HSMManager.hSMChangeSelectTransitionId(-1);
                }
            }
            EditorGUILayout.EndVertical();
            GUI.backgroundColor = Color.white;

            SkillHsmConfigTransition transition = null;

            EditorGUILayout.BeginVertical("box");
            {
                EditorGUILayout.LabelField("选择转换连线查看/添加/删除参数");
                for (int i = 0; i < nodeData.TransitionList.Count; ++i)
                {
                    SkillHsmConfigTransition temp = nodeData.TransitionList[i];
                    string name      = string.Format("转换条件参数:连线ID_{0}", temp.ToStateId);
                    bool   lastValue = (selectTransitionId == temp.TransitionId);
                    if (lastValue)
                    {
                        transition  = temp;
                        selectTitle = name;//string.Format("{0} 参数", name);
                    }

                    GUI.backgroundColor = lastValue ? new Color(0, 1, 0, 1) : Color.white;//
                    EditorGUILayout.BeginHorizontal("box");
                    {
                        GUIStyle guiStyle = new GUIStyle();
                        guiStyle.normal.textColor = lastValue ? Color.green : Color.black;
                        bool value = EditorGUILayout.Toggle(new GUIContent(name), lastValue);
                        if (value && !lastValue)
                        {
                            if (null != HSMManager.hSMChangeSelectTransitionId)
                            {
                                int id = nodeData.Id * 1000 + temp.TransitionId;
                                HSMManager.hSMChangeSelectTransitionId(id);
                            }
                        }

                        if (GUILayout.Button("复制"))
                        {
                            HSMManager.copyTransition = temp.Clone();
                        }

                        if (GUILayout.Button("粘贴"))
                        {
                            if (null != HSMManager.copyTransition)
                            {
                                HSMManager.copyTransition.TransitionId = temp.TransitionId;
                                HSMManager.copyTransition.ToStateId    = temp.ToStateId;
                                temp = HSMManager.copyTransition.Clone();
                                nodeData.TransitionList[i] = temp;
                                HSMManager.copyTransition  = null;
                            }
                        }

                        if (GUILayout.Button("删除"))
                        {
                            if (null != HSMManager.hSMNodeChangeTransition)
                            {
                                HSMManager.hSMNodeChangeTransition(nodeData.Id, temp.ToStateId, false);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUI.backgroundColor = Color.white;
                }
            }
            EditorGUILayout.EndVertical();

            if (null != transition)
            {
                DrawTransitionParameter(nodeData, transition, selectTitle);
            }
            if (selectNodeParameter)
            {
                DrawNodeParameter(nodeData, selectTitle);
            }
        }