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); } }
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); } }